Skip to content

Commit bd38439

Browse files
nik13claude
andcommitted
fix(claude-cowork): non-ASCII auth header, rejected results, opt-in privacy wording (TH-8296)
- Compare the bearer token as bytes: hmac.compare_digest raised TypeError on a non-ASCII Authorization header, so an unauthenticated client got a traceback and no reply instead of 401. - cowork.tool_calls counts only tools that ran: a tool_result whose decision was reject is one reject span and is not counted. - Page: with FI_BRIDGE_CAPTURE_CONTENT=1, tool input and tool error text carry commands, file paths, URLs and emails as Cowork sends them; the tool_parameters name filter's exact rule (128 chars, no / \ @ or line break); the built-in-server name exception cites Claude Code's reference. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a6b52f1 commit bd38439

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎examples/coding-agents/claude-cowork/bridge.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,9 @@ def spans(self, p: Prompt) -> List[Span]:
442442
p.root.attrs[key] = sum(c.attrs.get(src) or 0 for c in used)
443443
# A failed model request that Cowork retried successfully stays ERROR on its own span only.
444444
p.root.error = "model request failed" if llms and llms[-1].error is not None else None
445-
p.root.attrs["cowork.tool_calls"] = sum(1 for c in p.children if c.from_result)
445+
# Tools that ran: a tool_result whose decision was reject never executed.
446+
p.root.attrs["cowork.tool_calls"] = sum(1 for c in p.children
447+
if c.from_result and c.attrs.get("cowork.decision") != "reject")
446448
out = [p.root] + [c for c in p.children if not c.sent]
447449
for c in out[1:]: # session and user on every span, as the family emitter does
448450
for k in IDENTITY:
@@ -554,7 +556,9 @@ class Handler(BaseHTTPRequestHandler):
554556

555557
def do_POST(self): # noqa: N802
556558
# Nothing is read from the body before the token and path are checked.
557-
if token and not hmac.compare_digest(self.headers.get("Authorization", ""), "Bearer " + token):
559+
# Compared as bytes: compare_digest raises on non-ASCII str, which a client controls.
560+
sent = self.headers.get("Authorization", "").encode("utf-8", "replace")
561+
if token and not hmac.compare_digest(sent, ("Bearer " + token).encode("utf-8")):
558562
return self.reject(401, "missing or wrong bearer token")
559563
if self.path.split("?")[0].rstrip("/") not in ("", "/v1/logs"):
560564
return self.reject(404, "this bridge accepts OTLP logs on /v1/logs; enter the bare host as the "

‎examples/coding-agents/claude-cowork/tests/test_bridge.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ def test_reject_then_accept_same_tool_keeps_the_reject(self):
240240
root = [a for _, s, a in spans if "parentSpanId" not in s][0]
241241
self.assertEqual(root["cowork.tool_calls"], 1) # the rejected call never ran
242242

243+
def test_rejected_call_with_a_tool_result_is_one_span_and_not_counted(self):
244+
spans = self.mapped(rec("user_prompt", 0, 0),
245+
rec("tool_decision", 1, 1, tool_name="Bash", decision="reject", source="user_reject"),
246+
rec("tool_result", 2, 2, tool_name="Bash", success="false", decision_type="reject",
247+
decision_source="user_reject"))
248+
tools = [(s["name"], a["cowork.decision"]) for _, s, a in spans if a["fi.span.kind"] == "TOOL"]
249+
self.assertEqual(tools, [("Bash", "reject")])
250+
root = [a for _, s, a in spans if "parentSpanId" not in s][0]
251+
self.assertEqual(root["cowork.tool_calls"], 0)
252+
243253
def test_tool_use_id_pairs_decision_and_result(self):
244254
spans = self.mapped(rec("user_prompt", 0, 0),
245255
rec("tool_decision", 1, 1, tool_name="Read", decision="accept", tool_use_id="toolu_1"),
@@ -379,6 +389,9 @@ def test_token_is_checked_before_the_body_is_read(self):
379389
code = self.raw_post(port, {"Content-Type": "application/json", "Content-Length": 10**9}) # no body sent
380390
self.assertEqual(code, 401)
381391
self.assertLess(time.monotonic() - start, 3)
392+
# A non-ASCII header is a wrong token, not a crash with no reply.
393+
auth = {"Authorization": "Bearer téken", "Content-Type": "application/json", "Content-Length": 2}
394+
self.assertEqual(self.raw_post(port, auth, b"{}"), 401)
382395

383396
def test_bridge_will_not_start_without_a_token(self):
384397
env = {k: v for k, v in os.environ.items() if not k.startswith("FI_")}

‎src/pages/docs/integrations/coding-agents/claude-cowork.mdx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Cowork's exporter delivers at least once. The bridge skips a record identical to
123123

124124
- **A span hierarchy below the prompt.** Cowork's events say which prompt they belong to, not which model request started which tool. Model requests and tools are all children of the prompt span, in time order.
125125
- **Skills and plugins as their own spans.** The reference documents no event for them. A skill call is a tool span (named `Skill` in Claude Code's events) with the skill name in `cowork.skill_name`.
126-
- **MCP server, tool, and skill names when Cowork sends no `tool_parameters`.** The names come only from `tool_parameters`, which is part of Cowork's tool-details content. With `otlpContentCapture` set to `[]`, Cowork may leave it out (Anthropic keeps the names for Claude Desktop's built-in servers), and MCP calls then show as `mcp_tool`.
126+
- **MCP server, tool, and skill names when Cowork sends no `tool_parameters`.** The names come only from `tool_parameters`, which is part of Cowork's tool-details content. With `otlpContentCapture` set to `[]`, Cowork may leave it out, and MCP calls then show as `mcp_tool` and skill calls as `Skill`. Claude Code's [monitoring reference](https://code.claude.com/docs/en/monitoring-usage) says the server and tool names of Claude Desktop's built-in servers are still sent.
127127
- **Cowork's beta trace export.** On third-party deployments of Claude Desktop, an `otlpTracesEnabled` setting (beta) adds trace spans; it is not covered here.
128128
- **Code tab and CLI sessions.** They are Claude Code, not Cowork. The bridge ignores events whose `service.name` is not `cowork` (Claude Code sends `claude-code`).
129129
- **Live verification.** The bridge was tested with documented payloads and Claude Code's live events, not yet with a Cowork organization.
@@ -136,10 +136,10 @@ By default the bridge forwards metadata only, whatever Cowork sends. On a first-
136136
| --- | --- | --- |
137137
| `prompt` (prompt text) | dropped | prompt span input |
138138
| `response` (model response text) | dropped | prompt span output |
139-
| `tool_input` (tool arguments) | dropped | tool span input |
140-
| `error` on a failed `tool_result` | dropped, status message is `tool failed` | status message |
139+
| `tool_input` (tool arguments) | dropped | tool span input, as Cowork sends it: shell commands, file paths, URLs, and any email addresses in the arguments |
140+
| `error` on a failed `tool_result` | dropped, status message is `tool failed` | status message, which can name files, paths, and accounts |
141141
| `error` on `api_error` (the API's message) | dropped, status message is the HTTP status and the Anthropic error type, such as `HTTP 429 rate_limit_error` | status message |
142-
| `tool_parameters` (commands, file paths, URLs, MCP server and tool names, skill names) | names only: the values of `mcp_server_name`, `mcp_tool_name`, `skill_name`, and `subagent_type`, and only when the value contains no `/`, `\`, or `@`. Commands, file paths, URLs, and every other key are dropped | same as default |
142+
| `tool_parameters` (commands, file paths, URLs, MCP server and tool names, skill names) | names only: the values of `mcp_server_name`, `mcp_tool_name`, `skill_name`, and `subagent_type`, and only when the value has at most 128 characters and no `/`, `\`, `@`, or line break. Commands, file paths, URLs, and every other key are dropped | same as default |
143143
| `user.email`, `user.account_id`, the device-level `user.id`, `workspace.host_paths`, `enduser.id`, `process.owner` | dropped (`user.id` in Future AGI is the account UUID) | dropped |
144144

145145
The bridge has no pass-through. A field that is not in the table above or in [What is captured](#what-is-captured) is not forwarded, so a new field Cowork adds later stays out until the bridge maps it. MCP server, tool, and skill names are names your admins or users chose (for example a connector called `gmail`); they are kept so tool spans can be told apart.

0 commit comments

Comments
 (0)