fix(security): remove npm registry from base sandbox policy (#1458) - #1665
fix(security): remove npm registry from base sandbox policy (#1458)#1665ColinM-sys wants to merge 1 commit into
Conversation
The base sandbox policy hardcoded `network_policies.npm_registry` with read-only `registry.npmjs.org` access plus the npm and node binaries. Because the entry lived in the base policy, every sandbox received npm registry access regardless of which policy presets the user picked during `nemoclaw onboard`. That created the regression in NVIDIA#1458: a sandbox onboarded with ZERO policy presets could still successfully run `npm install`, while `pip install` was correctly rejected because PyPI is only declared in the `pypi` preset (`presets/pypi.yaml`). Two equivalent package-manager paths, one silently allowed, one correctly gated. This is the same shape as the GitHub leak fixed in NVIDIA#1583/NVIDIA#1660. Remove the `npm_registry` entry from the base policy. Users who need npm in the sandbox can select the existing `npm` preset (`presets/npm.yaml`) during onboard or apply it later via `openshell policy set`. Adds a regression test in test/validate-blueprint.test.ts asserting: - the base policy must not declare an `npm_registry` network_policies entry - no endpoint anywhere in the base policy may reference registry.npmjs.org (catches a re-add under a renamed key) Refs: NVIDIA#1458
📝 WalkthroughWalkthroughThis change removes npm registry network access from the base sandbox policy to fix a regression where npm operations could execute without explicit policy selection. A regression test validates that the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
🧹 Nitpick comments (1)
test/validate-blueprint.test.ts (1)
205-206: Optional hardening: include Yarn registry in the host regression check.Since npm policy preset covers both npm and Yarn registries, this test can guard both with one matcher to prevent a parallel bypass.
♻️ Suggested diff
- const npmHosts = findEndpoints((h) => h === "registry.npmjs.org"); - expect(npmHosts).toEqual([]); + const npmOrYarnHosts = findEndpoints( + (h) => h === "registry.npmjs.org" || h === "registry.yarnpkg.com", + ); + expect(npmOrYarnHosts).toEqual([]);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/validate-blueprint.test.ts` around lines 205 - 206, The test currently queries findEndpoints with a predicate matching only "registry.npmjs.org" (stored in npmHosts) which misses Yarn; update the predicate passed to findEndpoints in validate-blueprint.test.ts to match both registries (e.g., check h === "registry.npmjs.org" || h === "registry.yarnpkg.com"), optionally rename npmHosts to registryHosts for clarity, and keep the expect(registryHosts).toEqual([]) assertion so the test fails if either npm or Yarn registries are present.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/validate-blueprint.test.ts`:
- Around line 205-206: The test currently queries findEndpoints with a predicate
matching only "registry.npmjs.org" (stored in npmHosts) which misses Yarn;
update the predicate passed to findEndpoints in validate-blueprint.test.ts to
match both registries (e.g., check h === "registry.npmjs.org" || h ===
"registry.yarnpkg.com"), optionally rename npmHosts to registryHosts for
clarity, and keep the expect(registryHosts).toEqual([]) assertion so the test
fails if either npm or Yarn registries are present.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b0d8d15a-1593-444e-b313-11e6bb892087
📒 Files selected for processing (2)
nemoclaw-blueprint/policies/openclaw-sandbox.yamltest/validate-blueprint.test.ts
|
✨ Thanks for submitting this PR, which proposes a way to fix the security issue related to npm registry access and may help improve the overall security of the NemoClaw platform. Possibly related open PRs: Possibly related open issues: |
Summary
npm_registryentry from the base sandbox policy. npm registry access was being granted to every sandbox regardless of opt-in.npm_registryor referencesregistry.npmjs.org.Fixes #1458.
Why
The reporter onboarded a sandbox with zero policy presets and observed that
npm installstill succeeded inside the sandbox, whilepip installwas correctly rejected. The root cause:network_policies.npm_registrywas hardcoded into the base policy withGET /**onregistry.npmjs.orgplus the npm/node binaries, while PyPI was only declared inpresets/pypi.yaml. Two equivalent package-manager paths, one silently allowed and one correctly gated — exactly the same shape as the GitHub leak fixed in #1583/#1660.What changed
nemoclaw-blueprint/policies/openclaw-sandbox.yaml— remove thenpm_registryblock, leave a comment pointing at the existingpresets/npm.yamland [All platforms][Regression] None policy added but NPM install is able to execute #1458.test/validate-blueprint.test.ts— new regression test under#1458asserting the base policy declares nonpm_registryentry and references noregistry.npmjs.orghost.Test plan
npx vitest run test/validate-blueprint.test.ts→ 28/28 passing.openclaw plugins installflow depends on npm reachability from inside the sandbox. The build-timeopenclaw plugins install /opt/nemoclawstep in the Dockerfile is a local-path install, not an npm fetch, so it is unaffected by this change.Summary by CodeRabbit
Bug Fixes
Tests