Compare commits

...
Author SHA1 Message Date
Watch b867577041 fix(permissions): read-only and plan mode are a ceiling that allow rules cannot lift
This fix addresses issue #3412 where allow rules in read-only mode could
grant access to tools requiring higher permission levels.

Changes:
- Read-only mode is now a ceiling for allow rules: even if an allow rule
  matches, tools requiring higher permissions will be denied in read-only mode
- This applies to both explicit allow rules and hook-provided Allow overrides
- Plan mode (which parses to read-only) now also enforces the ceiling
- Updated USAGE.md to document that read-only is a ceiling for allow rules
- Added comprehensive tests verifying the read-only ceiling behavior

The fix prevents the security issue where untrusted cloned repositories
could ship permissions.allow rules in .claw/settings.json to bypass
read-only mode.

Fixes #3412
2026-11-29 02:00:38 +00:00
BellmanandWatch 0492eb3aa5 release: v0.1.16 (#3411)
- Bump version 0.1.15 -> 0.1.16
- Add CHANGELOG entry for #3410 hook BrokenPipe fix

Co-authored-by: Watch <watch@local>
2026-11-27 20:46:25 +00:00
Jay Pokale 365fa14cf8 fix(runtime): tolerate BrokenPipe when writing the hook payload to stdin (#3410)
A hook that exits without reading all of its stdin closes the pipe while
CommandWithStdin::output_with_stdin is still writing the JSON payload.
The write fails with BrokenPipe, and the error was propagated, so the hook
was reported as "failed to start ...: Broken pipe (os error 32)" even
though it ran and exited normally. A failed PreToolUse hook then denies
the tool call, and a failed PostToolUse hook marks the tool result as an
error.

Any payload larger than the pipe buffer (64 KiB on Linux) triggers it for
a hook that does not read stdin. The payload carries tool_input twice, so
a write_file of about 40 KB is enough.

plugins/src/hooks.rs already tolerates BrokenPipe for the same reason
(ROADMAP #25). Apply the same handling to the runtime hook runner, and
add a regression test.
2026-11-27 20:34:02 +00:00
Bellmanandclawdbot 0210856f6b docs(changelog): correct v0.1.15 gateway docs attribution (#3409)
Co-authored-by: clawdbot <clawdbot@ultraworkers.dev>
2026-11-27 05:10:42 +00:00
7 changed files with 208 additions and 19 deletions

No files matched your search

+8 -1
View File
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.1.16] - 2026-11-27
### Fixed
- Hooks no longer fail with BrokenPipe when a hook exits without reading a stdin payload larger than the pipe buffer (#3410)
## [0.1.15] - 2026-11-27
### Added
@@ -13,7 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Documentation: document WorldRouter OpenAI-compatible gateway setup (#3399)
- Documentation: document WorldRouter OpenAI-compatible gateway setup (d53a0882)
- Documentation: document onomeo OpenAI-compatible gateway setup (#3399)
- Documentation: document Straitly OpenAI-compatible gateway setup (#3400)
- Documentation: document TeamoRouter OpenAI-compatible gateway setup (#3402)
- Documentation: document TrustedRouter OpenAI-compatible gateway setup (#3403)
+1 -1
View File
@@ -211,7 +211,7 @@ Global workspace override flags: `--cwd PATH`, `-C PATH`, and `--directory PATH`
Supported permission modes (default: `workspace-write`):
- `read-only` allows inspection-only local tools such as file reads, glob/grep searches, local skills, and status-style reporting. It does not allow workspace mutation, network-fetch/search tools, or arbitrary command execution.
- `read-only` allows inspection-only local tools such as file reads, glob/grep searches, local skills, and status-style reporting. It does not allow workspace mutation, network-fetch/search tools, or arbitrary command execution. `read-only` is a ceiling: even if an allow rule is configured, it cannot grant access to tools requiring higher permissions.
- `workspace-write` is the safe default. It allows reads plus direct file-editing tools inside the current workspace, including write/edit/notebook/config/plan-mode updates, while still gating network-fetch/search tools, arbitrary shell execution, subagent launches, REPL subprocesses, and other full-access tools behind an explicit escalation.
- `danger-full-access` allows every registered tool requirement, including arbitrary command execution, web fetch/search, subagent launches, subprocess REPLs, and unrestricted tool access. Select it only with an explicit `--permission-mode danger-full-access`, `--dangerously-skip-permissions`, `--skip-permissions`, env, or config opt-in.
+11 -11
View File
@@ -93,7 +93,7 @@ checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
[[package]]
name = "api"
version = "0.1.15"
version = "0.1.16"
dependencies = [
"criterion",
"reqwest",
@@ -478,7 +478,7 @@ checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
[[package]]
name = "claw-analog"
version = "0.1.15"
version = "0.1.16"
dependencies = [
"api",
"clap",
@@ -498,7 +498,7 @@ dependencies = [
[[package]]
name = "claw-rag-service"
version = "0.1.15"
version = "0.1.16"
dependencies = [
"axum 0.8.9",
"blake3",
@@ -531,7 +531,7 @@ checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
[[package]]
name = "commands"
version = "0.1.15"
version = "0.1.16"
dependencies = [
"plugins",
"runtime",
@@ -540,7 +540,7 @@ dependencies = [
[[package]]
name = "compat-harness"
version = "0.1.15"
version = "0.1.16"
dependencies = [
"commands",
"runtime",
@@ -1568,7 +1568,7 @@ dependencies = [
[[package]]
name = "mock-anthropic-service"
version = "0.1.15"
version = "0.1.16"
dependencies = [
"api",
"serde_json",
@@ -1761,7 +1761,7 @@ dependencies = [
[[package]]
name = "plugins"
version = "0.1.15"
version = "0.1.16"
dependencies = [
"serde",
"serde_json",
@@ -2136,7 +2136,7 @@ dependencies = [
[[package]]
name = "runtime"
version = "0.1.15"
version = "0.1.16"
dependencies = [
"getrandom 0.2.17",
"glob",
@@ -2263,7 +2263,7 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]]
name = "rusty-claude-cli"
version = "0.1.15"
version = "0.1.16"
dependencies = [
"api",
"commands",
@@ -2624,7 +2624,7 @@ dependencies = [
[[package]]
name = "telemetry"
version = "0.1.15"
version = "0.1.16"
dependencies = [
"serde",
"serde_json",
@@ -2904,7 +2904,7 @@ dependencies = [
[[package]]
name = "tools"
version = "0.1.15"
version = "0.1.16"
dependencies = [
"api",
"aspect-core",
+1 -1
View File
@@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2"
[workspace.package]
version = "0.1.15"
version = "0.1.16"
edition = "2021"
license = "MIT"
publish = false
+1 -1
View File
@@ -82,7 +82,7 @@ async fn send_message_posts_json_and_parses_response() {
);
assert_eq!(
request.headers.get("user-agent").map(String::as_str),
Some("claude-code/0.1.15")
Some("claude-code/0.1.16")
);
assert_eq!(
request.headers.get("anthropic-beta").map(String::as_str),
+28 -1
View File
@@ -802,7 +802,16 @@ impl CommandWithStdin {
) -> std::io::Result<CommandExecution> {
let mut child = self.command.spawn()?;
if let Some(mut child_stdin) = child.stdin.take() {
child_stdin.write_all(stdin)?;
// A hook that exits without reading all of its stdin closes the pipe
// while the payload is still being written, which fails with
// `BrokenPipe`. That is not a hook failure: its exit status and
// output are still collected below. Same handling as the plugin hook
// runner in `plugins/src/hooks.rs`.
match child_stdin.write_all(stdin) {
Ok(()) => {}
Err(error) if error.kind() == std::io::ErrorKind::BrokenPipe => {}
Err(error) => return Err(error),
}
}
loop {
@@ -860,6 +869,24 @@ mod tests {
assert_eq!(result, HookRunResult::allow(vec!["pre ok".to_string()]));
}
#[test]
#[cfg(unix)]
fn hook_that_ignores_stdin_is_not_failed_by_a_payload_larger_than_the_pipe() {
// The hook never reads stdin and exits while the runner is still writing
// a payload that does not fit in the pipe buffer, so the write fails with
// `BrokenPipe`. The hook itself succeeded and must not be reported as failed.
let runner = HookRunner::new(RuntimeHookConfig::new(
vec![crate::test_hook("pre ok", "", 0, 0)],
Vec::new(),
Vec::new(),
));
let tool_input = serde_json::json!({ "content": "x".repeat(70_000) }).to_string();
let result = runner.run_pre_tool_use("write_file", &tool_input);
assert_eq!(result, HookRunResult::allow(vec!["pre ok".to_string()]));
}
#[test]
fn object_style_hook_matchers_filter_runtime_execution() {
let runner = HookRunner::new(RuntimeHookConfig::from_hook_commands(
+158 -3
View File
@@ -312,7 +312,13 @@ impl PermissionPolicy {
// The ladder, in one place. An `allow` rule is an explicit grant for
// this tool and outranks the mode; otherwise the mode decides through
// [`PermissionMode::covers`].
if allow_rule.is_some() || current_mode.covers(required_mode) {
//
// Exception: read-only is a ceiling. Even with an allow rule, a tool
// requiring a higher permission mode cannot run in read-only mode. This
// ensures that allow rules cannot be used to bypass read-only protection
// in untrusted configurations (e.g., project-scope .claw/settings.json).
let allow_rule_applies = allow_rule.is_some() && current_mode != PermissionMode::ReadOnly;
if allow_rule_applies || current_mode.covers(required_mode) {
return PermissionOutcome::Allow;
}
@@ -748,13 +754,15 @@ mod tests {
#[test]
fn applies_rule_based_denials_and_allows() {
// Test allow/deny rules in a higher permission mode where they can take effect.
// read-only is a ceiling, so allow rules cannot lift it, but deny rules still work.
let rules = RuntimePermissionRuleConfig::new(
vec!["bash(git:*)".to_string()],
vec!["bash(rm -rf:*)".to_string()],
Vec::new(),
Vec::new(),
);
let policy = PermissionPolicy::new(PermissionMode::ReadOnly)
let policy = PermissionPolicy::new(PermissionMode::WorkspaceWrite)
.with_tool_requirement("bash", PermissionMode::DangerFullAccess)
.with_permission_rules(&rules);
@@ -764,7 +772,7 @@ mod tests {
);
assert!(matches!(
policy.authorize("bash", r#"{"command":"rm -rf /tmp/x"}"#, None),
PermissionOutcome::Deny { reason } if reason.contains("denied by rule")
PermissionOutcome::Deny { ref reason } if reason.contains("denied by rule")
));
}
@@ -890,4 +898,151 @@ mod tests {
Some("hook requested confirmation")
);
}
#[test]
fn read_only_ceiling_deny_allow_rule_for_workspace_write_tool() {
let rules = RuntimePermissionRuleConfig::new(
vec!["write_file(*)".to_string()],
Vec::new(),
Vec::new(),
Vec::new(),
);
let policy = PermissionPolicy::new(PermissionMode::ReadOnly)
.with_tool_requirement("write_file", PermissionMode::WorkspaceWrite)
.with_permission_rules(&rules);
let outcome = policy.authorize("write_file", r#"{"path":"test.txt","content":"x"}"#, None);
assert!(
matches!(
outcome,
PermissionOutcome::Deny { ref reason } if reason.contains("read-only")
),
"allow rule should not lift read-only mode: {outcome:?}"
);
}
#[test]
fn read_only_ceiling_deny_allow_rule_for_edit_file() {
let rules = RuntimePermissionRuleConfig::new(
vec!["edit_file(*)".to_string()],
Vec::new(),
Vec::new(),
Vec::new(),
);
let policy = PermissionPolicy::new(PermissionMode::ReadOnly)
.with_tool_requirement("edit_file", PermissionMode::WorkspaceWrite)
.with_permission_rules(&rules);
let outcome = policy.authorize(
"edit_file",
r#"{"path":"test.txt","old_string":"a","new_string":"b"}"#,
None,
);
assert!(
matches!(
outcome,
PermissionOutcome::Deny { ref reason } if reason.contains("read-only")
),
"allow rule should not lift read-only mode: {outcome:?}"
);
}
#[test]
fn read_only_ceiling_deny_allow_rule_for_danger_full_access_tool() {
let rules = RuntimePermissionRuleConfig::new(
vec!["bash(git:*)".to_string()],
Vec::new(),
Vec::new(),
Vec::new(),
);
let policy = PermissionPolicy::new(PermissionMode::ReadOnly)
.with_tool_requirement("bash", PermissionMode::DangerFullAccess)
.with_permission_rules(&rules);
let outcome = policy.authorize("bash", r#"{"command":"git status"}"#, None);
assert!(
matches!(
outcome,
PermissionOutcome::Deny { ref reason } if reason.contains("read-only")
),
"allow rule should not lift read-only mode: {outcome:?}"
);
}
#[test]
fn plan_mode_ceiling_deny_allow_rule_for_workspace_write_tool() {
// plan mode is equivalent to read-only
let rules = RuntimePermissionRuleConfig::new(
vec!["write_file(*)".to_string()],
Vec::new(),
Vec::new(),
Vec::new(),
);
let policy =
PermissionPolicy::new(PermissionMode::ReadOnly) // plan parses to ReadOnly
.with_tool_requirement("write_file", PermissionMode::WorkspaceWrite)
.with_permission_rules(&rules);
let outcome = policy.authorize("write_file", r#"{"path":"test.txt","content":"x"}"#, None);
assert!(
matches!(
outcome,
PermissionOutcome::Deny { ref reason } if reason.contains("read-only")
),
"allow rule should not lift read-only mode (plan is read-only): {outcome:?}"
);
}
#[test]
fn hook_allow_should_not_lift_read_only_ceiling() {
let rules = RuntimePermissionRuleConfig::new(vec![], vec![], vec![], vec![]);
let policy = PermissionPolicy::new(PermissionMode::ReadOnly)
.with_tool_requirement("write_file", PermissionMode::WorkspaceWrite)
.with_permission_rules(&rules);
let context = PermissionContext::new(
Some(PermissionOverride::Allow),
Some("hook approved".to_string()),
);
let outcome = policy.authorize_with_context(
"write_file",
r#"{"path":"test.txt","content":"x"}"#,
&context,
None,
);
assert!(
matches!(
outcome,
PermissionOutcome::Deny { ref reason } if reason.contains("read-only")
),
"hook allow should not lift read-only ceiling: {outcome:?}"
);
}
#[test]
fn allow_rule_still_works_in_workspace_write_mode() {
// Confirm that allow rules still work correctly in higher permission modes
let rules = RuntimePermissionRuleConfig::new(
vec!["bash(git:*)".to_string()],
Vec::new(),
Vec::new(),
Vec::new(),
);
let policy = PermissionPolicy::new(PermissionMode::WorkspaceWrite)
.with_tool_requirement("bash", PermissionMode::DangerFullAccess)
.with_permission_rules(&rules);
let outcome = policy.authorize("bash", r#"{"command":"git status"}"#, None);
assert_eq!(
outcome,
PermissionOutcome::Allow,
"allow rule should still work in workspace-write mode"
);
}
}