Skip to content

JSON and SARIF output print bidi, C1 and DEL characters from server text raw #149

Backlog

Description

@ammartahamohamedy

What happens

--json, the raw-JSON commands and SARIF output write untrusted server text (PR titles, author names, finding text, environment names) with bidi controls (U+202E…), C1 controls (U+0080–U+009F, including the 8-bit CSI U+009B) and DEL left raw. They reach the terminal unchanged. A reversed title reads as something else, and terminals that honour 8-bit C1 take U+009B as the start of an escape sequence. Anyone who can open a PR on a connected repository sets its title.

serde_json escapes only U+0000–U+001F, " and \, and every JSON print site writes its output as is. The text renderer already replaces these characters (text::terminal_safe, bidi since #65), and export filters them on a terminal. The JSON paths were left out.

Offline, with a stand-in server:

export PROOFLINE_TOKEN=dummy PROOFLINE_ORGANIZATION_ID=0190f3a0-0000-7000-8000-000000000001
python3 - <<'PY' &
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
title = "Fix typo " + chr(0x202E) + "exe.tset" + chr(0x202C) + " " + chr(0x9B) + "31mRED" + chr(0x9B) + "0m DEL" + chr(0x7F)
body = json.dumps({"items": [{"pull_request_title": title}], "next_cursor": None}).encode()
class H(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200); self.send_header("Content-Type", "application/json"); self.end_headers(); self.wfile.write(body)
    def log_message(self, *args): pass
HTTPServer(("127.0.0.1", 8765), H).serve_forever()
PY
sleep 1
proofline --base-url http://127.0.0.1:8765 reviews | python3 -c 'import sys; print([f"U+{ord(c):04X}" for c in sys.stdin.read() if 0x7F <= ord(c) <= 0x9F or 0x202A <= ord(c) <= 0x202E])'
kill %1
['U+202E', 'U+202C', 'U+009B', 'U+009B', 'U+007F']

Printed straight to a terminal, the title reads "Fix typo test.exe".

Expected

JSON output never carries a character the text renderer keeps from the terminal, and it still parses to the server's values.

Proposal

After serializing, write each character terminal_safe replaces (other than JSON whitespace: space, tab, newline, carriage return) as a JSON \u escape. Outside strings a serialized document holds only ASCII, so these characters are always inside strings, where the escape decodes to the same character. The output stays valid and lossless, so it can apply whether or not stdout is a terminal. One helper covers every print site and the ci review --sarif file. The MCP bridge (frames for an agent, not a terminal) stays as it is.

Seen on main (22c86ca), on Linux and on Windows.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions