Repository navigation
fix(bwrap): resolve symlinks and check overlap of mount sources - #34
Closed
Stuart B. Wilkins (stuwilkins) wants to merge 1 commit into
Closed
Stuart B. Wilkins (stuwilkins) wants to merge 1 commit into
Stuart B. Wilkins (stuwilkins) wants to merge 1 commit into
Conversation
The check for mounts that expose the N2C session directory compared the source as written, so a symlinked source that leads to a directory holding it was missed. Compare the source as written and resolved against the session directory as written and resolved, in both directions (contains or lies inside). Assisted-by: opencode:claude-sonnet-5-5
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the expanded session-directory mount guard changes.
No open issues 🎉
What changed in this PR
Strengthens the shared Bubblewrap launcher guard to prevent bind mounts from exposing the N2C session directory and its refresh token, closing two gaps left after #32.
Changes:
- Checks mount sources and the session directory using both original and symlink-resolved paths.
- Rejects sources that equal, contain, or lie inside the session directory.
- Documents the expanded protection, including a symlinked cache example.
| File | Description |
|---|---|
lib/bwrap_sandbox_lib.sh |
Adds symlink resolution and bidirectional overlap checks to the final mount guard. |
docs/bw-wrappers.md |
Explains the expanded session-directory protection and symlink example. |
Review effort: Balanced
Contributor
Author
Merged
3 of 4 tasks
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.
Summary
Make the last-resort check that keeps the N2C session directory out of the
sandbox catch symlinked mount sources and mounts that lie inside it. Follow-up
to #32.
Description
verify_n2c_state_not_exposedruns after every mount is built and stops thelaunch if a bind mount would expose the N2C session directory (it holds the
MSAL cache with the refresh token). It had two gaps:
directory holding the session directory was not caught, for example
~/.npmlinked to a directory that contains
N2C_STATE_DIR.source lies inside the session directory was not caught.
Now each source is compared as written and with symlinks resolved
(
readlink -f) against the session directory as written and resolved, in bothdirections: the source is the session directory, contains it or lies inside it.
The error message is unchanged.
docs/bw-wrappers.mddescribes the wider check, with the symlinked~/.npmexample.
Testing
pre-commit run --files lib/bwrap_sandbox_lib.sh docs/bw-wrappers.md: allhooks pass (shfmt, shellcheck, codespell, markdownlint, gitleaks, mypy).
bash -n lib/bwrap_sandbox_lib.shis clean.--dry-runagainst a symlinked source or a mount inside thesession directory.
Checklist
pixi run -e dev lintlocally (or wait for CI) — see.github/workflows/lint.ymlrunansibledeployment)