Repository navigation
protocol: widen the forbidden prompt-character class to Cc/Cf/Zl/Zp/DICP (#86) - #96
cuihtlauac wants to merge 6 commits into
Conversation
cuihtlauac
left a comment
There was a problem hiding this comment.
🤖 Code review (Fable) — round 1
Verdict: approve-with-nits
Reviewed the whole diff of PR #96 (5 commits, fix/86-dangerous-chars) against the issue's "🤖 Approved plan (Claude) — final" comment. No blocker, no should-fix. The plan is implemented item by item, every deviation is justified, and the deferred nits P4–P10 are handled as the batch rules require (P4–P9 as implementation guidance, P10 applied).
What I verified independently
cargo test(debug, full suite, run twice): all green, includingdangerous_class_matches_unicode_oracle, the property test and the pty goldens (no golden changed; working tree clean afterwards).cargo clippy --all-targets -- -D warningswith--all-featuresand with--no-default-features: clean.cargo deny check: advisories/bans/licenses/sources ok with the new pinned dev-dependency.cargo kani(cargo-kani 0.67.0, run locally): 4/4 harnesses verified;has_dangerous_chars_matches_spec_per_char6.7 s,plan_run_leaf_matches_dangerous_char_spec35 s, both over the wholechardomain withunwind(8).DICP_16_0(src/protocol.rstests) compared entry by entry againstDerivedCoreProperties-16.0.0.txtfetched from unicode.org: identical, unmerged, 27 lines including theCnones (U+2065, U+FFF0–FFF8, U+E0000, U+E0002–E001F, U+E0080–E00FF, U+E01F0–E0FFF). So the oracle test is not derived from the table, as [P1] demanded.DANGEROUS_RANGESby inspection: the 21 Cf ranges of Unicode 16.0.0, Cc, Zl/Zp and every DICP range are present, adjacent ranges coalesced (U+2028–202E, U+2060–206F, U+FFF0–FFFB, U+E0000–E0FFF); sorted and disjoint. The exhaustive test is the real check and it passes.- Formatting: the tree is not rustfmt-clean on
mainand CI does not runcargo fmt. Per-file hunk counts, branch vsmain:src/protocol.rs36/36,src/tui.rs89/89,src/server.rs19/21,src/mcp.rs17/17,src/gui.rs6/6,src/audit.rs1/1,src/proofs.rs0/1,tests/audit.rs0/0,tests/validation.rs9/9 (all pre-existing lines). The implementer's claim holds: no new fmt diff. resolve_command(src/executor.rs) does not canonicalize, so the P5 statement in theresolve_detail/write_resolves_line/gui.rscomments (only the canonical path is caller-influenced, the rest is defence in depth) is accurate.shquote(src/tui.rs) accepts only ASCII alphanumerics and_./:=@%+,-unquoted, so the new threat-model residual's claim that non-ASCII tokens are single-quoted is correct.sanitize_descriptionis applied at the single site wheredescriptionbecomesreason; the otherdescriptionuses insrc/mcp.rs(lines 418, 527) are the host description ofupdate_host, unrelated. Deviation 4 is right.
Deviations from plan (all accepted)
[y|N]file name: a file name cannot contain/; the test still exercises ESC and newline, which is the point.pub(crate)foris_dangerous_char:src/mcp.rsis a module of the library crate (src/lib.rs:18), so this is exactly "the visibility the crate layout needs".- TAB kept in the table and exempted in
is_dangerous_char: matches the rule as written; the oracle test models the same exemption. - One filter site: verified above.
- README instead of
docs/usage.md: theexecutetool is documented in README "Run commands"; the sentence is the plan's. - 27 ranges instead of "about 35": the plan's count was an estimate and the coalescing is what it asked for.
- #95 filed for the zenity Pango-markup note: the plan's "Out of scope" section asked for exactly that.
Findings
Blockers
None.
Should-fix
None.
Follow-up
None.
Nits
- C1 (nit) — PR title. The title is the issue's title ("has_dangerous_chars misses DEL/C1, …"), which reads as a bug report rather than a change once it lands as the merge commit subject. Suggest something like "protocol: widen the forbidden prompt-character class to Cc/Cf/Zl/Zp/DICP (#86)". Cosmetic; only if convenient.
- C2 (nit) —
changelog.md:12:Cc u Cf u Zl u Zpuses an ASCIIufor the set union while the rest of the file already uses non-ASCII punctuation (—,→);∪as in the plan and in theDANGEROUS_RANGESdoc comment would read better. Drop if not editing the line. - C3 (nit, pre-existing, no action expected) —
src/protocol.rs:713escape_dangerous: a backslash is not escaped, so a symlink target literally namedx\u{1b}yprints the same as one containing a raw ESC. No security effect (a dangerous character is always escaped, so a name can look scarier than it is, never tamer), and the auditsafe()and--log-jsonescapers have had the same property since before this PR. Recording it so it is on the record; "dropped" is the expected outcome. - C4 (nit) —
docs/threat-model.md:174: the new sentence under 3.4 ("look-alikereason") argues fromshquote, which applies to argv tokens, not toreason(printed as is). The plan dictated both the wording and the anchor (P10), so this is on the plan, not the implementer; a future touch of that bullet could say "inargv,shquote…". Drop.
Manual test before merging
The PR's "Manual check before merging" list is the right one (reject U+00AD/U+2028 in reason; echo 'café 漢字 — →' prompts normally; an absolute symlink with ESC + newline in its target name shows escaped on Resolves:; MCP execute with "Restart nginx ⚠️" prompts with Reason: Restart nginx ⚠). I have nothing to add to it.
…ICP (#86) has_dangerous_chars only knew C0, three zero-width/bidi ranges, and nothing else: DEL, C1 (NEL, CSI, OSC), soft hyphen, ALM, LS/PS, word joiner and invisible operators, BOM, tag characters and variation selectors all reached the approval prompt. Replace the hand-listed ranges with one table-driven class, dangerous(c) <=> c != TAB && c in Cc u Cf u Zl u Zp u Default_Ignorable_Code_Point, built from the Unicode 16.0.0 UCD (DANGEROUS_RANGES, binary-searched by is_dangerous_char), and reuse it in the audit-record and --log-json escapers. An exhaustive unit test checks the table against a General_Category oracle (unicode-general-category =1.1.0, a pinned test-only dev-dependency) plus a verbatim copy of the DICP list. The env-key error no longer echoes the raw key; this is for consistency (the key only reaches the response, and the audit copy is escaped), not a security fix. Validation messages are otherwise unchanged. Tests: oracle and table-shape tests, a regression table, integration tests over every newly covered character in argv/reason/session/env value/plan Exec/plan Chdir, a non-ASCII accept test, an audit-record escape test, and a property test whose env keys are now valid by construction and whose alphabet includes multibyte text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
The Resolves: text printed canonicalize() output raw. A same-UID caller can exec an absolute symlink whose target name holds ESC or a newline; only argv[0] is validated, so that name reached the prompt verbatim. Print every displayed path through escape_dangerous. Only the canonical path is caller-influenced; escaping the resolved path (tui) and the gui's shown path is defence in depth. Comparisons keep the raw strings, so benign paths render byte-identically and the pty goldens are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
With the widened class, an agent's description such as "Restart nginx" followed by a warning-sign emoji with U+FE0F would make the daemon reject the request. sanitize_description removes every is_dangerous_char character before the description becomes reason; the daemon gate stays strict. The execute tool description says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
) Drop the < 0x2100 bound (tag characters sit at U+E0000). The per-char harness now proves (a) has_dangerous_chars(encode(c)) == is_dangerous_char(c) for every char, (b) an independently written list of the code points #86 names is dangerous, (c) TAB and printable ASCII are not. Exact membership is left to the exhaustive oracle unit test. unwind 8 covers the 4-byte decode and the binary search. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
Assurance case G3.3/G4.1 and their solutions, threat model (control row and the 3.4 residual), security.md, REVIEWING.md C6, the audit-escape note in usage.md, the MCP description note in README, a line under security-audit F1, a changelog entry, and the #86 clause struck from the Phase 0 backlog line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
C2: use set-theory symbols in the changelog rule, as in the DANGEROUS_RANGES doc comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
535cfa2 to
8c65706
Compare
Fixes #86
Part of #89
Summary
Implements the approved plan for #86 ("🤖 Approved plan (Claude) — final").
dangerous(c) ⇔ c ≠ TAB ∧ c ∈ Cc ∪ Cf ∪ Zl ∪ Zp ∪ Default_Ignorable_Code_Point, held asprotocol::DANGEROUS_RANGES(27 sorted, disjoint ranges built from the Unicode 16.0.0 UCD) and looked up byis_dangerous_char(binary search).has_dangerous_charsis nows.chars().any(is_dangerous_char), so every validated field and plan leaf gets the wider class with no other edit. The auditsafe()escaper and the--log-jsonescape_for_terminalreuse the same predicate.canonicalizeoutput (and, as defence in depth, the resolved path and the zenityshownpath) is printed through the newescape_dangerous. A same-UID caller could otherwise put ESC/newline on the prompt through an absolute symlink's target name, which never goes through validation. Comparisons keep the raw strings, so benign paths render byte-identically.sanitize_descriptionstrips the class fromdescriptionbefore it becomesreason, so"Restart nginx ⚠️"(U+FE0F) keeps working. The daemon gate stays strict. Theexecutetool description says so.chardomain, with a three-part spec: (a) string fold == char class, (b) independently written must-reject list (incl. U+2065), (c) must-accept TAB and printable ASCII. Exact membership is discharged by the exhaustive oracle test.[discharged]), threat model (control row + 3.4 residual),docs/security.md,REVIEWING.mdC6,docs/usage.mdaudit escapes, README note on MCPdescription,docs/security-audit.mdF1 line, changelog entry, and the has_dangerous_chars misses DEL/C1, soft hyphen, U+061C, U+2028/2029, U+2060-2064 and U+FEFF #86 clause struck from the Phase 0 backlog line. All line-local / append-only.Newly rejected at the daemon (each gets the existing "contains forbidden control/bidi characters" error; the fix is to drop the character): soft hyphen, U+FE0F emoji presentation in
reasonfrom non-MCP clients, Arabic/Syriac text with U+061C, U+0600–0605 or U+070F, a leading BOM, tag characters.Test evidence
cargo test(debug, full suite)cargo test --test pty_ui_goldenwithoutUPDATE_GOLDENcargo clippy --all-targets --all-features -- -D warningscargo clippy --all-targets --no-default-features -- -D warningscargo deny checkcargo kani(cargo-kani 0.67.0, local)has_dangerous_chars_matches_spec_per_char(≈6 s),plan_run_leaf_matches_dangerous_char_spec(≈25 s), plus the two unchangedymd_hms_to_epochharnessescargo fmt --checkmaintoo (the tree is not rustfmt-clean and CI does not run fmt). Per-filerustfmt --checkhunk counts on the touched files are equal or lower than onmain, so this PR adds no new fmt diffsNew tests:
protocol::tests::dangerous_class_matches_unicode_oracle: all 1,114,112chars vsunicode-general-category(=1.1.0, Unicode 16.0.0, asserted viaUNICODE_VERSION) plusDICP_16_0, copied verbatim (unmerged, incl. Cn U+2065, U+FFF0–FFF8, U+E0000, U+E0002–E001F, U+E0080–E00FF, U+E01F0–E0FFF) fromDerivedCoreProperties-16.0.0.txt.dangerous_ranges_sorted_and_disjoint,dangerous_char_regression_table,escape_dangerous_escapes_class_keeps_rest.tests/validation.rs:newly_forbidden_chars_rejected(9 chars × argv/reason/session/env value/planExec/planChdir, also asserts the prompter is never called),legitimate_non_ascii_accepted, anddangerous_env_key_rejectedtightened (no raw key in the message).tests/audit.rs:widened_class_is_rejected_and_escaped_in_record(U+2028 and U+00AD are recorded as\u{2028}/\u{ad}).mcp::tests::description_is_sanitised_of_forbidden_chars.tui::tests::resolves_escapes_dangerous_symlink_target(exercises bothresolve_detailandwrite_resolves_line).server.rsproperty test:DANGEROUSextended, env keys from a valid-by-construction alphabet, benign alphabet addsé 漢 →, and a newaccepted >= 2000of 5000 floor (observed: 2575 accepted / 2425 rejected).Deviations from plan
"evil\x1b[2J\nExecute? [y|N]"instead of"…[y/N]". A file name cannot contain/. Nothing else changes.is_dangerous_charvisibility. It ispub(crate), notpub.src/mcp.rsis a module of the library crate, sopub(crate)is enough, which is what the plan's "the visibility the crate layout needs" asks for.DANGEROUS_RANGESkeeps TAB. The table holds U+0000–001F as one Cc range, andis_dangerous_charexempts TAB, matching the rulec ≠ TAB ∧ …. The plan text allowed either form.src/mcp.rs:73/:88only pass the already-builtreasonon, so the filter is applied once, wheredescriptionbecomesreason.executetool is documented inREADME.md("Run commands"), not indocs/usage.md, so the one-line note went there.Nits
Plan review:
resolve_detail/write_resolves_linedoc comments and the gui comment say that only the canonical path is caller-influenced and that wrapping the others is defence in depth.partition_pointbinary search, and the choice and the resultingunwind(8)are explained in theis_dangerous_charand harness comments.unicode-general-category = "=1.1.0"(Apache-2.0) is a dev-dependency, Unicode 16.0.0 is cited, and the test assertsUNICODE_VERSION == (16, 0, 0).cargo deny checkpasses.style_for(true)and an absolute symlink target, and asserts that the->arm is taken.docs/threat-model.md, so it stays one bullet.Code review:
changelog.mdrule written with≠ ∧ ∈ ∪, as in theDANGEROUS_RANGESdoc comment).safe()and--log-jsonescapers; no security effect (a dangerous character is always escaped, so a name can only look scarier, never tamer), and the reviewer expected a drop.Follow-ups
--text, which zenity parses as Pango markup).Review
cargo clippy --all-targets -- -D warningsclean,cargo test(debug, full suite) all pass.cargo fmt --checkstill fails as onmain(see Test evidence).cargo kaninot re-run: the nit commit only toucheschangelog.md.Manual check before merging
Run the branch daemon in a terminal and send, with
sudo-request --planor a direct socket request:reasoncontaining U+00AD or U+2028, which must be rejected with the validation error;echo 'café 漢字 — →', which must prompt normally;argv[0], which must show the target on theResolves:line with\u{1b}/\u{a}escapes and no redraw.From the MCP server,
executewith description"Restart nginx ⚠️"must prompt withReason: Restart nginx ⚠.🤖 Generated with Claude Code