checkout: an address field is one line, and the invoice prints it as text

The invoice is clearsigned, and its "Billed and shipped to" block is the
buyer's own words: name, street, postal code and city went into it as
typed. A name with a line break in it could write lines of its own into
a document the shop signs. One with no line break could still open a
heading ("# CREDIT NOTE") or, together with the street and the city, a
table, because each of those fields starts a line.

Checkout now refuses those four fields when they hold a line break or a
control character: the C0 and C1 controls, U+2028 and U+2029, and the
bidirectional embedding, override and isolate controls, which make a
line display in another order than it is stored. A tab is the
exception. A single-line input drops line breaks from a paste and keeps
tabs, so "Hoofdstraat<TAB>12" is a real buyer's address, and it is
stored with the space the tab stood for. Form::SingleLine is the one
definition of what counts.

The invoice builder applies the same function to whatever the record
holds, since a record can be older than the check or written by hand,
and prints the block indented four spaces. That is Markdown's literal
block: nothing in it is read as markup, and it reads the same as plain
text. The item in the amounts table is held to its cell too, because a
colour the catalogue no longer lists is printed as the ledger has it,
and checkout no longer stores a posted colour for a product that has no
variants.

ShouldBuildInvoices checks the property on the document (every line of
the block is blank or indented) rather than on particular strings, and
ShouldValidateForms pins the edges of each character range.

Found in the security review of 2026-11-26; the Markdown half by the
adversarial review of the first fix. No priced product is listed, so
none of it was reachable yet.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
This commit is contained in:
Jorijn van der Graaf 2026-11-26 11:05:35 +01:00
commit f51105a768
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
5 changed files with 319 additions and 11 deletions

View file

