Skip to content

Quote the text an error repeats from a file, a key or a plugin - #146

Merged
pscheid92 merged 1 commit into
mainfrom
fix/review-s4-untrusted-text
Dec 2, 2026
Merged

pscheid92 merged 1 commit into
mainfrom
fix/review-s4-untrusted-text

Conversation

@pscheid92

Copy link
Copy Markdown
Owner

Finding S4 of the 2026-11-30 review. 15 of the 22 new tests failed before the change.

The problem

Error messages repeated untrusted text exactly as it came: a header line, an armor line, an SSH key type, BouncyCastle's account of a key file, a plugin's malformed line, its error message and its stderr. A caller that printed ex.Message to a terminal printed the sender's escape sequences, and a megabyte-long line made a megabyte-long message.

The change

UntrustedText (new, internal) writes out what cannot be seen and cuts what is long, as go-age does the first with %q.

  • A value is set in quotes: unexpected line in header: "\x1b[2J\x1b]0;owned\x07 hello".
  • A plugin's or BouncyCastle's own sentence is escaped without quotes.
  • Control characters, direction overrides, zero-width characters, line separators, lone surrogates and private-use characters are written out; letters of any script are kept, since a plugin's error may be in any language.
  • Text is cut at 120 characters (a plugin's error message at 500, BouncyCastle's at 200), and a cut value says how long it was.

Used for: the header's version line, an unexpected line, the MAC line, a stanza's opening line, the armor's begin line, a scrypt work factor, the SSH key type on a recipient line, BouncyCastle's message about a key, and in the plugin client a line that is no stanza, a file index, a confirm label, the plugin's error message and each line of its stderr.

Behaviour beyond the quoting

  • A byte in an armor body that is not base64 is named by its value (0xE9), as the header names one; it was '?'. One existing test asserted the old text and is changed.
  • NoIdentityMatchException.Message shows at most eight stanza types of 32 characters each. StanzaTypes holds them whole.
  • Not changed: the inner exception of an SSH key error is still BouncyCastle's own, with its message as it wrote it. The fuzzer tells outcomes apart by it.
  • Not changed: text a plugin asks to have displayed reaches IPluginCallbacks as sent, as in go-age's client. The interface's documentation now says so, and that a host should replace control characters before writing it to a terminal, as go-age's terminal UI does.

Noted in TODO.md for the next release notes.

Checked

  • dotnet test and dotnet test -c Release -p:ForcePortableAead=true -p:TreatWarningsAsErrors=true: 1,176 vectors and 1,658 unit tests pass.
  • Age.Fuzz, all ten targets for 30 s: no findings.

From the 2026-11-30 review (S4). Error messages repeated a header line, an
armor line, an SSH key type, BouncyCastle's account of a key file, a
plugin's malformed line, its error message and its stderr exactly as they
came. A caller that printed the message to a terminal printed the sender's
escape sequences, and a megabyte-long line made a megabyte-long message.

UntrustedText writes out what cannot be seen (control characters,
direction overrides, zero-width characters) and cuts what is long, as
go-age's %q does the first. A value is set in quotes; a plugin's or
BouncyCastle's own sentence is escaped without them. Letters of any
script are kept, since a plugin's error may be in any language.

A byte in an armor body that is not base64 is now named by its value, as
the header names one. NoIdentityMatchException's message shows at most
eight stanza types of 32 characters; StanzaTypes holds them whole.

Text a plugin asks to have displayed still reaches IPluginCallbacks as
sent, as in go-age's client; the interface now says so, and what a host
should do before writing it to a terminal.
@pscheid92
pscheid92 merged commit c1b7810 into main Dec 2, 2026
4 checks passed
@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.77419% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.54%. Comparing base (fffb287) to head (04ae72f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
Age/Exceptions.cs 66.66% 0 Missing and 1 partial ⚠️
Age/Recipients/PluginIdentity.cs 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #146   +/-   ##
=======================================
  Coverage   97.54%   97.54%           
=======================================
  Files          75       76    +1     
  Lines        5001     5044   +43     
  Branches      688      695    +7     
=======================================
+ Hits         4878     4920   +42     
  Misses         76       76           
- Partials       47       48    +1     
Flag Coverage Δ
macos-latest 97.50% <96.77%> (+<0.01%) ⬆️
ubuntu-latest 97.50% <96.77%> (+<0.01%) ⬆️
windows-latest 97.44% <96.77%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant