Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork565
feat: Add configuration schema for safety features#223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
- Add readOnlyDirectories for protected paths- Add requireExplicitPermission flag for destructive commands- Add allowedSudoCommands array for sudo whitelist- Backward compatible with defaults (empty arrays, false flag)This commit adds configuration without changing behavior.
coderabbitaibot commentedAug 22, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
WalkthroughAdded three optional properties to ServerConfig in src/config-manager.ts and initialized corresponding defaults: readOnlyDirectories (string[]), requireExplicitPermission (boolean), and allowedSudoCommands (string[]). Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from theIntegrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat withCodeRabbit:
SupportNeed help? Create a ticket on oursupport page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/config-manager.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/config-manager.ts (2)
src/tools/filesystem.ts (1)
getAllowedDirs(108-128)src/tools/config.ts (1)
setConfigValue(55-142)
🔇 Additional comments (1)
src/config-manager.ts (1)
136-140:Incorrect interpretation of defaultallowedDirectories—no change neededThe current logic in
getAllowedDirs()returns an empty array ([]) when the default config is used. InisPathAllowed(), there is an explicit check:constallowedDirectories=awaitgetAllowedDirs();if(allowedDirectories.includes('/')||allowedDirectories.length===0){returntrue;}Because
allowedDirectories.length === 0evaluates to true,all filesystem paths remain allowed by default—preserving the original, unrestricted behavior on fresh installs. The reviewer’s concern that[]would lock out FS access overlooks this secondary fallback inisPathAllowed.No modifications to the defaults or filesystem utils are required.
Likely an incorrect or invalid review comment.
| readOnlyDirectories?:string[];// Directories that can be read but not modified | ||
| requireExplicitPermission?:boolean;// Require explicit flag for destructive commands | ||
| allowedSudoCommands?:string[];// Whitelist of allowed sudo commands with pattern support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
💡 Verification agent
🧩 Analysis chain
Safety config keys: good foundation; wire up parsing and enforcement semantics next
- These optional props keep backwards compatibility. Good.
- Ensure the CLI/tooling can set these array-typed keys from string inputs. In src/tools/config.ts, setConfigValue currently special-cases only 'allowedDirectories' and 'blockedCommands'. Please include 'readOnlyDirectories' and 'allowedSudoCommands' to avoid storing a single string when a user passes JSON or a comma-separated string.
Example adjustment in src/tools/config.ts (illustrative; outside this diff):
// Extend the known array keys setconstarrayKeys=newSet(['allowedDirectories','blockedCommands','readOnlyDirectories','allowedSudoCommands',]);// Then use: if (arrayKeys.has(parsed.data.key) && !Array.isArray(valueToStore)) { ... }
- Define precedence now to avoid ambiguity later: if a path appears in both allowedDirectories and readOnlyDirectories, writes must be denied. Document and enforce this in the file ops layer.
- “Pattern support” for allowedSudoCommands: specify the dialect (glob vs regex), anchoring rules, and escaping to prevent surprising matches.
To verify coverage now, run:
🏁 Script executed:
#!/bin/bash# Find usages of the new keys to ensure setter/parsing/enforcement existsrg -n -C2 -g'!**/dist/**' -e'\breadOnlyDirectories\b|\brequireExplicitPermission\b|\ballowedSudoCommands\b' src
Length of output: 1477
#!/bin/bash# Inspect setConfigValue implementation and array key handlingecho"---- Searching for setConfigValue declaration ----"rg -n -C3"setConfigValue" -g'src/tools/config.ts'echo -e"\n---- Checking arrayKeys or similar handling ----"rg -n -C3"allowedDirectories" -g'src/tools/config.ts'rg -n -C3"blockedCommands" -g'src/tools/config.ts'rg -n -C3"readOnlyDirectories" -g'src/tools/config.ts'rg -n -C3"allowedSudoCommands" -g'src/tools/config.ts'
#!/bin/bash# Locate and inspect the setConfigValue implementationecho"---- Finding setConfigValue definition ----"rg -n -C5"function setConfigValue" -g'src/tools/config.ts'echo -e"\n---- Showing 20 lines around setConfigValue ----"rg -n -C10"setConfigValue" -g'src/tools/config.ts'echo -e"\n---- Searching for multi-value or array key handling ----"rg -n -C5"arrayKeys" -g'src/tools/config.ts'rg -n -C5"multiValue" -g'src/tools/config.ts'rg -n -C5"split" -g'src/tools/config.ts'
#!/bin/bash# Locate and inspect setConfigValue implementation in src/tools/config.tsecho"---- setConfigValue definition and context ----"rg -n -C5"function setConfigValue" -g'src/tools/config.ts'echo -e"\n---- References to array key handling ----"rg -n -C5"new Set" -g'src/tools/config.ts'rg -n -C5"allowedDirectories" -g'src/tools/config.ts'
🏁 Script executed:
#!/bin/bash# Inspect setConfigValue in src/tools/config.ts for array key parsingrg -n -C5"function setConfigValue" src/tools/config.tsrg -n -C5"switch (key)" src/tools/config.tsrg -n -C5"allowedDirectories" src/tools/config.tsrg -n -C5"blockedCommands" src/tools/config.tsrg -n -C5"readOnlyDirectories" src/tools/config.tsrg -n -C5"allowedSudoCommands" src/tools/config.ts
Length of output: 1669
Handle new config keys insetConfigValue and enforce semantics
The special-case logic insrc/tools/config.ts currently only parses JSON/comma-lists forallowedDirectories andblockedCommands. We need to extend it to cover bothreadOnlyDirectories andallowedSudoCommands, and then implement the enforcement semantics you outlined.
• Insrc/tools/config.ts:setConfigValue(), update the array-key check to include the two new keys (and ensurerequireExplicitPermission stays boolean-only).
- if ((parsed.data.key === 'allowedDirectories' || parsed.data.key === 'blockedCommands') && !Array.isArray(valueToStore)) {+ const arrayKeys = new Set([+ 'allowedDirectories',+ 'blockedCommands',+ 'readOnlyDirectories',+ 'allowedSudoCommands',+ ]);+ if (arrayKeys.has(parsed.data.key) && !Array.isArray(valueToStore)) {
• Define and document precedence in your file-operations layer:
– If a path appears in bothallowedDirectories andreadOnlyDirectories, forbid write operations (read-only wins).
– IfrequireExplicitPermission istrue, any destructive command (e.g.,rm,mv) must be gated behind an explicit flag.
• ForallowedSudoCommands, specify the pattern dialect and matching rules in comments and/or schema:
– Glob vs. regex? Anchoring (full-match vs. substring)?
– How to escape metacharacters?
– Reject/escape invalid patterns at set time.
Please update the code and documentation accordingly before merging.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In src/config-manager.ts around lines 13 to 15: extend setConfigValue handlingso array-parsing includes readOnlyDirectories and allowedSudoCommands whilekeeping requireExplicitPermission treated only as a boolean; updatesrc/tools/config.ts:setConfigValue() to treat allowedDirectories,blockedCommands, readOnlyDirectories, and allowedSudoCommands as array-keys(parse JSON or comma-lists) and validate/normalize values on set (reject invalidtypes). In the file-operations layer implement and document precedence: if apath is in both allowedDirectories and readOnlyDirectories, consider itread-only and block write operations; if requireExplicitPermission is true, gatedestructive commands (e.g., rm, mv, rmdir, truncate) behind an explicitpermission flag check. For allowedSudoCommands add clear schema comments statingthe pattern dialect (use anchored glob patterns, full-match semantics, e.g.,bash-style globs, not regex), document how to escape metacharacters, validatepatterns at set time (reject malformed globs) and implement matching as afull-match glob against the entire command string; log or surface invalidpatterns when set. Ensure docs/comments reflect precedence and enforcement rulesand that invalid config values produce clear errors when set.
Uh oh!
There was an error while loading.Please reload this page.
PR 1: Configuration Schema
Title: feat: Add configuration schema for safety features
Description:
This PR adds the foundation for safety features without changing any existing behavior.
What this adds:
readOnlyDirectoriesconfiguration option (empty by default)requireExplicitPermissionflag for destructive commands (false by default)allowedSudoCommandsarray for sudo whitelist (empty by default)Why this matters:
Sets up the configuration structure needed for safety features while maintaining 100% backward compatibility.
Testing:
Breaking changes:
None - all new options have safe defaults that maintain current behavior.
Summary by CodeRabbit