Skip to content

Read the plugin protocol's stanzas with the header's parser - #148

Merged
pscheid92 merged 4 commits into
mainfrom
refactor/review-s6-one-stanza-parser
Dec 3, 2026
Merged

pscheid92 merged 4 commits into
mainfrom
refactor/review-s6-one-stanza-parser

Conversation

@pscheid92

Copy link
Copy Markdown
Owner

Finding S6 of the 2026-11-30 review, in two commits so that the header side can be judged on its own.

The problem

The plugin channel had a stanza parser of its own, laxer than the header's. go-age reads files and plugins with one parser.

  • A CR ended a line, so CRLF and lone-CR output was accepted.
  • On the plugin's side a byte outside ASCII was decoded to ? before any rule saw it, and passed.
  • A stanza could have any number of arguments.
  • A last line cut off by the end of the output counted as whole.
  • PluginRecipient.Parse accepted an uppercase recipient and PluginIdentity.Parse a lowercase identity, and AgePlugin accepted both.

Commit 1: the header's parser can read from any source of lines

No change in behaviour. Stanza.Read takes the opening line and a way to get the next one; Header.Parse hands it the line it has already read, so HeaderReader's push-back is gone. Decoded body lines are cleared once joined.

Checked on its own: 1,176 vectors and all unit tests pass. The fuzzer's header target names 32 outcomes where it named 34 to 36 before; I listed every outcome of both and the difference is two armor outcomes that occurred once each, and the same errors attributed to different methods after the code moved.

Commit 2: the plugin channel reads through it

  • StanzaChannel.Read calls Stanza.Read and the header's line rules (HeaderLineFramer.ForStanzasAlone: the rules only, nothing recorded, no total). It reads a character at a time, since ReadLine takes a CR for a line ending and hides it, and from Latin-1 readers, so each byte arrives as itself.
  • A stanza may have 130 arguments: the header's 128 and the two a forwarded one gains (the file index and its type). A test sends a 128-argument header stanza the whole way to a plugin's identity.
  • A malformed stanza is plugin sent a malformed stanza: … or client sent a malformed stanza: …, in the parser's words.
  • Output that ends partway through a stanza or a line is reported as that. In the client it goes through Failure, so the plugin's stderr is attached, as when a plugin dies between stanzas.
  • PluginKeys replaces the three places that parsed a plugin's key strings and checks their case: a recipient is lowercase, an identity uppercase.

Tests

  • New PluginFramingTests (28 cases), all red before commit 2. The server-side ones feed raw bytes through Run(args, Stream, Stream, TextWriter).
  • Eight existing tests asserted the old wording and now assert the new one exactly; one test reader overrode ReadLine and now overrides Read.
  • One-parser proof, in a scratch copy: removing a check from Stanza.Read or the framer now fails more tests than before this PR (over-long body line 3 → 5, empty argument 4 → 10, CR allowed 2 → 6).

Fuzzer

All malformed stanzas now throw from one place, which would have hidden them from each other. Outcomes.Shape follows the cause of an AgePluginException, and the server target reads the second half of a malformed-stanza report. The client target decodes its input as Latin-1, as production does. Outcomes: plugin 54 (43 before), plugin-client 30 (26 before); no findings in 30 s.

Behaviour changes

Noted in TODO.md for the next release notes. The one a plugin author may feel: a plugin that writes CRLF line endings is now refused, as go-age refuses it.

Checked

  • dotnet test and dotnet test -c Release -p:ForcePortableAead=true -p:TreatWarningsAsErrors=true: 1,176 vectors and 1,714 unit tests pass, 3 skipped as before, so the go-age and rage plugin interop tests ran.

No change in behaviour: the first step towards reading the plugin
protocol's stanzas with the same parser, as go-age does (finding S6 of the
2026-11-30 review).

Stanza.Read takes the opening line and a way to get the next one, and
Header.Parse hands it the line it has already read, so HeaderReader's
push-back is gone. The decoded body lines are now cleared once joined,
which the plugin side needs and the header side does not mind.
Finding S6 of the 2026-11-30 review. The plugin channel had a stanza
parser of its own, laxer than the header's: a CR ended a line, a byte
outside ASCII became a question mark on the plugin's side, a stanza could
have any number of arguments, and a last line cut off by the end of the
output counted as whole. go-age reads files and plugins with one parser.

StanzaChannel now reads through Stanza.Read and the header's line rules,
a character at a time so that a CR is seen rather than taken for a line
ending, and from Latin-1 readers so that each byte arrives as itself. Of
the header's framer it uses the rules only: nothing is recorded and no
total applies. A stanza may have the header's 128 arguments and the two a
forwarded one gains. A malformed stanza is reported in the parser's
words, with who sent it in front; output that ends partway through a
stanza is reported as that, with the plugin's stderr.

The three places that parsed a plugin's key strings are one, PluginKeys,
which also checks their case as go-age does: a recipient is lowercase, an
identity uppercase.

The fuzzer follows the cause of a plugin exception, and of a malformed
stanza the plugin reports, so that it still tells them apart.
The process tests' plugins on Windows are batch scripts, and cmd's echo
ends a line with CRLF. The protocol's lines end with LF alone, and a CR is
now refused, as go-age refuses it, so six of them failed there. Each
script now keeps its answer in a file and writes it out with `type`.
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.70%. Comparing base (043091f) to head (4a95bbb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #148      +/-   ##
==========================================
+ Coverage   97.51%   97.70%   +0.19%     
==========================================
  Files          76       77       +1     
  Lines        5074     5064      -10     
  Branches      699      692       -7     
==========================================
  Hits         4948     4948              
+ Misses         77       70       -7     
+ Partials       49       46       -3     
Flag Coverage Δ
macos-latest 97.66% <100.00%> (+0.15%) ⬆️
ubuntu-latest 97.61% <100.00%> (+0.09%) ⬆️
windows-latest 97.55% <100.00%> (?)

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.

The plugin channel relies on both: a line there may hold a file key, and
a session has no fixed length. Nothing held the framer to it.
@pscheid92
pscheid92 merged commit 1248ab9 into main Dec 3, 2026
6 checks passed
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