From eef0938e079b03b810d6624f62414beca8024e32 Mon Sep 17 00:00:00 2001 From: Watch Date: Sun, 29 Nov 2026 02:59:58 +0000 Subject: [PATCH 1/3] fix(config): ignore permission grants from untrusted project settings Strip permissions.allow and permissions.defaultMode from project-local config files (.claw.json, .claw/settings.json) to prevent privilege escalation. Keep restrictive permissions (deny, ask) from project files. Add test verifying that project-granted permissions do not reach runtime. Document untrusted project settings behavior in USAGE.md. Fixes #3414 --- USAGE.md | 10 +++ rust/crates/runtime/src/config.rs | 119 +++++++++++++++++++++++------- 2 files changed, 103 insertions(+), 26 deletions(-) diff --git a/USAGE.md b/USAGE.md index 60db84bfa1..4a4121b6ed 100644 --- a/USAGE.md +++ b/USAGE.md @@ -592,6 +592,16 @@ Runtime config is loaded in this order, with later entries overriding earlier on The list is also the precedence chain: project-local settings override project settings, project settings override the legacy project `.claw.json`, and project files override user files. `claw --output-format json config` includes each discovered file's `precedence_rank`, `wins_for_keys`, and `shadowed_keys` so automation can see which file controls each effective key without reimplementing the merge order. +### Untrusted project settings + +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 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 in 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). + ## MCP server validation `claw mcp --output-format json` loads valid `mcpServers` entries even when sibling entries are malformed. The JSON list envelope distinguishes the total configured entries from the valid and invalid subsets: diff --git a/rust/crates/runtime/src/config.rs b/rust/crates/runtime/src/config.rs index 67c274cb35..b809885576 100644 --- a/rust/crates/runtime/src/config.rs +++ b/rust/crates/runtime/src/config.rs @@ -480,11 +480,9 @@ impl ConfigLoader { continue; }; let ParsedConfigFile { mut object, source } = parsed; - if let Some(warning) = - strip_untrusted_project_hooks(entry.source, &mut object, &entry.path) - { - all_warnings.push(warning); - } + let settings_warnings = + strip_untrusted_project_settings(entry.source, &mut object, &entry.path); + all_warnings.extend(settings_warnings); let validation = crate::config_validate::validate_config_file(&object, &source, &entry.path); if !validation.is_ok() { @@ -527,11 +525,9 @@ impl ConfigLoader { continue; }; let ParsedConfigFile { mut object, source } = parsed; - if let Some(warning) = - strip_untrusted_project_hooks(entry.source, &mut object, &entry.path) - { - all_warnings.push(warning); - } + let settings_warnings = + strip_untrusted_project_settings(entry.source, &mut object, &entry.path); + all_warnings.extend(settings_warnings); let validation = crate::config_validate::validate_config_file(&object, &source, &entry.path); if !validation.is_ok() { @@ -607,11 +603,9 @@ impl ConfigLoader { }; let ParsedConfigFile { mut object, source } = parsed; - if let Some(warning) = - strip_untrusted_project_hooks(entry.source, &mut object, &entry.path) - { - warnings.push(warning); - } + let settings_warnings = + strip_untrusted_project_settings(entry.source, &mut object, &entry.path); + warnings.extend(settings_warnings); let validation = crate::config_validate::validate_config_file(&object, &source, &entry.path); if !validation.is_ok() { @@ -681,21 +675,47 @@ impl ConfigLoader { } } -fn strip_untrusted_project_hooks( +fn strip_untrusted_project_settings( source: ConfigSource, object: &mut BTreeMap, path: &Path, -) -> Option { - // Project settings come from the repository and there is no project-hook - // trust approval flow yet. User and local settings remain eligible. - if source == ConfigSource::Project && object.remove("hooks").is_some() { - Some(format!( - "Ignoring project hooks in {} because project-hook trust approval is not supported.", - path.display() - )) - } else { - None +) -> Vec { + // Project settings come from the repository and there is no project trust + // approval flow yet. User and local settings remain eligible. + // We strip hooks (all types) and permissions grants (allow, defaultMode), + // but keep permission restrictions (deny, ask) as they only limit access. + let mut warnings = Vec::new(); + + if source == ConfigSource::Project { + // Strip hooks entirely + if object.remove("hooks").is_some() { + warnings.push(format!( + "Ignoring project hooks in {} because project-hook 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(); + let had_default_mode = permissions.remove("defaultMode").is_some(); + + if had_allow { + warnings.push(format!( + "Ignoring project permissions.allow in {} because project trust approval is not supported.", + path.display() + )); + } + if had_default_mode { + warnings.push(format!( + "Ignoring project permissions.defaultMode in {} because project trust approval is not supported.", + path.display() + )); + } + } } + + warnings } impl ConfigFileReport { @@ -3705,6 +3725,53 @@ mod tests { fs::remove_dir_all(root).expect("cleanup temp dir"); } + #[test] + fn project_config_permissions_cannot_grant_access() { + // given + let root = temp_dir(); + let cwd = root.join("project"); + let home = root.join("home").join(".claw"); + let project_settings = cwd.join(".claw").join("settings.json"); + fs::create_dir_all(project_settings.parent().expect("project config dir")) + .expect("create project config dir"); + fs::create_dir_all(&home).expect("home config dir"); + + // Project tries to grant permissions.allow and set defaultMode to danger-full-access, + // but also includes restrictive permissions that should be kept + fs::write( + &project_settings, + r#"{"permissions":{"allow":["bash"],"defaultMode":"dontAsk","deny":["rm"],"ask":["Edit"]}}"#, + ) + .expect("write untrusted project permissions"); + + // when + let (loaded, warnings) = ConfigLoader::new(&cwd, &home) + .load_collecting_warnings() + .expect("config should load"); + + // then: project permissions.allow and defaultMode are stripped, but deny and ask remain + assert!(loaded.permission_rules().allow().is_empty()); + assert_eq!(loaded.permission_mode(), None); + assert_eq!(loaded.permission_rules().deny(), &["rm".to_string()]); + assert_eq!(loaded.permission_rules().ask(), &["Edit".to_string()]); + assert_eq!( + warnings + .iter() + .filter(|warning| warning.contains("Ignoring project permissions.allow")) + .count(), + 1 + ); + assert_eq!( + warnings + .iter() + .filter(|warning| warning.contains("Ignoring project permissions.defaultMode")) + .count(), + 1 + ); + + fs::remove_dir_all(root).expect("cleanup temp dir"); + } + #[test] fn permission_mode_aliases_resolve_to_expected_modes() { // given / when / then From f64bd3f7f731dc5fe4ba3067576bce1cd9b4c43f Mon Sep 17 00:00:00 2001 From: clawdbot Date: Sun, 29 Nov 2026 03:06:57 +0000 Subject: [PATCH 2/3] 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. --- USAGE.md | 2 +- rust/crates/runtime/src/config.rs | 36 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/USAGE.md b/USAGE.md index 4a4121b6ed..e0aa298d25 100644 --- a/USAGE.md +++ b/USAGE.md @@ -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 in 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). diff --git a/rust/crates/runtime/src/config.rs b/rust/crates/runtime/src/config.rs index b809885576..2af3d80e1e 100644 --- a/rust/crates/runtime/src/config.rs +++ b/rust/crates/runtime/src/config.rs @@ -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 From cf4cc72a73ae8a63d243e2caaf2374d046b2a9c5 Mon Sep 17 00:00:00 2001 From: clawdbot Date: Sun, 29 Nov 2026 03:13:10 +0000 Subject: [PATCH 3/3] test(prompt): load permissionMode fixture from local settings Project-scope permissionMode is now ignored, so the prompt rendering fixtures use .claw/settings.local.json. --- rust/crates/runtime/src/prompt.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/crates/runtime/src/prompt.rs b/rust/crates/runtime/src/prompt.rs index bb8052b583..138de3366a 100644 --- a/rust/crates/runtime/src/prompt.rs +++ b/rust/crates/runtime/src/prompt.rs @@ -1255,7 +1255,7 @@ mod tests { fs::create_dir_all(root.join(".claw")).expect("claw dir"); fs::write(root.join("CLAUDE.md"), "Project rules").expect("write instructions"); fs::write( - root.join(".claw").join("settings.json"), + root.join(".claw").join("settings.local.json"), r#"{"permissionMode":"acceptEdits"}"#, ) .expect("write settings"); @@ -1418,7 +1418,7 @@ mod tests { fs::create_dir_all(root.join(".claw")).expect("claw dir"); fs::write(root.join("CLAUDE.md"), "Project rules").expect("write CLAUDE.md"); fs::write( - root.join(".claw").join("settings.json"), + root.join(".claw").join("settings.local.json"), r#"{"permissionMode":"acceptEdits"}"#, ) .expect("write settings");