Commit Graph

419 Commits

Author SHA1 Message Date
Peter Steinberger
dd409eec80 perf(test): mock audit plugin policy deps 2026-04-20 19:33:43 +01:00
Peter Steinberger
16985aba4e test: type skill scanner matrix cases 2026-04-20 19:21:24 +01:00
Peter Steinberger
ed526a2121 perf(test): merge skill scanner matrix cases 2026-04-20 19:11:45 +01:00
Peter Steinberger
305d04b758 perf(test): move temp path guard to check 2026-04-20 19:07:29 +01:00
Peter Steinberger
26c213031d perf(test): isolate gateway audit tests 2026-04-20 18:58:10 +01:00
Peter Steinberger
f43e006529 perf(test): mock plugin trust audit deps 2026-04-20 18:51:05 +01:00
Peter Steinberger
dbfc3d7104 perf(test): split plugin trust audit seam 2026-04-20 18:25:25 +01:00
Peter Steinberger
71b08988fb perf(test): narrow security audit imports 2026-04-20 18:09:13 +01:00
Peter Steinberger
642a3567b1 perf(test): mock security code safety scans 2026-04-20 18:06:32 +01:00
Peter Steinberger
f304af6b74 test(core): guard security audit boundaries 2026-04-20 17:38:20 +01:00
Peter Steinberger
a73bbe4bdd test(extensions): move channel security coverage 2026-04-20 17:38:20 +01:00
Peter Steinberger
c4358fb567 perf(test): shorten security audit hotspot tests 2026-04-20 16:22:36 +01:00
Peter Steinberger
e069169765 perf: decouple plugin facades from extension types 2026-04-18 22:06:45 +01:00
Peter Steinberger
d3eeadba94 refactor: drop private channel sdk facades 2026-04-18 19:37:15 +01:00
Peter Steinberger
678b019467 test: stabilize config and plugin scanner tests 2026-04-16 22:10:36 +01:00
Viz
f624b1d246 fix(security): 7 P1 hardening fixes — scan-paths, windows-acl, audit-extra (#67003)
* test(security): add coverage tests before security fixes

- scan-paths.ts: 100% line coverage (new test file, previously zero)
- windows-acl.ts: 100% line coverage (SID bypass, whoami throw, no-user null return)
- external-content.ts: 99% (line 248 defensive overlap guard, unreachable)
- skill-scanner.ts: 93% (lines 293-294/330/571 are defensive guards for
  future extensibility, unreachable with current rules/patterns)

200+ tests covering TOCTOU paths, cache invalidation, forced-file escapes,
dir-entry-cache hit, SID world-bypass, diacritic-strip fallback,
fullwidth homoglyph markers, and more.

* fix(security): 5 security hardening fixes in src/security/

scan-paths: default requireRealpath to false (safe). All production callers
already pass requireRealpath: true; default callers are now secure.

windows-acl: block world-equivalent SIDs (S-1-1-0 Everyone etc.) from being
added to trusted set via USERSID env var.

windows-acl: log resolveCurrentUserSid failures instead of bare catch{}.

audit-extra: wrap JSON.parse in readPluginManifestExtensions with try-catch.
Malformed package.json returns [] instead of crashing the audit.

audit-extra: depth guard in listWorkspaceSkillMarkdownFiles to prevent
resource exhaustion from deep symlink cycles.

audit-extra: 2s timeout on fs.realpath in collectWorkspaceSkillSymlinkEscapeFindings
to protect against hanging on slow/network filesystems.

audit-extra: warn about phantom entries in plugins.allow that don't match
any installed plugin (pre-approval exploitation vector).

media-understanding/types: add allowPrivateNetwork to transport overrides
(duplicate of PR #66967, required for tsgo to pass here).

* fix(security): address security review findings in audit-extra.async.ts

Issue 1 — Symlink escape audit bypass on realpath timeout:
When realpathWithTimeout returns null (timeout or failure), the previous code
called 'continue', silently skipping the escape check. An attacker with a
symlink to a slow/network filesystem could hang realpath to prevent escape
detection. Now treats unverifiable symlinks as potential escapes and includes
them in the finding.

Issue 2 — Malformed package.json hides extension entrypoints from deep scan:
readPluginManifestExtensions previously swallowed JSON.parse errors and
returned [], which a malicious plugin could exploit by crafting a malformed
package.json to hide its openclaw.extensions entrypoints from the deep code
scanner. Now re-throws the parse error (with cause) so the caller in
collectPluginsCodeSafetyFindings can surface a warn finding and alert the
user, while still scanning the plugin directory via getCodeSafetySummary.

* fix(security): address PR review findings (P1 + P2)

P1 — BFS realpath in listWorkspaceSkillMarkdownFiles lacks timeout:
Extract realpathWithTimeout to module scope so the BFS dequeue loop
uses the same 2 s guard as the outer escape-detection callers. Previously
only the per-workspace and per-skill-file realpaths had the timeout;
a hanging NFS/SMB directory entry inside the BFS could still block
indefinitely.

P1 (acknowledged limitation) — Promise.race leaves the underlying
fs.realpath call running after timeout. fs.realpath cannot be cancelled
once submitted to libuv. Callers are sequential (one await at a time),
so at most one worker thread is occupied; the OS will eventually time
out the stuck call. This is documented in the module-level JSDoc.

P2 — Phantom allowlist check incorrectly flags bundled plugin IDs:
listChannelPlugins() returns bundled channel plugin IDs (telegram,
discord, browser, etc.) that are never in stateDir/extensions.
Add bundledPluginIds exclusion so the phantom-entry finding is scoped
to user-installed extension IDs only.

P2 — Rename MAX_SYMLINK_DEPTH / depthGuard to MAX_TOTAL_DIR_VISITS /
totalDirVisits to accurately reflect that the guard caps total BFS
iterations (2_000 * 20 = 40_000), not per-path symlink depth.

* fix(security): clean up realpathWithTimeout timer and add regression tests

- Clear the timer handle when fs.realpath resolves before the deadline,
  preventing timer accumulation during large audit runs with many files.
- Add .unref() on the timer so it cannot hold the process alive while
  waiting on a potentially hanging NFS/SMB path.

Regression tests added for three audit-extra.async security fixes:
- manifest parse error: malformed plugin package.json surfaces
  plugins.code_safety.manifest_parse_error (audit-extra.async.test.ts)
- phantom allowlist with bundled exclusion: bundled channel plugin IDs
  are excluded from plugins.allow_phantom_entries warnings; non-installed
  non-bundled IDs are correctly reported (audit-plugins-phantom.test.ts)
- unverifiable realpath escape: fs.realpath failure / timeout produces a
  skills.workspace.symlink_escape finding with 'realpath timed out' in
  the detail (audit-workspace-skill-escape.test.ts)

* chore(security): add TODO for structured logger in windows-acl resolveCurrentUserSid

console.warn is acceptable short-term but may be noisy on constrained
Windows hosts; note the follow-up in-code so it is not lost.

* chore: drop unrelated formatting churn from security PR

Restores extensions/memory-lancedb/config.ts and
src/agents/pi-embedded-helpers/errors.ts to their origin/main state.
These were line-wrap-only formatting changes with no relation to the
security fixes in this branch.

* fix(security): address Codex P2 review findings

1. Normalize plugins.allow entries through normalizePluginId before
   phantom-entry filtering so that bundled plugin aliases and legacy IDs
   are correctly excluded. Without this, valid allow entries that resolve
   via alias normalization could generate false-positive phantom warnings.

2. Surface a skills.workspace.scan_truncated warn finding when the BFS
   visit cap (MAX_TOTAL_DIR_VISITS) is hit mid-traversal. Previously the
   scanner silently returned partial results, allowing escaped SKILL.md
   symlinks in the unvisited tree to go undetected.

   listWorkspaceSkillMarkdownFiles now returns {skillFilePaths, truncated}
   and collectWorkspaceSkillSymlinkEscapeFindings emits the new finding
   when truncated is true.

Regression test added for the truncation path using a mocked readdir
that fills the queue past the cap (40 001 fake entries) and a mocked
realpath for zero-I/O iteration speed.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-04-16 13:40:05 -04:00
Vincent Koc
5b11985439 perf(cron): lazy-load external content runtime 2026-04-13 18:34:04 +01:00
Vincent Koc
74e7b8d47b fix(cycles): bulk extract leaf type surfaces 2026-04-11 13:26:50 +01:00
Vincent Koc
7198a9f0ee fix(cycles): reduce remaining static import seams 2026-04-11 02:46:41 +01:00
Vincent Koc
350299401f fix(cycles): continue shared seam extraction 2026-04-11 02:46:41 +01:00
Peter Steinberger
9e0d358695 refactor: simplify runtime conversions 2026-04-11 01:23:34 +01:00
Tak Hoffman
928c1c3861 test: skip helper directories in runtime guardrail scans 2026-04-10 17:42:12 -05:00
Davanum Srinivas
fbf11ebdb7 fix(sandbox): enforce CDP source-range restriction by default (#61404)
* fix(sandbox): enforce CDP source-range restriction by default

Auto-derive CDP_SOURCE_RANGE from Docker network gateway IP when not
explicitly configured. The entrypoint script refuses to start the socat
CDP relay without a source range (fail-closed).

- readDockerNetworkGateway: use Go template println, filter <no value>
  sentinel, prefer IPv4 gateway on dual-stack networks
- Reject IPv6-only gateways for auto-derivation (relay binds IPv4)
- Remove stale browser_cdp_bridge_unrestricted audit check (runtime
  auto-derives range for all bridge-like networks)
- Bump SANDBOX_BROWSER_SECURITY_HASH_EPOCH to force container recreation

* chore(changelog): add sandbox CDP source-range entry

* fix(sandbox): gate CDP source-range derivation to bridge-style networks

Only auto-derive OPENCLAW_BROWSER_CDP_SOURCE_RANGE from the Docker
gateway IP for bridge networks (or when driver is unknown). Non-bridge
drivers (macvlan, ipvlan, overlay) may route traffic from different
source IPs, so they require explicit cdpSourceRange config.

Adds readDockerNetworkDriver helper and a regression test for macvlan.

---------

Co-authored-by: Devin Robison <drobison@nvidia.com>
2026-04-10 14:59:25 -06:00
Agustin Rivera
905f19230a Align external marker span mapping (#63885)
* fix(markers): align external marker spans

* fix(browser): ssrfPolicy defaults fail-closed for unconfigured installs (GHSA-53vx-pmqw-863c)

* fix(browser): enforce strict default SSRF policy

* chore(changelog): add browser SSRF default + marker alignment entry

---------

Co-authored-by: Devin Robison <drobison@nvidia.com>
2026-04-10 12:35:20 -06:00
Peter Steinberger
59925c1a74 chore: update dependencies and oxc tooling 2026-04-10 19:28:42 +01:00
Peter Steinberger
08cee3316d refactor: dedupe core trimmed readers 2026-04-08 01:36:39 +01:00
Peter Steinberger
9314bb7180 refactor: dedupe extension lowercase helpers 2026-04-07 15:12:32 +01:00
Peter Steinberger
2cd11565a6 refactor: dedupe security lowercase helpers 2026-04-07 15:12:32 +01:00
Peter Steinberger
2aabe0e8fd Tests: trim audit imports and fix reply typing 2026-04-07 13:23:59 +08:00
Peter Steinberger
60ec27bce0 Security: split permission target collection from apply 2026-04-07 12:59:00 +08:00
Peter Steinberger
5b1b7f0f80 Security: split config-only fixer tests from permission path 2026-04-07 12:39:30 +08:00
Peter Steinberger
c9c656f2cb Tests: trim Feishu and Synology audit import cost 2026-04-07 12:24:31 +08:00
Peter Steinberger
4ff82e9c4a Tests: trim slack audit import cost 2026-04-07 12:11:34 +08:00
Peter Steinberger
8c7dd66a7b refactor: dedupe string readers 2026-04-07 05:06:54 +01:00
Peter Steinberger
b59560c49a Security: inject channel config-fix plugins in tests 2026-04-07 11:50:39 +08:00
Peter Steinberger
8c1b954c1b Tests: trim discord audit import cost 2026-04-07 11:44:40 +08:00
Peter Steinberger
e336311126 refactor: dedupe non-empty string helper 2026-04-06 23:52:31 +01:00
Peter Steinberger
d08abd8ce4 refactor: dedupe security audit record helper 2026-04-06 23:36:25 +01:00
Peter Steinberger
ab0c102ed7 fix(tests): narrow bundled plugin test seams 2026-04-06 23:35:07 +01:00
Peter Steinberger
6acb43f294 fix: resolve channel typing regressions 2026-04-06 17:43:57 +01:00
Peter Steinberger
ce30557399 refactor(deadcode): remove orphaned core helpers 2026-04-06 17:26:25 +01:00
Peter Steinberger
a65f9971b7 refactor(deadcode): remove duplicate barrels and helper shims 2026-04-06 17:00:40 +01:00
Vincent Koc
9c3d9c5c18 chore(lint): drop stale repo lint comments 2026-04-06 16:01:23 +01:00
Peter Steinberger
21c82ca623 perf(test): trim security audit wrapper coverage 2026-04-06 14:13:08 +01:00
Vincent Koc
5fa166ed11 fix(check): repair status report typing drift 2026-04-06 13:34:08 +01:00
Peter Steinberger
49e3ecfe5e perf(test): isolate deep probe finding helper 2026-04-06 13:29:35 +01:00
Peter Steinberger
10554644aa perf(test): trim security gateway auth test path 2026-04-06 13:22:46 +01:00
Peter Steinberger
d4da45c202 perf(test): split remaining security audit coverage 2026-04-06 13:14:52 +01:00
Peter Steinberger
f1b6b97df3 perf(test): split security audit coverage 2026-04-06 13:05:39 +01:00
Vincent Koc
e611761809 fix(plugins): move acpx config contracts into manifests 2026-04-06 12:33:20 +01:00