Skip to content

fix(sandbox): isUnderDirectory returns true for root directory#1

Open
tdiam wants to merge 1 commit intosysid:mainfrom
tdiam:fix/isUnderDirectory-root-path
Open

fix(sandbox): isUnderDirectory returns true for root directory#1
tdiam wants to merge 1 commit intosysid:mainfrom
tdiam:fix/isUnderDirectory-root-path

Conversation

@tdiam
Copy link

@tdiam tdiam commented Mar 17, 2026

Summary

Fix bug where isUnderDirectory('/home/user', '/') returned false, making denyRead: ["/"] in sandbox.json ineffective.

Problem

When dirPath is "/", the check:

normalizedFile.startsWith(`${normalizedDir}/`)

became startsWith("//") which never matches any normalized path.

Changes

  • path-guard.ts: Fix root directory handling in both the non-symlink and symlink code paths
  • path-guard.test.ts: Add tests for root directory cases

Fix bug where isUnderDirectory('/home/user', '/') returned false.
When dirPath is '/', the check normalizedFile.startsWith('${normalizedDir}/')
became startsWith('//') which never matches.

Now handles root directory specially by using '/' as the prefix
instead of '//'.

This fix makes denyRead: ['/'] in sandbox.json work correctly.
@tdiam tdiam force-pushed the fix/isUnderDirectory-root-path branch 2 times, most recently from b95c778 to e713662 Compare March 17, 2026 20:29
@tdiam tdiam marked this pull request as ready for review March 17, 2026 20:30
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.

1 participant