Skip to content

gl: sanitize every node- or third-party-supplied string before it reaches the terminal #605

Open

Description

@beardthelion

gl sanitizes some node-supplied strings before printing them and prints others raw. A raw string can carry ANSI/OSC escapes (spoofed output, hidden lines) or Unicode bidi/format controls such as U+202E (reordered display, Trojan Source). The helper exists and is correct: sanitize_node_msg in crates/gl/src/http.rs drops C0/C1 controls and bidi/format characters and caps length. The gap is coverage, and four open issues each track one slice of it.

This issue is the single checklist. #187, #189, #303 and #393 stay open as the per-slice write-ups until their slice lands.

Who authors the bytes

Source Examples Tracked in
Node error message on write paths bail!("... ({status}): {msg}") in mirror.rs, profile.rs and the other write commands #187
Node-advertised fields gl status version and PR/issue titles, bounty title, agent model and capabilities #189
Third-party content (another user, not the operator) gl issue show title and body, issue and PR comments, PR review bodies, gl pr diff, profile fields #303
Operator-supplied input echoed back gl doctor prints the --node / GITLAWB_NODE URL in three rows #393
Service-supplied prompt interactive_prompt in crates/icaptcha-client/src/lib.rs writes the challenge kind and prompt to stderr raw, although the crate's own error path sanitizes comment on #189

Third-party content is the most reachable of these: on any public node an issue body or comment is written by someone who is not the node operator, so no hostile or intercepted node is needed.

Current state on main (7005073)

Files under crates/gl/src with zero calls to a sanitizer: bounty.rs, doctor.rs, issue.rs, mirror.rs, pr.rs, profile.rs, status.rs, plus changelog.rs, protect.rs, visibility.rs, webhook.rs, name.rs, node.rs and node_stake.rs (not yet audited for node-supplied output). Raw print sites confirmed by reading the source:

  • issue.rs: title (lines 224, 261, 284), body (290), comment bodies (377)
  • pr.rs: title (271, 318, 347), body (352), review and comment bodies (393, 430, 580)
  • status.rs: PR and issue titles (96, 125), node version (67)
  • bounty.rs: title (227, 279)
  • mirror.rs:121 and profile.rs:321, 443: raw {msg} in bail!
  • icaptcha-client interactive_prompt: raw kind and prompt

Already covered: http.rs read_json, whoami, peer, ipfs_cmd, repo, task, sync, clone, star, register, quickstart, ucan_cmd (which has a local shown helper).

Proposed approach

  1. Print through one helper. Promote sanitize_node_msg (or the shown wrapper in ucan_cmd.rs) to crate::text so a display site is a one-word change and the rule is "wire strings go through text::shown".
  2. Multi-line third-party text (issue and PR bodies, diffs) needs a variant that keeps \n and \t and drops everything else. Do not reuse the single-line message helper, which would flatten bodies.
  3. Add a completeness test in the style of the status-before-parse gate from fix(gl): status-check the client read/write surfaces so a node denial surfaces as an error, not a fake result (#123) #186. It should scan println!, eprintln!, bail! and writeln! in crates/gl/src and fail on an interpolated value that came from a JSON field or response body without passing through the helper. This is a direction, not a settled design: a textual scrape will have false positives for values the caller itself produced, so it needs an explicit allowlist with a reason per entry. Prove it load-bearing by reverting one fix and confirming it fails.
  4. Land in slices that match the issues, third-party content first.

Acceptance

  • Each site above prints through the helper, with a test that feeds ESC (U+001B) and U+202E through a mock node and asserts neither reaches the output.
  • The completeness test exists and fails when a site is reverted.
  • The icaptcha prompt strips the same characters as its error path.

Out of scope

Output the operator typed themselves in the same command (for example bounty create --title, echoed back). That is the caller's own input, not wire data.

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

    crate:glgl — the contributor CLIkind:securityVulnerability fix or hardeningsev:mediumDegraded but workaround exists

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions