Compare commits

...
Author SHA1 Message Date
clawdbot cf4cc72a73 test(prompt): load permissionMode fixture from local settings
Project-scope permissionMode is now ignored, so the prompt rendering
fixtures use .claw/settings.local.json.
2026-11-29 03:13:10 +00:00
clawdbot f64bd3f7f7 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.
2026-11-29 03:06:57 +00:00
Watch eef0938e07 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
2026-11-29 02:59:58 +00:00
3 changed files with 141 additions and 28 deletions

No files matched your search

+10
View File
@@ -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`, 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).
## 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:
+129 -26
View File
@@ -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,55 @@ impl ConfigLoader {
}
}
fn strip_untrusted_project_hooks(
fn strip_untrusted_project_settings(
source: ConfigSource,
object: &mut BTreeMap<String, JsonValue>,
path: &Path,
) -> Option<String> {
// 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<String> {
// 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()
));
}
// 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();
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 +3733,81 @@ 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 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
+2 -2
View File
@@ -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");