mailer: refuse RFC 2231 parameters up front; the family's P3s (ruled)
Ruled by Paul, 2026-11-14 (the header-block family's second round,
option 1), recorded in the plan with the other two rulings of the day:
- Any header parameter whose name holds "*" (RFC 2231 extended or
continued) is a 400. The RFC 2231 decoder is gone from encoded.go, so
there is none left to get wrong. Only a parameter position (after a
";") is matched: "Subject: a*=b" is admitted. Six spellings are
refusal cases, and the full send path answers 400 for one.
- The P3s: a utf-8 word must be valid UTF-8 (so a U+2028 split across
two adjacent words is refused); the charset allowlist is exact names;
the check runs again on the value with fold whitespace removed; and
text with "=?" and "?=" that is not shaped like a word ("is a=?b then
c?=d", a List-Unsubscribe URL holding x=?1&y=2?=3) is admitted.
- The binary ceiling's reason line notes Paul's confirmation of 65 MB.
Census: the internal/mailer envelope is re-proposed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+145
−153
.amadan/ci.d/20-cross@5+2 −1docs/superpowers/plans/2026-11-13-platform-mail-submission.md+15 −0internal/mailer/encoded.go+69 −120internal/mailer/hygiene.go+14 −9internal/mailer/hygiene_test.go+37 −21internal/mailer/send_test.go+7 −1internal/provision/testdata/plan14-root-reads-platform-mail-submission.tsv+1 −1
diff --git a/.amadan/ci.d/20-cross@5 b/.amadan/ci.d/20-cross@5| index 2b244d66d..062dd8c72 100755 |
| --- a/.amadan/ci.d/20-cross@5 |
| +++ b/.amadan/ci.d/20-cross@5 |
| @@ -83,7 +83,8 @@ GOOS="$GOOS" GOARCH="$GOARCH" CGO_ENABLED=0 go build ./... |
| # mailer adds about 520 KB (sesv2's SendEmail path, internal/mailer, |
| # mailsubmit, mailwire, net/mail). Its SES client is stored as a method |
| # value (mailer.sesSendFunc); stored in the interface it had added 3.1 MB, |
| -# which this tripwire caught. 65 MB still fails a repeat of #275. It is a |
| +# which this tripwire caught. Confirmed by Paul, 2026-11-14. 65 MB still |
| +# fails a repeat of #275. It is a |
| # ceiling and not an equality on purpose. If you are here because it fired, look for an SDK client stored in |
| # an interface, which html/template's method retention then drags in whole: |
| # |
diff --git a/docs/superpowers/plans/2026-11-13-platform-mail-submission.md b/docs/superpowers/plans/2026-11-13-platform-mail-submission.md| index 6f4d1abf9..04c2137ac 100644 |
| --- a/docs/superpowers/plans/2026-11-13-platform-mail-submission.md |
| +++ b/docs/superpowers/plans/2026-11-13-platform-mail-submission.md |
| @@ -50,6 +50,21 @@ Plan choices that are not gaps, for the plan reviewer (each resolves an item on |
| - **The mailer's box facts** (region, pools, fleet label, bucket, S3 endpoint) come from `/etc/carlos/host.env` through systemd's `EnvironmentFile=`. PID 1 reads it as root, so the mailer user needs no read access. The unit sets `UnsetEnvironment=CARLOS_SECRETS_KEY`. The AWS regions come from two new optional host.env keys (round 1 P2-3): `CARLOS_MAIL_REGION` (SES; the same name and meaning as the console's) and `CARLOS_DEPLOYMENT_REGION` (the deployment bucket). `CARLOS_REGION` is a placement label and is used only for "on this box". |
| - **The mailer is a verb of the one `carlos` binary** (`carlos mailer serve`), as `carlos relay serve` is. Its code imports a new small wire package, `internal/mailwire`, and never `internal/mail`. That keeps `internal/mail` (and its IAM and SES walks) out of the root binary and out of census scope (`go list -deps .` today has no `internal/mail`). |
| +### Rulings of 2026-11-14 (the second-round families and the binary ceiling) |
| + |
| +**Ruled by Paul, 2026-11-14 ("All fine").** Three choices, built on the branch: |
| + |
| +1. **The mailer header-block family (round 2 P1, RFC 2231 parameters still decode to CR LF): option 1, refuse it up front.** Any top-level header parameter whose name contains `*` (an RFC 2231 extended or continued parameter) is a `400`. The RFC 2231 decoder is removed from `internal/mailer/encoded.go`, so there is no decoder left to get wrong. Rastrillo and the Oficina apps never emit such a parameter at top level (checked). The `*` check is scoped to parameter positions (after a `;`), so `Subject: a*=b` is admitted. With that ruled, the family's P3s are applied too: every `utf-8` word must be valid UTF-8, and adjacent words are checked again joined (a U+2028 split across two words is refused); the charset allowlist is exact names, not prefixes; the check runs a second time on the value with fold whitespace removed; and the leftover rule is narrowed to text shaped like `=?x?x?…?=`, so `Subject: is a=?b then c?=d` and a `List-Unsubscribe` URL holding `x=?1&y=2?=3` are admitted. **Ruled by Paul, 2026-11-14.** |
| +2. **The Task 6 "one working channel" family (P2-1 to P2-4): option 1, one invariant enforced in one place.** The invariant: *every instance of a switched app has a working mail channel at every moment*: its build declares `--mail submit` and its bundle holds `<stem>_MAIL_FROM`, or, once the switch is off, its bundle holds the five `<P>_SMTP_*`. Under it: |
| + - **P2-1:** the switch door takes `beginCopiesMutation` (the app lock, which every serve door holds) before `submissionPreconditions` and holds it through `SwitchOn` or `SwitchOff`. The lock order is the account, then the app. |
| + - **P2-2:** the precondition loop also judges what each record's pin would serve, by the pin half of `submissionRecordRefusal`'s rule: a record pinned to a build that does not declare `--mail submit` refuses the switch. |
| + - **P2-3:** switch-off delivers SMTP to every bundle first (the Enable and EnableEnvironment walks' "deliver although switched" path), writes `On:false` last, and only then takes `<stem>_MAIL_FROM` out. A failure part-way leaves the app on submission, still working, and a re-run finishes. Switch-on is ordered the same way: the From goes into every bundle first, `On:true` next, and the five come out last. **The per-instance restart gap, stated:** an instance keeps the channel it was started with until it restarts. After `On:false`, an instance started with `CARLOS_MAIL=submit` is refused by the mailer (`403 SUBMISSION_OFF`) until its restart, which the door requests at once. After `On:true`, an instance started with an owned environment's SMTP key loses that key when the environment's user is reaped, until its restart; an instance on the app-level key keeps it for the overlap week. |
| + - **P2-4:** for a switched app, a `DeliverMailFromIn` failure is returned to the door that created or adopted the environment, which answers it (no more log-and-swallow in `teamcreds.go`). The environment was written by then, so an instance create or rebind into an owned environment whose bundle lacks the From is refused too, with the remedy (switch on again, which delivers it). |
| + - A randomised simulation test (`TestSubmissionChannelSimulation`) drives interleavings of switch on and off, promote, rollback, pin and channel moves, instance and environment creation, box arm and disarm, and injected AWS and store failures at each write, and asserts the invariant after every step. Mutation-checked: it catches each of P2-1 to P2-4 when its fix is removed. **Ruled by Paul, 2026-11-14.** |
| +3. **The platform binary's size ceiling: 65 MB, confirmed.** **Ruled by Paul, 2026-11-14.** |
| + |
| +The copy review (Task 6 P2-6) is still Paul's; the copy record stays a draft. |
| + |
| --- |
| ## Global Constraints |
diff --git a/internal/mailer/encoded.go b/internal/mailer/encoded.go| index 7ac2c962e..8de87241d 100644 |
| --- a/internal/mailer/encoded.go |
| +++ b/internal/mailer/encoded.go |
| @@ -8,19 +8,20 @@ import ( |
| ) |
| // The encoded text a header field may carry, checked the same way in every |
| -// field (Task 6 review, round 1 P1 and P2): RFC 2047 encoded words, which a |
| -// reader decodes for display names, subjects and more, and RFC 2231 |
| -// extended parameters (name*=utf-8''...), which a MIME reader decodes for |
| -// file names. The mailer does not decode a message for SES; it refuses one |
| -// a reader could decode into a line break, so no reader that decodes and |
| -// writes the header out again can be handed a new field. |
| +// field (Task 6 review, rounds 1 and 2; ruled by Paul, 2026-11-14): RFC 2047 |
| +// encoded words, which a reader decodes for display names, subjects and |
| +// more, are decoded here strictly and refused if they could decode into a |
| +// line break; RFC 2231 parameters (name*=utf-8''..., name*0*=...), which a |
| +// MIME reader decodes for file names, are refused outright. The mailer |
| +// does not decode a message for SES; it refuses one a reader could decode |
| +// into a new field. |
| // |
| -// The check is byte-wise, after the transfer encoding (B, Q or %XX) only, |
| -// so it needs no charset tables. That is sound only for a charset in which |
| -// a C0 byte always means a C0 character, which is why the charsets are an |
| -// allowlist (encodedCharset): UTF-7 (+AA0-) and EBCDIC (LF is 0x25) write |
| -// a line break with no CR or LF byte, and are refused with every other |
| -// charset not listed. |
| +// The check on an encoded word is byte-wise, after the transfer encoding |
| +// (B or Q) only, so it needs no charset tables. That is sound only for a |
| +// charset in which a C0 byte always means a C0 character, which is why the |
| +// charsets are an exact allowlist (encodedCharset): UTF-7 (+AA0-) and |
| +// EBCDIC (LF is 0x25) write a line break with no CR or LF byte, and are |
| +// refused with every other charset not listed. |
| // encodedWordShape is anything shaped like an encoded word: "=?", a |
| // charset, "?", an encoding, "?", text, "?=". Whitespace is allowed |
| @@ -29,78 +30,78 @@ import ( |
| // decoding failing here. |
| var encodedWordShape = regexp.MustCompile(`=\?[^?]*\?[^?]*\?.*?\?=`) |
| +// rfc2231Param is a header parameter whose name holds "*": after a ";", |
| +// a name (any run of characters but "=" and ";", so "name *" counts too) |
| +// holding a "*", then "=". Only a parameter position is matched, so |
| +// "Subject: a*=b" is not one. |
| +var rfc2231Param = regexp.MustCompile(`;[^=;]*\*[^=;]*=`) |
| + |
| // cleanFieldValue reports whether an unfolded header field value carries |
| -// only clean encoded text: every encoded word decodes cleanly |
| -// (cleanEncodedWord), nothing shaped like one is left once they are taken |
| -// out, and every RFC 2231 extended parameter decodes cleanly. A value with |
| -// neither "=?" nor "*=" has none, and is clean. |
| +// only clean encoded text: no RFC 2231 parameter, and everything shaped |
| +// like an encoded word (=?x?x?…?=) decodes cleanly as one |
| +// (decodeEncodedWord, cleanDecoded). Adjacent words, which a reader joins |
| +// (RFC 2047 §6.2), need no joined check: a C0, DEL or ISO-8859 C1 byte is |
| +// seen in its own word, and a UTF-8 character split across two words (a |
| +// U+2028 among them) leaves each word invalid UTF-8, which is refused. |
| +// Text with "=?" and "?=" that is not shaped |
| +// like a word ("is a=?b then c?=d") is not one, and is admitted (ruled |
| +// 2026-11-14): the leftmost-first match leaves nothing word-shaped behind. |
| func cleanFieldValue(v string) bool { |
| - if strings.Contains(v, "=?") { |
| - for _, w := range encodedWordShape.FindAllString(v, -1) { |
| - if !cleanEncodedWord(w) { |
| - return false |
| - } |
| - } |
| - rest := encodedWordShape.ReplaceAllString(v, " ") |
| - if i := strings.Index(rest, "=?"); i >= 0 && strings.Contains(rest[i+2:], "?=") { |
| + if rfc2231Param.MatchString(v) { |
| + return false |
| + } |
| + if !strings.Contains(v, "=?") { |
| + return true |
| + } |
| + for _, w := range encodedWordShape.FindAllString(v, -1) { |
| + cs, raw, ok := decodeEncodedWord(w) |
| + if !ok || !cleanDecoded(raw, cs) { |
| return false |
| } |
| } |
| - if strings.Contains(v, "*=") && !cleanExtendedParams(v) { |
| - return false |
| - } |
| return true |
| } |
| -// cleanEncodedWord reports whether one encoded word ("=?cs?e?text?=") is in |
| -// an allowed charset (an RFC 2231 language suffix, "*en", is dropped), is |
| -// B or Q, decodes strictly, and decodes to clean bytes in that charset. |
| -func cleanEncodedWord(w string) bool { |
| +// decodeEncodedWord decodes one encoded word ("=?cs?e?text?=") strictly: |
| +// its charset, lowercased with any RFC 2231 language suffix ("*en") |
| +// dropped, must be on the allowlist, its encoding B or Q, and its text |
| +// must decode. raw is the decoded bytes, in that charset. |
| +func decodeEncodedWord(w string) (cs string, raw []byte, ok bool) { |
| parts := strings.SplitN(w[2:len(w)-2], "?", 3) |
| if len(parts) != 3 { |
| - return false |
| + return "", nil, false |
| } |
| - cs, _, _ := strings.Cut(strings.ToLower(parts[0]), "*") |
| - if !encodedCharset(cs) { |
| - return false |
| + cs, _, _ = strings.Cut(strings.ToLower(parts[0]), "*") |
| + if !encodedCharset[cs] { |
| + return "", nil, false |
| } |
| - var raw []byte |
| switch parts[1] { |
| case "b", "B": |
| b, err := base64.StdEncoding.DecodeString(parts[2]) |
| if err != nil { |
| - return false |
| + return "", nil, false |
| } |
| - raw = b |
| + return cs, b, true |
| case "q", "Q": |
| b, ok := decodeQ(parts[2]) |
| - if !ok { |
| - return false |
| - } |
| - raw = b |
| - default: |
| - return false |
| + return cs, b, ok |
| } |
| - return cleanDecoded(raw, cs) |
| + return "", nil, false |
| } |
| -// encodedCharset is the allowlist: charsets in which every byte below 0x20 |
| -// is the C0 control of that value and stands for nothing else, so a |
| -// byte-wise check sees every line break. Lowercased. |
| -func encodedCharset(cs string) bool { |
| - switch cs { |
| - case "utf-8", "us-ascii", "iso-2022-jp", "shift_jis", "big5", "gb2312", "gbk": |
| - return true |
| - } |
| - if rest, ok := strings.CutPrefix(cs, "windows-125"); ok { |
| - return len(rest) == 1 && rest[0] >= '0' && rest[0] <= '8' |
| - } |
| - for _, p := range []string{"iso-8859-", "euc-", "koi8-"} { |
| - if rest, ok := strings.CutPrefix(cs, p); ok { |
| - return rest != "" && strings.Trim(rest, "abcdefghijklmnopqrstuvwxyz0123456789") == "" |
| - } |
| - } |
| - return false |
| +// encodedCharset is the allowlist, by exact lowercased name: charsets in |
| +// which every byte below 0x20 is the C0 control of that value and stands |
| +// for nothing else, so a byte-wise check sees every line break. gb18030 is |
| +// left out: it can encode NEL and U+2028 in bytes the check cannot read. |
| +var encodedCharset = map[string]bool{ |
| + "utf-8": true, "us-ascii": true, |
| + "iso-8859-1": true, "iso-8859-2": true, "iso-8859-3": true, "iso-8859-4": true, "iso-8859-5": true, |
| + "iso-8859-6": true, "iso-8859-7": true, "iso-8859-8": true, "iso-8859-9": true, "iso-8859-10": true, |
| + "iso-8859-11": true, "iso-8859-13": true, "iso-8859-14": true, "iso-8859-15": true, "iso-8859-16": true, |
| + "windows-1250": true, "windows-1251": true, "windows-1252": true, "windows-1253": true, "windows-1254": true, |
| + "windows-1255": true, "windows-1256": true, "windows-1257": true, "windows-1258": true, |
| + "iso-2022-jp": true, "shift_jis": true, "euc-jp": true, "euc-kr": true, |
| + "gb2312": true, "gbk": true, "big5": true, "koi8-r": true, "koi8-u": true, |
| } |
| // decodeQ is RFC 2047's Q decoding, strictly: "_" is a space, "=XX" is a |
| @@ -152,9 +153,9 @@ func hexDigit(c byte) (byte, bool) { |
| // cleanDecoded reports whether decoded bytes in charset cs hold no control |
| // character. Every charset: no C0 byte but tab, and no DEL; ESC only in |
| // ISO-2022-JP, whose shifts are written with it. ISO-8859-*: no byte in |
| -// 0x80-0x9f, its C1 controls (NEL is 0x85). UTF-8: no C1 control and no |
| -// line or paragraph separator (U+2028, U+2029). The other charsets on the |
| -// allowlist encode none of those. |
| +// 0x80-0x9f, its C1 controls (NEL is 0x85). UTF-8: valid UTF-8, with no C1 |
| +// control and no line or paragraph separator (U+2028, U+2029). The other |
| +// charsets on the allowlist encode none of those. |
| func cleanDecoded(raw []byte, cs string) bool { |
| for _, b := range raw { |
| switch { |
| @@ -166,65 +167,13 @@ func cleanDecoded(raw []byte, cs string) bool { |
| } |
| } |
| if cs == "utf-8" { |
| - for s := string(raw); s != ""; { |
| - r, n := utf8.DecodeRuneInString(s) |
| - if (r >= 0x80 && r <= 0x9f) || r == 0x2028 || r == 0x2029 { |
| - return false |
| - } |
| - s = s[n:] |
| - } |
| - } |
| - return true |
| -} |
| - |
| -// extendedParam is an RFC 2231 extended parameter: name*= or name*N*=, |
| -// then charset'language'value, the value percent-encoded. A continuation |
| -// (name*1*=) has no charset of its own; it is decoded in the charset of |
| -// the parameter it continues, and in us-ascii when none is seen. |
| -var extendedParam = regexp.MustCompile(`([A-Za-z0-9!#$&+.^_` + "`" + `|~-]+)\*(?:(\d+)\*)?=\s*"?([^;"\s]*)`) |
| - |
| -// cleanExtendedParams reports whether every RFC 2231 extended parameter in |
| -// a field value decodes strictly (each "%" starts two hex digits), in an |
| -// allowed charset, to clean bytes (cleanDecoded). |
| -func cleanExtendedParams(v string) bool { |
| - charsets := map[string]string{} // parameter name -> charset of its first section |
| - for _, m := range extendedParam.FindAllStringSubmatch(v, -1) { |
| - name, section, value := strings.ToLower(m[1]), m[2], m[3] |
| - cs, ok := charsets[name] |
| - if section == "" || section == "0" { |
| - parts := strings.SplitN(value, "'", 3) |
| - if len(parts) != 3 { |
| - return false |
| - } |
| - cs, value = strings.ToLower(parts[0]), parts[2] |
| - if cs == "" { |
| - cs = "us-ascii" |
| - } |
| - charsets[name] = cs |
| - } else if !ok { |
| - cs = "us-ascii" |
| - } |
| - if !encodedCharset(cs) { |
| + if !utf8.Valid(raw) { |
| return false |
| } |
| - raw := make([]byte, 0, len(value)) |
| - for i := 0; i < len(value); i++ { |
| - if value[i] != '%' { |
| - raw = append(raw, value[i]) |
| - continue |
| - } |
| - if i+2 >= len(value) { |
| - return false |
| - } |
| - b, ok := unhex(value[i+1], value[i+2]) |
| - if !ok { |
| + for _, r := range string(raw) { |
| + if (r >= 0x80 && r <= 0x9f) || r == 0x2028 || r == 0x2029 { |
| return false |
| } |
| - raw = append(raw, b) |
| - i += 2 |
| - } |
| - if !cleanDecoded(raw, cs) { |
| - return false |
| } |
| } |
| return true |
diff --git a/internal/mailer/hygiene.go b/internal/mailer/hygiene.go| index d961d92d6..eb50ec2ea 100644 |
| --- a/internal/mailer/hygiene.go |
| +++ b/internal/mailer/hygiene.go |
| @@ -49,21 +49,24 @@ var errHeaderSyntax = errors.New("mailer: malformed header block") |
| // keys as "From ", are refused rather than guessed at; |
| // - a line longer than 998 characters before its line ending (RFC 5322 |
| // §2.1.1), which a relay may fold or cut where it likes (Task 6 review); |
| -// - in any field, an RFC 2047 encoded word, or an RFC 2231 extended |
| -// parameter, that does not decode, is in a charset outside the |
| -// allowlist, or decodes to a control character: CR, LF, NUL and the |
| -// rest (cleanFieldValue, encoded.go). A reader that decodes it and |
| -// writes it out again would otherwise write the decoded line break as |
| -// a new header field. |
| +// - in any field, an RFC 2047 encoded word that does not decode, is in |
| +// a charset outside the allowlist, or decodes to a control character: |
| +// CR, LF, NUL and the rest; and any RFC 2231 parameter (a parameter |
| +// name holding "*"), refused up front (cleanFieldValue, encoded.go; |
| +// ruled 2026-11-14). A reader that decodes it and writes it out again |
| +// would otherwise write the decoded line break as a new header field. |
| func headerBlock(raw []byte) ([]byte, error) { |
| header, _, ok := splitHeader(raw) |
| if !ok { |
| return nil, errNoSeparator |
| } |
| first := true |
| - // The unfolded value of the field being read. |
| - var value []byte |
| - field := func() bool { return cleanFieldValue(string(value)) } |
| + // The value of the field being read, unfolded two ways: with each |
| + // fold's whitespace kept (RFC 5322's unfolding), and with it removed, |
| + // as a reader that drops the fold whole would read it. Both are |
| + // checked (ruled 2026-11-14). |
| + var value, joined []byte |
| + field := func() bool { return cleanFieldValue(string(value)) && cleanFieldValue(string(joined)) } |
| for i := 0; i < len(header); { |
| j := bytes.IndexByte(header[i:], '\n') |
| line := bytes.TrimSuffix(header[i:i+j], []byte{'\r'}) |
| @@ -77,6 +80,7 @@ func headerBlock(raw []byte) ([]byte, error) { |
| return nil, errHeaderSyntax |
| } |
| value = append(value, line...) |
| + joined = append(joined, bytes.TrimLeft(line, " \t")...) |
| } else { |
| c := bytes.IndexByte(line, ':') |
| if c <= 0 { |
| @@ -92,6 +96,7 @@ func headerBlock(raw []byte) ([]byte, error) { |
| } |
| rest = line[c+1:] |
| value = append([]byte(nil), rest...) |
| + joined = append([]byte(nil), rest...) |
| } |
| for _, b := range rest { |
| if (b < 0x20 && b != '\t') || b == 0x7f { |
diff --git a/internal/mailer/hygiene_test.go b/internal/mailer/hygiene_test.go| index c59de3754..ed4435f6c 100644 |
| --- a/internal/mailer/hygiene_test.go |
| +++ b/internal/mailer/hygiene_test.go |
| @@ -157,17 +157,29 @@ func TestHeaderBlockRefusesEncodedControls(t *testing.T) { |
| "a word with no charset": msg("From: "+from, "Subject: =??q?x?="), |
| "an encoding not B or Q": msg("From: "+from, "Subject: =?utf-8?x?abc?="), |
| "Q with a space": msg("From: "+from, "Subject: =?utf-8?q?a b?="), |
| - "a leftover word shape": msg("From: "+from, "Subject: =?utf-8?=0A?="), |
| // Round 1 P2: every field. |
| - "Resent-From": msg("From: "+from, "Resent-From: =?utf-8?q?x=0D=0ABcc:_v@example.com?= <y@example.org>"), |
| - "Return-Path": msg("From: "+from, "Return-Path: =?utf-8?q?x=0Ay?= <y@example.org>"), |
| - "Comments": msg("From: "+from, "Comments: =?utf-8?q?x=0Ay?="), |
| - "List-Id": msg("From: "+from, "List-Id: =?utf-8?q?x=0Ay?= <list.example.org>"), |
| - "Content-Type name=": msg("From: "+from, `Content-Type: application/pdf; name="=?utf-8?q?x=0Ay.pdf?="`), |
| - "RFC 2231 file name": msg("From: "+from, "Content-Disposition: attachment; filename*=utf-8''x%0D%0ABcc%3A%20v"), |
| - "RFC 2231 continuation": msg("From: "+from, "Content-Disposition: attachment;", " filename*0*=utf-8''a; filename*1*=%0Ab"), |
| - "RFC 2231 UTF-7": msg("From: "+from, "Content-Type: text/plain; name*=utf-7''%2BAA0ACg-"), |
| - "RFC 2231 bad escape": msg("From: "+from, "Content-Type: text/plain; name*=utf-8''a%0"), |
| + "Resent-From": msg("From: "+from, "Resent-From: =?utf-8?q?x=0D=0ABcc:_v@example.com?= <y@example.org>"), |
| + "Return-Path": msg("From: "+from, "Return-Path: =?utf-8?q?x=0Ay?= <y@example.org>"), |
| + "Comments": msg("From: "+from, "Comments: =?utf-8?q?x=0Ay?="), |
| + "List-Id": msg("From: "+from, "List-Id: =?utf-8?q?x=0Ay?= <list.example.org>"), |
| + "Content-Type name=": msg("From: "+from, `Content-Type: application/pdf; name="=?utf-8?q?x=0Ay.pdf?="`), |
| + // Ruled 2026-11-14: every RFC 2231 parameter is refused up front, |
| + // whatever it decodes to. Six spellings: extended, extended and |
| + // continued, continued plain, an empty charset, spaced and upper |
| + // case, and in a field that is not MIME's. |
| + "RFC 2231 extended": msg("From: "+from, "Content-Disposition: attachment; filename*=utf-8''x%0D%0ABcc%3A%20v"), |
| + "RFC 2231 extended, continued": msg("From: "+from, "Content-Disposition: attachment;", " filename*0*=utf-8''a; filename*1*=%0Ab"), |
| + "RFC 2231 continued, plain": msg("From: "+from, `Content-Type: application/pdf; name*0="a"; name*1="b.pdf"`), |
| + "RFC 2231 empty charset": msg("From: "+from, "Content-Type: text/plain; name*=''%0A"), |
| + "RFC 2231 spaced, upper case": msg("From: "+from, "Content-Type: text/plain; NAME *= UTF-7''%2BAA0ACg-"), |
| + "RFC 2231 in another field": msg("From: "+from, "X-Note: a; title*=utf-8''caf%C3%A9"), |
| + "RFC 2231, clean": msg("From: "+from, "Content-Disposition: attachment; filename*=utf-8'en'caf%C3%A9.pdf"), |
| + // Ruled 2026-11-14, the family's P3s. |
| + "invalid UTF-8 in a utf-8 word": msg("From: "+from, "Subject: =?utf-8?q?a=E2=80?="), |
| + "U+2028 split across two words": msg("From: "+from, "Subject: =?utf-8?q?a=E2=80?= =?utf-8?q?=A8b?="), |
| + "a charset by prefix only": msg("From: "+from, "Subject: =?iso-8859-1x?q?a?="), |
| + "an unknown euc": msg("From: "+from, "Subject: =?euc-x?q?a?="), |
| + "a word split by a fold": msg("From: "+from, "Subject: x=", " ?utf-8?q?=0A?="), |
| // Round 1 P3s: ESC per word, and C1 whatever the charset. |
| "ESC beside an ISO-2022-JP word": msg("From: "+from, "Subject: =?iso-2022-jp?b?GyRCJEokcyQrGyhC?= =?utf-8?b?eBt5?="), |
| "NEL in iso-8859-2": msg("From: "+from, "Subject: =?iso-8859-2?q?x=85y?="), |
| @@ -181,17 +193,21 @@ func TestHeaderBlockRefusesEncodedControls(t *testing.T) { |
| } |
| } |
| for name, raw := range map[string][]byte{ |
| - "B, a UTF-8 name": msg("From: =?utf-8?b?Y2Fmw6k=?= <" + from + ">"), |
| - "Q, a UTF-8 name": msg("From: =?utf-8?q?caf=C3=A9?= <" + from + ">"), |
| - "Q, a tab": msg("From: "+from, "Subject: =?utf-8?q?a=09b?="), |
| - "ISO-2022-JP's ESC": msg("From: "+from, "Subject: =?iso-2022-jp?b?GyRCJEokcyQrGyhC?="), |
| - "no encoded word": msg("From: Docs <"+from+">", "Subject: =? not a word"), |
| - "a folded subject": msg("From: "+from, "Subject: =?utf-8?q?caf=C3=A9?=", " =?utf-8?q?_au_lait?="), |
| - "windows-1252": msg("From: "+from, "Subject: =?windows-1252?q?=93quoted=94?="), |
| - "Shift_JIS": msg("From: "+from, "Subject: =?Shift_JIS?B?g26DjYFb?="), |
| - "a language suffix": msg("From: "+from, "Subject: =?utf-8*en?q?hello?="), |
| - "RFC 2231, clean": msg("From: "+from, "Content-Disposition: attachment; filename*=utf-8'en'caf%C3%A9.pdf"), |
| - "a URL with ?=": msg("From: "+from, "List-Unsubscribe: <https://example.org/u?id=1&t=2>"), |
| + "B, a UTF-8 name": msg("From: =?utf-8?b?Y2Fmw6k=?= <" + from + ">"), |
| + "Q, a UTF-8 name": msg("From: =?utf-8?q?caf=C3=A9?= <" + from + ">"), |
| + "Q, a tab": msg("From: "+from, "Subject: =?utf-8?q?a=09b?="), |
| + "ISO-2022-JP's ESC": msg("From: "+from, "Subject: =?iso-2022-jp?b?GyRCJEokcyQrGyhC?="), |
| + "no encoded word": msg("From: Docs <"+from+">", "Subject: =? not a word"), |
| + "a folded subject": msg("From: "+from, "Subject: =?utf-8?q?caf=C3=A9?=", " =?utf-8?q?_au_lait?="), |
| + "windows-1252": msg("From: "+from, "Subject: =?windows-1252?q?=93quoted=94?="), |
| + "Shift_JIS": msg("From: "+from, "Subject: =?Shift_JIS?B?g26DjYFb?="), |
| + "a language suffix": msg("From: "+from, "Subject: =?utf-8*en?q?hello?="), |
| + "a star, not in a parameter": msg("From: "+from, "Subject: a*=b"), |
| + "=? and ?= that are not a word": msg("From: "+from, "Subject: is a=?b then c?=d"), |
| + "a URL holding =? and ?=": msg("From: "+from, "List-Unsubscribe: <https://example.org/u?x=?1&y=2?=3>"), |
| + "=? with too few ?": msg("From: "+from, "Subject: =?utf-8?=0A?="), |
| + "a plain parameter": msg("From: "+from, `Content-Type: application/pdf; name="report.pdf"`), |
| + "a URL with ?=": msg("From: "+from, "List-Unsubscribe: <https://example.org/u?id=1&t=2>"), |
| } { |
| if _, err := headerBlock(raw); err != nil { |
| t.Errorf("%s: headerBlock refused %q: %v", name, raw, err) |
diff --git a/internal/mailer/send_test.go b/internal/mailer/send_test.go| index bd72f3c04..54afb7c22 100644 |
| --- a/internal/mailer/send_test.go |
| +++ b/internal/mailer/send_test.go |
| @@ -655,10 +655,16 @@ func TestMailerRefusesEncodedHeaderInjection(t *testing.T) { |
| t.Errorf("%s: %+v, want 400 bad_request", from, got) |
| } |
| } |
| + // Ruled 2026-11-14: an RFC 2231 parameter is a 400 too, whatever it |
| + // decodes to. |
| + raw := "From: " + tFrom + "\r\nTo: x@example.org\r\nContent-Disposition: attachment; filename*=utf-8''x%0D%0ABcc%3A%20v\r\n\r\nbody\r\n" |
| + if got := h.send(h.request(func(r *mailsubmit.SendRequest) { r.Raw = []byte(raw) })); got.status != http.StatusBadRequest || got.ans.Code != mailsubmit.CodeBadRequest { |
| + t.Errorf("an RFC 2231 parameter: %+v, want 400 bad_request", got) |
| + } |
| if h.ses.n() != 0 { |
| t.Fatalf("SES called %d times", h.ses.n()) |
| } |
| - raw := "From: =?utf-8?b?Y2Fmw6k=?= <" + tFrom + ">\r\nTo: x@example.org\r\nSubject: hi\r\n\r\nbody\r\n" |
| + raw = "From: =?utf-8?b?Y2Fmw6k=?= <" + tFrom + ">\r\nTo: x@example.org\r\nSubject: hi\r\n\r\nbody\r\n" |
| if got := h.send(h.request(func(r *mailsubmit.SendRequest) { r.Raw = []byte(raw) })); got.status != http.StatusOK { |
| t.Fatalf("a clean encoded name: %+v", got) |
| } |
diff --git a/internal/provision/testdata/plan14-root-reads-platform-mail-submission.tsv b/internal/provision/testdata/plan14-root-reads-platform-mail-submission.tsv| index 042035ae5..bb9708d43 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-platform-mail-submission.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-platform-mail-submission.tsv |
| @@ -95,7 +95,7 @@ internal/host/agent.go runAgent authority B,C,D,F rev3=census-ruling-self-serve- |
| @coverage internal/host/units 63a333f0bb4a354fdde9802089f4ec6794cdfbf774c20fbd48cffab805cd022c |
| @coverage internal/hostenv 6c96c4abe8548fe3cf12d3a220de3e2917c3edfa5320b1662ea76bdf364d24b5 |
| @coverage internal/instancectl 811493ad636a21f5f8e7f2336e8e58055fd2a83f53dd71ef689cd90232e7d3df |
| -@coverage internal/mailer 68d76c7fda5ed89f1924a0ddcb777635879d6c08ff0daf66d005cf5032337757 |
| +@coverage internal/mailer 8480d8ca048f2f7e966e317d74b3aac864e28d270216459f1386ef929c354bae |
| @coverage internal/mailsubmit 519123e15891e0802427595306d8caca1fd7f4f861ae1a2ec70e1c10f012e263 |
| @coverage internal/mailwire 0242392c670a0f61b875056b0d79576ccb69c2e29f56735cbb191e7d038222a0 |
| @coverage internal/moves 9390702695d308a327f5572f4ff5967718141c5d385dff7671ff1e2c825ef407 |