@ -169,6 +169,101 @@ int main() {
+ "&street=x&postal=1&city=y&country=NL").Ok(),
"checkout: overlong name rejected");
// One line each. The address fields are printed one to a line on the
// invoice the shop signs, so a line break inside one is a way to write
// lines of one's own into that document: a heading, a row of the amounts
// table, a sentence about a refund. A browser's single-line input cannot
// send one; %0A in a hand-made post can.
{
auto broken = validate("email=a%40b.example"
"&name=Ada%0A%0A%23%23%20Amounts%0A%0ARefund%20due"
"&street=x&postal=1&city=y&country=NL");
Check(!broken.Ok(), "checkout: a line break inside the name is rejected");
Check(broken.errors.size() == 1 && broken.errors[0].field == "name",
"checkout: and the refusal hangs off the name field");
}
Check(!validate("email=a%40b.example&name=Ada&street=Main%20St%201%0D%0AMore"
"&postal=1&city=y&country=NL").Ok(),
"checkout: CRLF inside the street is rejected");
// A tab is the one of these a real buyer sends: a single-line input drops
// the line breaks from a paste and keeps the tabs, and an address copied
// out of two spreadsheet cells arrives with one in the middle. It is
// whitespace someone meant as a space, so it is stored as one. Refusing
// it told a buyer who pasted their own address that it "must be a single
// line", which it was.
{
auto pasted = validate("email=a%40b.example&name=Ada&street=Hoofdstraat%0912"
"&postal=1234%09AB&city=y&country=NL");
Check(pasted.Ok(), "checkout: a pasted tab does not refuse the address");
Check(pasted.value.street == "Hoofdstraat 12",
"checkout: a tab inside a field is stored as the space it stood for",
pasted.value.street);
Check(pasted.value.postal == "1234 AB",
"checkout: in every address field", pasted.value.postal);
}
// What a refusal says. It names the cause, because the buyer who meets it
// pasted something they cannot see.
{
auto broken = validate("email=a%40b.example&name=Ada%0AMore&street=x&postal=1"
"&city=y&country=NL");
Check(broken.errors.size() == 1
&& broken.errors[0].message.find("Line breaks") != std::string::npos,
"checkout: the refusal says line breaks are the problem",
broken.errors.empty() ? "no error" : broken.errors[0].message);
}
// Two more kinds of character that are not text on a line. U+009B is CSI,
// which starts an escape sequence in a terminal showing the ledger or the
// invoice. U+202E turns the rest of the line around on screen, so that a
// line reads one thing and holds another.
Check(!validate("email=a%40b.example&name=Ada%C2%9B31mRed&street=x&postal=1"
"&city=y&country=NL").Ok(),
"checkout: a C1 control character inside the name is rejected");
Check(!validate("email=a%40b.example&name=Ada&street=x&postal=1"
"&city=y%E2%80%AEdiap&country=NL").Ok(),
"checkout: a direction override inside the city is rejected");
// U+2028 and U+0085: line breaks to an editor, and not control characters
// to a check that only looks below 0x20.
Check(!validate("email=a%40b.example&name=Ada&street=x&postal=1"
"&city=Delft%E2%80%A8More&country=NL").Ok(),
"checkout: a Unicode line separator inside the city is rejected");
Check(!validate("email=a%40b.example&name=Ada%C2%85More&street=x&postal=1"
"&city=y&country=NL").Ok(),
"checkout: a Unicode next-line inside the name is rejected");
// What must NOT be caught: a line break at the very end is trimmed like
// any other stray whitespace, and a name outside ASCII is a name. Zoë and
// Łukasz are here for their bytes — C3 AB and C5 81 sit right next to the
// C2 85 the rule looks for.
Check(validate("email=a%40b.example&name=Ada%0D%0A&street=x&postal=1"
"&city=y&country=NL").Ok(),
"checkout: a trailing line break is trimmed, not refused");
Check(validate("email=a%40b.example&name=Zo%C3%AB%20%C5%81ukasz&street=x"
"&postal=1&city=%C2%A3%E2%80%99s-Hertogenbosch&country=NL").Ok(),
"checkout: names and cities outside ASCII are still accepted");
Check(SingleLine("a\nb\r\nc\td") == "a b c d",
"single line: each control character becomes one space");
Check(SingleLine("x\xC2\x85y\xE2\x80\xA8z\xE2\x80\xA9!") == "x y z !",
"single line: NEL, LS and PS each become one space");
Check(SingleLine("Zo\xC3\xAB \xC2\xA3 \xE2\x80\x99s") == "Zo\xC3\xAB \xC2\xA3 \xE2\x80\x99s",
"single line: other multi-byte characters pass through untouched");
// The edges of each range, so a neighbour is not swept up with it:
// U+007F..U+00A0 around the C1 block, U+2027..U+202F around the line
// breaks and overrides, U+2065..U+206A around the isolates.
Check(SingleLine("a\xC2\x80" "b\xC2\x9F" "c") == "a b c",
"single line: the first and last C1 controls become spaces");
Check(SingleLine("a\xC2\xA0" "b") == "a\xC2\xA0" "b",
"single line: a no-break space, one past the C1 block, is text");
Check(SingleLine("a\xE2\x80\xAA" "b\xE2\x80\xAE" "c\xE2\x81\xA6" "d\xE2\x81\xA9" "e")
== "a b c d e",
"single line: the direction controls become spaces");
Check(SingleLine("a\xE2\x80\xA7" "b\xE2\x80\xAF" "c\xE2\x81\xA5" "d\xE2\x81\xAA" "e")
== "a\xE2\x80\xA7" "b\xE2\x80\xAF" "c\xE2\x81\xA5" "d\xE2\x81\xAA" "e",
"single line: their neighbours on either side are left alone");
// Arabic and Hebrew text needs none of the explicit controls: its
// direction comes from the letters. A name in either must pass whole.
Check(SingleLine("\xD7\xA9\xD7\x9C\xD7\x95\xD7\x9D \xD9\x85\xD8\xB1\xD8\xAD\xD8\xA8\xD8\xA7")
== "\xD7\xA9\xD7\x9C\xD7\x95\xD7\x9D \xD9\x85\xD8\xB1\xD8\xAD\xD8\xA8\xD8\xA7",
"single line: right-to-left text itself is untouched");
// Colour and quantity: shape checks here, catalogue checks in the handler.
Check(validate(std::string(kGoodOrder) + "&color=green&quantity=2").Ok(),
"checkout: colour and quantity accepted");