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:
parent
1fb4b1c302
commit
f51105a768
5 changed files with 319 additions and 11 deletions
|
|
@ -135,6 +135,55 @@ export std::string_view Trim(std::string_view s) {
|
|||
return s;
|
||||
}
|
||||
|
||||
// `s` as one line of text, read in the order it is written: every character
|
||||
// that starts a new line, is not text at all, or changes the direction text
|
||||
// is drawn in, becomes a space. That is
|
||||
//
|
||||
// * the C0 controls and DEL;
|
||||
// * the C1 controls, U+0080 to U+009F, which include NEL (a line break)
|
||||
// and CSI (the start of a terminal escape sequence);
|
||||
// * LS U+2028 and PS U+2029, line breaks to an editor that are not control
|
||||
// characters to anything that only looks at bytes below 0x20;
|
||||
// * the bidirectional embedding, override and isolate controls, U+202A to
|
||||
// U+202E and U+2066 to U+2069, which make a line DISPLAY in another
|
||||
// order than it is stored. An address in Arabic or Hebrew needs none of
|
||||
// them; a line that reads one thing and holds another does.
|
||||
//
|
||||
// It exists for the address fields. They are free text and stay free text,
|
||||
// but they are printed into an invoice the shop then SIGNS, one field to a
|
||||
// line, and a name carrying a line break would write lines of its own into
|
||||
// that document under the shop's signature. So one definition is shared:
|
||||
// validation refuses a field this function would change (a tab aside, which
|
||||
// it makes the same space), and the invoice builder applies it to whatever a
|
||||
// ledger already holds.
|
||||
//
|
||||
// This is about LINES, not about Markdown. A field that stays on its line can
|
||||
// still begin with '#' or '|', which is why the invoice prints the address as
|
||||
// a literal block instead of trusting this to keep it inert.
|
||||
export std::string SingleLine(std::string_view s) {
|
||||
auto at = [&](std::size_t i) { return static_cast<unsigned char>(s[i]); };
|
||||
std::string out;
|
||||
out.reserve(s.size());
|
||||
for (std::size_t i = 0; i < s.size(); ++i) {
|
||||
const unsigned char c = at(i);
|
||||
if (c < 0x20 || c == 0x7F) {
|
||||
out += ' ';
|
||||
} else if (c == 0xC2 && i + 1 < s.size()
|
||||
&& at(i + 1) >= 0x80 && at(i + 1) <= 0x9F) {
|
||||
out += ' '; // U+0080..U+009F
|
||||
i += 1;
|
||||
} else if (c == 0xE2 && i + 2 < s.size()
|
||||
&& ((at(i + 1) == 0x80 && at(i + 2) >= 0xA8 && at(i + 2) <= 0xAE)
|
||||
|| (at(i + 1) == 0x81 && at(i + 2) >= 0xA6 && at(i + 2) <= 0xA9))) {
|
||||
out += ' '; // U+2028..U+202E, U+2066..U+2069
|
||||
i += 2;
|
||||
} else {
|
||||
out += s[i];
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Deliberately permissive email check.
|
||||
//
|
||||
// Not a regex from a blog post and not an RFC 5322 parser. Fully validating an
|
||||
|
|
@ -370,17 +419,36 @@ export CheckoutResult ValidateCheckout(const Fields& f) {
|
|||
r.errors.push_back({ "email", "That doesn't look like an email address." });
|
||||
}
|
||||
|
||||
// A required free-text field: reject empty and oversize, accept everything
|
||||
// else. Names, streets and cities worldwide defeat any stricter shape check
|
||||
// — validating them harder only rejects real addresses.
|
||||
// A required free-text field: reject empty, oversize and anything that is
|
||||
// not one line, accept everything else. Names, streets and cities
|
||||
// worldwide defeat any stricter shape check — validating them harder only
|
||||
// rejects real addresses.
|
||||
//
|
||||
// One line is not a shape check on the address, it is what keeps the field
|
||||
// a field: these four are printed one to a line on the label and on the
|
||||
// signed invoice, and a line break inside one would start lines of the
|
||||
// buyer's own writing in a document the shop signs (see SingleLine).
|
||||
//
|
||||
// A TAB is the one such character a real buyer sends. A browser's
|
||||
// single-line input drops the line breaks from a paste and keeps its
|
||||
// tabs, and an address copied out of two spreadsheet cells arrives as
|
||||
// "Hoofdstraat<TAB>12". That is whitespace somebody meant as a space, so
|
||||
// it becomes one, the way Trim already treats it at either end. Anything
|
||||
// else SingleLine would change is refused rather than flattened, for the
|
||||
// reason quantity is: quietly changing what someone typed is worse than
|
||||
// asking again, and only a hand-made post can send it.
|
||||
auto requiredText = [&](std::string_view fieldName, std::string& into,
|
||||
std::size_t maxLen, std::string_view emptyMsg) {
|
||||
const std::string_view v = Trim(f.Get(fieldName));
|
||||
into = std::string(v);
|
||||
into = std::string(Trim(f.Get(fieldName)));
|
||||
std::ranges::replace(into, '\t', ' ');
|
||||
const std::string_view v = into;
|
||||
if (v.empty()) {
|
||||
r.errors.push_back({ std::string(fieldName), std::string(emptyMsg) });
|
||||
} else if (v.size() > maxLen) {
|
||||
r.errors.push_back({ std::string(fieldName), "Too long." });
|
||||
} else if (SingleLine(v) != v) {
|
||||
r.errors.push_back({ std::string(fieldName),
|
||||
"Line breaks and control characters can't be used here." });
|
||||
}
|
||||
};
|
||||
requiredText("name", r.value.name, 120, "A recipient name is required — it goes on the label.");
|
||||
|
|
|
|||
Loading…
Reference in a new issue