[codex] fix(security): harden sandbox command execution#1416
[codex] fix(security): harden sandbox command execution#141613ernkastel wants to merge 5 commits intoNVIDIA:mainfrom
Conversation
sandboxName and GATEWAY_NAME are interpolated into shell command strings passed to run()/runCapture() without shellQuote(), which is inconsistent with other user-controlled values in the same file (lines 460, 1438, 3005). Wrap both values with shellQuote() to prevent shell metacharacter interpretation. Add regression test that scans onboard.js for any unquoted sandboxName in run/runCapture calls. Closes NVIDIA#1391 Signed-off-by: latenighthackathon <latenighthackathon@users.noreply.github.com>
Line-by-line scanning misses multiline run()/runCapture() calls. Switch to a regex that matches the full call including the template literal, so violations spanning multiple lines are caught. Signed-off-by: latenighthackathon <latenighthackathon@users.noreply.github.com>
Builds on NVIDIA#1392 by validating sandboxName overrides at the createSandbox boundary, moving the dashboard readiness check onto the structured OpenShell helper path, and running the DNS proxy setup through argv-style execution instead of bash -c interpolation. Adds regression coverage for the new runner helper, invalid sandboxNameOverride rejection, and the createSandbox command paths. Co-authored-by: latenighthackathon <latenighthackathon@users.noreply.github.com> Signed-off-by: 13ernkastel <LennonCMJ@live.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a new runner helper Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
bin/lib/runner.js (1)
60-75: Collapse the spawn helpers into one internal path.
run(),runInteractive(), andrunFile()now repeat the samespawnSync/redaction/exit handling. A shared helper would make future hardening changes much harder to miss in one branch.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@bin/lib/runner.js` around lines 60 - 75, The three functions run(), runInteractive(), and runFile() duplicate spawnSync/stdio/env/redaction/exit handling; extract that logic into a single internal helper (e.g., spawnAndHandle or _spawnSyncWithRedaction) that takes (fileOrCmd, args, opts, stdio) and performs spawnSync with cwd ROOT, merged env, calls writeRedactedResult(result, stdio), logs the redacted rendered command on non-zero exit and process.exit, and returns result; then refactor run(), runInteractive(), and runFile() to call this helper with the appropriate stdio and ignoreError behavior, removing the duplicated spawnSync and exit handling from each function.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@bin/lib/onboard.js`:
- Around line 2095-2098: The prompt validation and the final boundary check are
out of sync: replace the `sandboxNameOverride || (await
promptValidatedSandboxName())` expression with `sandboxNameOverride ?? (await
promptValidatedSandboxName())` to prevent empty string falling through, and
modify `promptValidatedSandboxName()` to call and return `validateName(...)`
(instead of using the RFC-1123 regex directly) so the interactive retry loop
enforces the same 63-character/lowercase rules as `validateName`; ensure
`validateName` is used for both override and prompted values so failures
re-prompt rather than abort.
---
Nitpick comments:
In `@bin/lib/runner.js`:
- Around line 60-75: The three functions run(), runInteractive(), and runFile()
duplicate spawnSync/stdio/env/redaction/exit handling; extract that logic into a
single internal helper (e.g., spawnAndHandle or _spawnSyncWithRedaction) that
takes (fileOrCmd, args, opts, stdio) and performs spawnSync with cwd ROOT,
merged env, calls writeRedactedResult(result, stdio), logs the redacted rendered
command on non-zero exit and process.exit, and returns result; then refactor
run(), runInteractive(), and runFile() to call this helper with the appropriate
stdio and ignoreError behavior, removing the duplicated spawnSync and exit
handling from each function.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4277283d-a5ab-4474-9d2b-b9e92316bc0b
📒 Files selected for processing (5)
bin/lib/onboard.jsbin/lib/runner.jstest/onboard.test.jstest/runner.test.jstest/shellquote-sandbox.test.js
Signed-off-by: 13ernkastel <LennonCMJ@live.com>
|
✨ Thanks for submitting this pull request, which proposes a way to improve security by hardening sandbox command execution in OpenShell. |
Summary
Hardens the open shell-quoting fix in
#1392by tightening thecreateSandbox()boundary and removing the remaining shell-string dependency from the follow-on command paths.This keeps the original security fix intact, but makes the code less dependent on per-call quoting and adds behavior-level regression coverage for the override and execution paths.
Related Issue
Follow-up to #1392.
Changes
sandboxNameOverridewithvalidateName()insidecreateSandbox()before any command helper is called.runCapture()shell string.runFile()tobin/lib/runner.jsso scripts can run via argv-style execution withoutbash -cinterpolation.runFile()forsetup-dns-proxy.shin onboarding.test/onboard.test.js,test/runner.test.js, andtest/shellquote-sandbox.test.js.Type of Change
Testing
npx prek run --all-filespasses (or equivalentlymake check).npm testpasses.make docsbuilds without warnings. (for doc-only changes)Targeted checks run:
npx vitest run test/runner.test.js test/onboard.test.js test/shellquote-sandbox.test.jsnpx prek run --files bin/lib/onboard.js bin/lib/runner.js test/onboard.test.js test/runner.test.js test/shellquote-sandbox.test.jsThis reaches an existing unrelated failure in
test/usage-notice.test.jsduring the repo-widetest-clihook.npx vitest run test/usage-notice.test.jsReproduces the same unrelated existing failure:
renders url lines as terminal hyperlinks when tty output is available.Checklist
General
Code Changes
npx prek run --files ...auto-fixed formatting for the touched files before validation.Doc Changes
update-docsagent skill to draft changes while complying with the style guide. For example, prompt your agent with "/update-docscatch up the docs for the new changes I made in this PR."Signed-off-by: 13ernkastel LennonCMJ@live.com
Summary by CodeRabbit
Bug Fixes
Tests