Repository navigation
Fix writers that emit untrusted bytes unquoted - #863
Open
danieleggert wants to merge 8 commits into
Open
danieleggert wants to merge 8 commits into
danieleggert wants to merge 8 commits into
Conversation
This was referenced Oct 12, 2026
danieleggert
force-pushed
the
harden-1-encoder-fixes
branch
from
October 24, 2026 09:37
4a72df2 to
5a28d8b
Compare
danieleggert
marked this pull request as ready for review
October 24, 2026 09:39
mdiep
approved these changes
Oct 26, 2026
danieleggert
force-pushed
the
harden-1-encoder-fixes
branch
from
October 28, 2026 13:30
5a28d8b to
4cfef4e
Compare
`parseListMailbox` was only tested against DEL. Cover wildcards, resp-specials, the quoted-string branch, and an empty input.
`GmailLabel("\\x)\r\nA2 DELETE INBOX\r\nA3 NOOP (")` was written raw
because it starts with `\`, injecting a command into STORE X-GM-LABELS.
Reachable from server data via `init(mailboxName:)`.
Write bare only for `"\" atom`; otherwise `writeIMAPString`. Also fixes
round-trip of astring labels such as `"\\Foo bar"`.
`.urlFetch([ByteBuffer(string: "x\r\nA2 DELETE INBOX")])` was written verbatim, injecting a command. RFC 4467: `url-full = astring`. Write bare if `1*ASTRING-CHAR` (keeps long URLAUTH URLs out of literals), else `writeIMAPString` (`%`, `*`).
`Encoding("x\" 0 0) UID 9 (")` was spliced into `"…"` unescaped, so a
MIME `Content-Transfer-Encoding` header spoofs FETCH items. The parser
accepts any `string` (incl. literals with CRLF), so proxies re-emitted it.
`body-fld-enc = (DQUOTE ("7BIT"/…) DQUOTE) / string`. Use
`writeIMAPString`; standard values are unchanged on the wire.
`Media.Subtype("x\"\r\n* 1 EXPUNGE")` was spliced into `"…"` unescaped;
a MIME `Content-Type` header could inject an untagged response.
`media-basic = ((DQUOTE (…) DQUOTE) / string) SP media-subtype`,
`media-subtype = string`. Use `writeIMAPString` (still uppercased).
`SearchCorrelator(tag: "a\") * BYE")` was spliced into `"…"` unescaped, so ESEARCH / UIDBATCHES responses could carry injected data. RFC 4466: `tag-string = string`. Use `writeIMAPString`, and parse a `string` rather than `"` tag `"` so every tag round-trips.
The quoted-special cases were swapped: `\` encoded as `"\"` (unterminated), `"` as `"\\"` (a backslash). `pathSeparator: "\n"` was written as a raw LF inside `"…"`, and NUL silently became NIL. `(DQUOTE QUOTED-CHAR DQUOTE / nil)`, `QUOTED-CHAR = <TEXT-CHAR except quoted-specials> / "\" quoted-specials`. Swap the cases; parse the escaped forms; `MailboxPath.init` throws for CR, LF, CRLF, NUL.
The parser base64-decodes `mechanism-base64`, but the encoder wrote the decoded bytes raw: parse `INTERNAL=YQ==` → "a" → `INTERNAL=a`. A proxy re-encoding `[URLMECH INTERNAL X=<base64 of CRLF…>]` emitted raw CRLF. RFC 4467: `mechanism-base64 = mechanism ["=" base64]`. Encode on write; fix the fixtures that locked in the mismatch.
danieleggert
force-pushed
the
harden-1-encoder-fixes
branch
from
October 30, 2026 14:42
4cfef4e to
8e6f565
Compare
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.
[1/6] One of the design goals of this library is that the API types can only represent valid state. But that doesn’t hold true today. These 6 stacked PRs are smaller steps towards that goal. #863 #864 #865 #866 #867 #868
Motivation:
These writers emitted values raw or quoted without escaping:
.urlFetch([ByteBuffer(string: "x\r\nA2 DELETE INBOX")])injects a command. A proxy re-encoding a hostileBODYSTRUCTUREor[URLMECH]does too.Modifications:
No API change. Values go through
writeIMAPString; URLFETCH URLs stay bare when they're1*ASTRING-CHAR, to avoid a literal per URLAUTH URL.MailboxPathseparator escapes were swapped.MechanismBase64is base64-encoded on write; fixtures locked in the mismatch.Result:
Each writer round-trips every value its type accepts.