Repository navigation
Fix path sanitization through symlinked roots - #1594
Conversation
✅ Deploy Preview for agent-sandbox canceled.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
ChangesSandbox path sanitization
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Sandbox paths accessed through symlink aliases now normalize to the resolved sandbox root without duplicating path segments, while confinement remains enforced. The focused regression coverage indicates no remaining merge-blocking risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, preserves the security invariant (resolved path must remain under the resolved root), and adds a targeted regression test for the reported symlink-alias case.
Pull request overview
This PR fixes an edge case in packages/sandboxd/pkg/pathutil where SanitizePath could mishandle absolute user paths when the sandbox root is accessed via a symlinked/aliased path (e.g., lexical vs resolved root paths). It preserves the lexical root for absolute-prefix stripping while continuing to enforce confinement against the symlink-resolved root.
Changes:
- Track both the lexical cleaned root and the symlink-resolved root, and strip either prefix from absolute user paths before joining.
- Add a regression test that uses a symlinked sandbox root to ensure absolute paths under the alias are confined correctly.
File summaries
| File | Description |
|---|---|
| packages/sandboxd/pkg/pathutil/sandbox.go | Preserve lexical root for prefix recognition while still confining using the resolved root. |
| packages/sandboxd/pkg/pathutil/sandbox_test.go | Add regression coverage for absolute paths under a symlinked root alias. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Verified the confinement invariant is untouched: the lexical-root trim only changes prefix recognition, and the final EvalSymlinks + resolved-root boundary check still gates every result. Regression test is portable and targeted. /lgtm |
janetkuo
left a comment
There was a problem hiding this comment.
Can be address in a follow up
| require.NoError(t, os.WriteFile(filepath.Join(root, "f.txt"), []byte("x"), 0o644)) | ||
| require.NoError(t, os.Symlink(root, rootAlias)) | ||
|
|
||
| got, err := SanitizePath(rootAlias, filepath.Join(rootAlias, "f.txt")) |
There was a problem hiding this comment.
Consider adding a case where userPath is rootAlias itself, as well as passing the resolved root while rootDir is rootAlias.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: janetkuo, yujunz The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
3503363
into
kubernetes-sigs:main
What this PR does / why we need it:
SanitizePath resolves the sandbox root before comparing full absolute user paths against it. When the root is accessed through a symlink alias, such as macOS /var mapping to /private/var, that comparison misses and duplicates the absolute path beneath the root.
This change preserves the cleaned lexical root for prefix recognition while continuing to use the resolved root for final path confinement. It also adds a portable regression test using a symlinked sandbox root.
Which issue(s) this PR is related to:
None.
Release Note
Summary by CodeRabbit