Skip to content

FIX: resolve real tool binary to prevent sandbox PATH shadowing#16

Open
Stuart B. Wilkins (stuwilkins) wants to merge 1 commit into
NSLS2:mainfrom
stuwilkins:fix_wrapper_path_shadowing
Open

FIX: resolve real tool binary to prevent sandbox PATH shadowing#16
Stuart B. Wilkins (stuwilkins) wants to merge 1 commit into
NSLS2:mainfrom
stuwilkins:fix_wrapper_path_shadowing

Conversation

@stuwilkins

Copy link
Copy Markdown
Contributor

Add resolve_real_tool_binary() to lib/bwrap_sandbox_lib.sh. On managed
hosts the dotfiles wrapper (~/.local/bin/opencode) shadows the real npm
binary on PATH. command -v opencode then resolves to the wrapper; its
directory gets added to SANDBOX_PATH and bind-mounted into the --clearenv
sandbox, where AZURE_*/N2SNSCRIPTS_LIB are stripped and the wrapper fails
with 'cannot locate gpg-passwd.sh' (the double-invocation bug).

Fix: detect dotfiles wrappers by checking whether readlink -f resolves to
a path containing /config/scripts/. If so, substitute the npm-prefix
binary directly. Hard-error if the npm binary is also absent (returning
the wrapper would silently recreate the bug). Non-npm tools (system
packages) are unaffected — the candidate is returned unchanged.

Wire resolve_real_tool_binary into all four wrappers: bwopencode,
bwclaude, bwcodex, bwcopilot.

Assisted-by: opencode:claude-opus-4-8
Assisted-by: opencode:claude-sonnet-4-6
Assisted-by: opencode:gpt-5.6-sol

Add resolve_real_tool_binary() to lib/bwrap_sandbox_lib.sh. On managed
hosts the dotfiles wrapper (~/.local/bin/opencode) shadows the real npm
binary on PATH. command -v opencode then resolves to the wrapper; its
directory gets added to SANDBOX_PATH and bind-mounted into the --clearenv
sandbox, where AZURE_*/N2SNSCRIPTS_LIB are stripped and the wrapper fails
with 'cannot locate gpg-passwd.sh' (the double-invocation bug).

Fix: detect dotfiles wrappers by checking whether readlink -f resolves to
a path containing /config/scripts/. If so, substitute the npm-prefix
binary directly. Hard-error if the npm binary is also absent (returning
the wrapper would silently recreate the bug). Non-npm tools (system
packages) are unaffected — the candidate is returned unchanged.

Wire resolve_real_tool_binary into all four wrappers: bwopencode,
bwclaude, bwcodex, bwcopilot.

Assisted-by: opencode:claude-opus-4-8
Assisted-by: opencode:claude-sonnet-4-6
Assisted-by: opencode:gpt-5.6-sol

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.

Pull request overview

This PR hardens the bubblewrap sandbox wrappers against PATH shadowing by dotfiles “wrapper” scripts (e.g., ~/.local/bin/opencode) on managed hosts, ensuring the sandbox mounts and executes the real tool binary rather than a wrapper that depends on stripped environment variables.

Changes:

  • Add resolve_real_tool_binary() to lib/bwrap_sandbox_lib.sh to detect dotfiles wrappers (via readlink -f containing /config/scripts/) and substitute the npm-prefix binary.
  • Wire the new resolver into bwopencode, bwclaude, bwcodex, and bwcopilot so tool discovery no longer depends on wrapper paths.

Reviewed changes

Copilot reviewed 1 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/bwrap_sandbox_lib.sh Adds resolve_real_tool_binary() to bypass dotfiles wrapper symlinks and return the real npm-installed binary (or error if absent).
bin/bwopencode Uses resolve_real_tool_binary opencode for host tool resolution before sandboxing.
bin/bwcopilot Uses resolve_real_tool_binary copilot for host tool resolution before sandboxing.
bin/bwcodex Uses resolve_real_tool_binary codex for host tool resolution before sandboxing.
bin/bwclaude Uses resolve_real_tool_binary claude for host tool resolution before sandboxing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/bwrap_sandbox_lib.sh
# Detect dotfiles wrapper: the symlink target contains /config/scripts/
# (the dotfiles convention for per-tool wrapper scripts).
real_candidate="$(readlink -f "${candidate}" 2> /dev/null || printf '%s' "${candidate}")"
if [[ "${real_candidate}" == */config/scripts/* ]]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the source of this convention?

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.

3 participants