Repository navigation
Escape bidi, C1 and DEL characters in JSON and SARIF output - #150
Open
ammartahamohamedy wants to merge 2 commits into
Open
ammartahamohamedy wants to merge 2 commits into
ammartahamohamedy wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #149
Problem
serde_jsonescapes only U+0000–U+001F, so JSON and SARIF output wrote untrusted server text (PR titles, author names, finding text, environment names) with bidi controls, C1 controls and DEL raw to the terminal. The text renderer andexportalready keep them out.Fix
text::json_safewrites each characterterminal_safereplaces, other than JSON whitespace (space, tab, newline, carriage return), as a JSON\uescape. Outside its strings a serialized document holds only ASCII, so these characters are always inside a string, where the escape decodes to the same character. The output stays valid JSON with the same values.tools::prettyandtools::compactwrapserde_jsonwith it, and every JSON print site uses them:tools::json(reviews,history,run,routing,guidance,fix-prompt,config,plan,scan --json),review/findings/ci review --json,--sarifon stdout and theci review --sariffile,review --no-wait --json,review --schema,stop --json,ci deploy --jsonandcoverage upload --json.agent install's config files, the credential store and the update cache.Tests (written first; the new tests failed before the change)
raw_json_commands_escape_terminal_controls_and_keep_the_values(new,tests/http.rs)reviews,routingandfix-promptprint no raw bidi, C1 or DEL, and their stdout parses to the served documentci_review_sarif_file_escapes_terminal_controls_and_keeps_the_values(new,tests/http.rs)ci review --sarifwrites holds none raw and keeps the environment name.identity_consolenow delegates tonamed_identity_console, which takes the environment namejson_and_sarif_output_escape_terminal_controls_and_keep_the_values(new,tests/sarif.rs)findings --jsonand--sarifescape every kind (U+202E, U+2066, U+2069, U+061C, U+200F, U+009B, U+007F), the JSON parses to the server's review, and the SARIF still validates against the schema with the same environment namejson_strings_escape_every_terminal_control_and_keep_their_value,json_without_terminal_controls_is_unchanged,json_whitespace_between_tokens_stays_raw(new,src/text.rsunit)Mutation checks: writing the SARIF file with
serde_jsonagain fails only theci review --sariftest; dropping the bidi check fromjson_safefails the three integration tests and the round-trip unit test; escaping tabs and carriage returns again fails the whitespace unit test.End to end, offline, with the built binary: the issue's repro lists
U+202E U+202C U+009B U+009B U+007Fonmainand none with this change.Checks
cargo fmt --check: ✅cargo clippy --locked -- -D warnings: clean on the lib, the bins and every integration test.--all-targetsstops at the 2 errorsmainalready has on Windows (src/agent/tests.rs).cargo test --locked: the new tests pass. Otherwise, the same 12 Windows failures as onmain(tests/mcp.rs×7,agent_install×2,update,local_patch,hooks), none in a file this change touches.cargo deny check: no dependency changes.checkandwindowsgreen on ammar-taha-dev/proofline-cli#5 (commitfa2af96).Proofline review log
Fork review PR: ammar-taha-dev/proofline-cli#5. Rounds capped at 2.
json_saferewrites carriage returns and tabs as\uescapes even when they are legal whitespace between JSON tokens. Recommended: turn CR into spaces, keep tabsserde_jsonoutput, which never holds a raw tab or CR. Butjson_safetakes any&str, so it should leave JSON whitespace alonejson_safeonly escapes, so it shouldn't reformat. Valid JSON can hold a raw tab or CR only between tokens, so leaving them is lossless, while turning CR into a space would change the caller's bytes for nothing. The doc comment is shorter and says soThe prompts below are the ones that drove this implementation; the investigation, reproduction and fix scope were done before them and aren't included.