mirror of
https://github.com/instructkr/claw-code.git
synced 2026-12-02 00:00:34 +08:00
fix(config): also ignore the legacy top-level permissionMode from project settings
A project .claw.json could still set "permissionMode": "danger-full-access", which permission_mode() reads before permissions.defaultMode.
This commit is contained in:
2 files changed
+37
-1
No files matched your search
@@ -597,7 +597,7 @@ The list is also the precedence chain: project-local settings override project s
|
||||
Project-local config files (`.claw.json`, `.claw/settings.json`) are loaded from the repository and are not individually approved by the user. To prevent accidental or malicious escalation of privileges, `claw` strips the following settings from project-local files:
|
||||
|
||||
- **Hooks** (`hooks.*`): Project hooks are always stripped. User and local settings (`.claw/settings.local.json`) may define hooks.
|
||||
- **Permission grants** (`permissions.allow`, `permissions.defaultMode`): Project files cannot grant elevated permissions. User and local settings may set these.
|
||||
- **Permission grants** (`permissions.allow`, `permissions.defaultMode`, legacy top-level `permissionMode`): Project files cannot grant elevated permissions. User and local settings may set these.
|
||||
- **Permission restrictions** (`permissions.deny`, `permissions.ask`) remain active from project files, as they only limit access.
|
||||
|
||||
When a project file attempts to use stripped settings, a warning is emitted: `Ignoring project <setting> in <path> because project trust approval is not supported.` To configure permissions for a repository, place settings in `~/.claw/settings.json` (user-level) or `.claw/settings.local.json` (local-only, typically gitignored).
|
||||
|
||||
@@ -695,6 +695,14 @@ fn strip_untrusted_project_settings(
|
||||
));
|
||||
}
|
||||
|
||||
// The legacy top-level `permissionMode` key selects the mode too.
|
||||
if object.remove("permissionMode").is_some() {
|
||||
warnings.push(format!(
|
||||
"Ignoring project permissionMode in {} because project trust approval is not supported.",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
|
||||
// Strip permissions.allow and permissions.defaultMode, keep deny and ask
|
||||
if let Some(JsonValue::Object(permissions)) = object.get_mut("permissions") {
|
||||
let had_allow = permissions.remove("allow").is_some();
|
||||
@@ -3772,6 +3780,34 @@ mod tests {
|
||||
fs::remove_dir_all(root).expect("cleanup temp dir");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn project_config_legacy_permission_mode_cannot_escalate() {
|
||||
// given
|
||||
let root = temp_dir();
|
||||
let cwd = root.join("project");
|
||||
let home = root.join("home").join(".claw");
|
||||
fs::create_dir_all(&cwd).expect("project dir");
|
||||
fs::create_dir_all(&home).expect("home config dir");
|
||||
fs::write(
|
||||
cwd.join(".claw.json"),
|
||||
r#"{"permissionMode":"danger-full-access"}"#,
|
||||
)
|
||||
.expect("write untrusted legacy project permission mode");
|
||||
|
||||
// when
|
||||
let (loaded, warnings) = ConfigLoader::new(&cwd, &home)
|
||||
.load_collecting_warnings()
|
||||
.expect("config should load");
|
||||
|
||||
// then
|
||||
assert_eq!(loaded.permission_mode(), None);
|
||||
assert!(warnings
|
||||
.iter()
|
||||
.any(|warning| warning.contains("Ignoring project permissionMode")));
|
||||
|
||||
fs::remove_dir_all(root).expect("cleanup temp dir");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn permission_mode_aliases_resolve_to_expected_modes() {
|
||||
// given / when / then
|
||||
|
||||
Reference in new issue
Block a user