Repository navigation
sandbox: stop banning cd/pushd in unrestricted mode - #84
Merged
Merged
Conversation
The shell denylist used to short-circuit cd / chdir / pushd / popd
unconditionally when shell_deny_enabled was True, regardless of
whether restrict_to_workspace was on. That broke legitimate
compile-and-build flows like the Delphi/Windows one
cmd /c "C:\…\rsvars.bat && cd C:\proj && dcc32.exe probe.dpr"
for users whose config.json had no sandbox section at all —
because TConfig defaults are restrict_to_workspace=false +
shell_deny_enabled=true, which silently combined to ban cd in
unrestricted mode for no actual security benefit. The cd-family
only matters when the workspace cwd pin exists; without a pin to
defeat, banning them is pure friction.
Split ForbiddenTokens into two arrays:
ForbiddenTokens (24 entries, was 28) — sudo, rm,
chmod, chown, kill family, mkfs,
diskpart, del, format, etc. Always
checked when shell_deny_enabled.
Behaviour preserved verbatim for
every non-cd-family entry.
WorkspaceEscapeTokens (4 entries, NEW) — cd, chdir, pushd,
popd. Checked only when BOTH
restrict_to_workspace=True AND
shell_deny_enabled=True. Lives in
the existing restriction branch in
ShellAllowed, right next to the
absolute-path scanner and the
traversal-token check.
Refusal message for the new check names the actual reason
("workspace-escape token … restrict_to_workspace=true pins shell
cwd to …") so the model can rewrite with absolute paths inside
the workspace instead of bouncing off the generic "forbidden
token" error and getting stuck.
Verified locally:
make builds clean under FPC 3.2.2.
Standalone smoke (4 policy combinations × 11 commands):
- unrestricted + deny on: cd / chdir / pushd ALLOWED (the
regression fix); sudo / rm / curl|sh STILL BLOCKED
- restricted + deny on: cd / pushd BLOCKED (intent preserved,
new clearer message); sudo STILL BLOCKED
- restricted + deny off: cd (relative) allowed — gate
requires both flags
- unrestricted + deny off: full passthrough (existing behaviour)
All 11 assertions pass.
https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
The shell denylist short-circuited
cd/chdir/pushd/popdunconditionally whenevershell_deny_enabledwas True, regardless of whetherrestrict_to_workspacewas on. That broke legitimate compile-and-build flows like the Delphi/Windows one:For users whose
config.jsonhad nosandboxsection at all — becauseTConfigdefaults torestrict_to_workspace=false+shell_deny_enabled=true, which silently combined to bancdin unrestricted mode for no actual security benefit. The cd-family only matters when a workspace cwd pin exists; without a pin to defeat, banning them is pure friction.The fix
Split
ForbiddenTokensinto two arrays:ForbiddenTokensshell_deny_enabledaloneWorkspaceEscapeTokensrestrict_to_workspace AND shell_deny_enabledThe new check lives in the existing
RestrictToWorkspacebranch inShellAllowed, right next to the absolute-path scanner and the traversal-token check. Refusal message names the actual reason ("workspace-escape token …restrict_to_workspace=truepins shell cwd to …") so the model can rewrite with absolute paths inside the workspace instead of bouncing off a generic "forbidden token" error and getting stuck — which is what was happening in the transcript that surfaced this regression.Verification
Standalone smoke covering all four policy combinations × 11 commands. All 11 assertions pass:
cd/chdir/pushdallowed (regression fix);sudo/rm/curl | shstill blockedcd/pushdblocked with the new clearer message;sudostill blockedcd(relative path) allowed — new gate requires both flagsBehaviour preserved verbatim for every non-cd-family entry in the original list. The
restrict_to_workspace=trueoperator loses nothing: the workspace cwd pin, the absolute-path scanner, and the traversal-token check all still fire as before, and the newWorkspaceEscapecheck joins them inside the same branch.https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code