fix: reject unrecognized config paths in config set (Fixes #2019)#2036
fix: reject unrecognized config paths in config set (Fixes #2019)#2036ericksoa merged 1 commit intoNVIDIA:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds and exports Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/lib/sandbox-config.ts`:
- Around line 116-125: The function isRecognizedConfigPath currently uses the
"in" operator which allows prototype-inherited keys (e.g., "toString") to pass
validation; update the check inside isRecognizedConfigPath to use
Object.prototype.hasOwnProperty.call(current as Record<string, unknown>, key)
instead of "(key in (current as Record<string, unknown>))" so only own
properties are accepted, and add unit tests exercising paths like "toString" and
"constructor" to assert they are rejected to prevent prototype-chain bypasses.
In `@test/config-set.test.ts`:
- Around line 7-13: Replace the CommonJS require at module level by converting
the top-level import to an ESM-compatible pattern: use Node's
createRequire(import.meta.url) to load the compiled CommonJS module and then
destructure the exported symbols (extractDotpath, isRecognizedConfigPath,
setDotpath, validateUrlValue, resolveAgentConfig) from that require result;
update the test file imports to follow the same pattern used in
test/registry.test.ts and test/onboard.test.ts so the test-module convention is
respected.
🪄 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 Plus
Run ID: 6952bcf4-8470-4da7-8339-6528a728466d
📒 Files selected for processing (3)
src/lib/sandbox-config.tstest/config-set.test.tstest/e2e/test-shields-config.sh
334c167 to
359c8bf
Compare
|
Rebased on current main and addressed the CodeRabbit follow-up. The config path check now only accepts own properties, the test import uses createRequire, and the focused config tests pass locally. |
|
✨ Thanks for submitting this PR that proposes a fix to reject unrecognized config paths in config set, which could help improve the getting started process and prevent config corruption. Possibly related open issues: |
Fixes NVIDIA#2019 Signed-off-by: Deepak Jain <[email protected]>
359c8bf to
0a29bf0
Compare
|
Rebased on current main and reran the focused config checks. npm run build:cli and npm test -- test/config-set.test.ts test/config-rotate-token.test.ts both pass locally. |
ericksoa
left a comment
There was a problem hiding this comment.
Looks good. The validation logic is solid — handles empty segments, null intermediates, arrays, and prototype-chain keys correctly. Test coverage is thorough and the E2E update is clean.
One minor observation for a future follow-up: the validation allows setting intermediate (non-leaf) nodes. E.g., config set --key agents.defaults --value '"foo"' would pass validation since agents.defaults is a recognized own property, but it would overwrite the entire defaults object with a string. Not introduced by this PR and not a blocker — just something to consider adding a leaf-only or type-mismatch guard for down the road.
Upstream commits: - feat(snapshot): add --name flag and version restore selectors (#2184) - fix: reject unrecognized config paths in config set (#2036) Conflict resolution: - src/lib/sandbox-config.ts: keep ours (configSet and helpers removed) - test/config-set.test.ts: keep deleted (command removed) - test/e2e/test-shields-config.sh: keep ours (rewritten for mutable default) The config-set path validation fix (#2036) is moot since config set no longer exists — agents edit config natively in the mutable default.
Fixes #2019
Summary
nemoclaw <name> config setwas accepting arbitrary dotpaths and writing them straight intoopenclaw.json. That made it easy to create config keys that OpenClaw does not recognize, which then breaks agent startup.This change makes
config setreject unrecognized config paths before it writes anything.Changes
src/lib/sandbox-config.ts: addedisRecognizedConfigPath()and madeconfigSet()fail fast when the requested dotpath is not already present in the current agent config.test/config-set.test.ts: added regression coverage for recognized and unrecognized config paths.test/e2e/test-shields-config.sh: updated the config-set smoke path to mutate a real existing config field instead of relying on creating a brand-new top-level key.Testing
npm run build:clinpm run typecheck:clinpm test -- test/config-set.test.ts test/config-rotate-token.test.tsEvidence It Works
config set --key inference.endpoint ...now fails with a key validation error instead of corruptingopenclaw.json.Notes
npm test. In this worktree it still reproduces unrelated existing failures intest/legacy-path-guard.test.ts,src/lib/preflight.test.ts,src/lib/sandbox-version.test.ts, andtest/install-preflight.test.ts.Signed-off-by: Deepak Jain [email protected]
Summary by CodeRabbit
New Features
Tests