Skip to content

sec (6/9): run user-defined scanners in an isolated working directory#30

Open
jesse-merhi wants to merge 1 commit into
sec/05-windows-target-guardfrom
sec/06-isolated-cwd
Open

sec (6/9): run user-defined scanners in an isolated working directory#30
jesse-merhi wants to merge 1 commit into
sec/05-windows-target-guardfrom
sec/06-isolated-cwd

Conversation

@jesse-merhi

@jesse-merhi jesse-merhi commented Jul 23, 2026

Copy link
Copy Markdown
Member

What changes

A user-defined scanner no longer runs with its working directory set to the
target's folder. On a host run it now runs in a fresh isolated temp directory
(clawscan-scanner-*, removed after the run); under Docker the workdir stays
empty so nothing target-adjacent is mounted.

Why it matters

Running with cwd = the target's directory hands the scanner writable access
to every file sitting next to the target. A malicious or buggy scanner could
modify or drop files beside the skill being scanned (and under Docker that
directory would be a writable bind mount). Giving the scanner a private throwaway
cwd removes that ambient write access; the target is still passed explicitly as
an argument.

Before / after (runnable)

Scanner that records its cwd and tries to write a neighbor file:

command: "echo {{target}} >/dev/null; pwd 1>&2; touch NEIGHBOR_LEAK; echo '{}'; exit 9"
Behavior
Before cwd = target dir; NEIGHBOR_LEAK lands next to the skill
After cwd = isolated temp dir; nothing left beside the target
$ clawscan ./skill --config cwd.yml --profile demo --sandbox off --json
# scanner error stderr shows its cwd:
exit status 9: /private/var/folders/.../T/clawscan-scanner-2472157201
# and next to the target:
marker next to target? no — ran in isolated temp dir, cleaned up

Verify

go test ./internal/runner/ -run 'IsolatedCwd' -count=1

TestUserDefinedScannerUsesIsolatedCwd asserts the host run's cwd is a fresh
temp dir (not the target dir) and that Docker runs use an empty workdir.

The scanner used to run with a working directory derived from the target:
the target's parent directory, or the target itself when it was a directory.
That handed the scanner writable access to files sitting next to the target,
and under Docker that parent became a writable bind mount. Run host scanners
in a fresh os.MkdirTemp directory (removed after the run) and keep the Docker
cwd empty so nothing target-derived is mounted; the container workdir is
already isolated. Removes the now-unused userDefinedScannerCWD helper.
Copilot AI review requested due to automatic review settings July 23, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@clawsweeper

clawsweeper Bot commented Jul 24, 2026

Copy link
Copy Markdown

ClawSweeper status: review started.

I am starting a fresh review of this pull request: sec (6/9): run user-defined scanners in an isolated working directory This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants