harden: enforce path-safe subagent IDs at ExtractSpawnedAgentIDs

main

Commit

Soph3mo ago

CalculateTotalTokenUsage and ExtractAllModifiedFiles build agent-<id>.jsonl from subagent IDs and read that file, with no local validation of the ID. Today the IDs are path-safe only because their sole source, extractAgentIDFromText, happens to accept just [a-zA-Z0-9]. That makes the path-safety of a file read depend on the incidental character set of a parser two calls away — a fragile coupling: relaxing extractAgentIDFromText (e.g. to accept hyphenated UUIDs) would silently open a traversal-read of arbitrary agent-*.jsonl-shaped paths.

Enforce the invariant at the choke point: ExtractSpawnedAgentIDs now drops any ID that fails validation.ValidateAgentID, so every downstream agent-<id>.jsonl consumer (claudecode + factoryaidroid, token usage and modified-files) is path-safe by construction.

Not a live vulnerability — the current parser already constrains the ID, so the guard is a no-op for today's inputs and adds no behavior change. No test is added: the guarded branch is unreachable through the real extractor (it can't emit a non-path-safe ID), so a test would only exercise dead input.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com Entire-Checkpoint: c56a01dc268e

Checkpoints

Review Security Vulnerability Report

Claude CodeOpus 4.8[1m]
View session
Checkpoint 1