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
|
|
@ -48,6 +48,33 @@ std::int64_t RowMinor(const std::string& md, std::string_view prefix) {
|
|||
return euros * 100 + cents;
|
||||
}
|
||||
|
||||
// Whether the address block is a Markdown literal block and nothing else:
|
||||
// every line between its heading and the next one is blank or starts with
|
||||
// four spaces. That is the property that makes a buyer's text inert there,
|
||||
// whatever it holds, and it is checked on the document, not on particular
|
||||
// forged strings: a line that slipped out of the block would fail this
|
||||
// whatever it said.
|
||||
bool AddressBlockIsLiteral(const std::string& md) {
|
||||
const std::string_view open = "\n## Billed and shipped to\n";
|
||||
const std::size_t from = md.find(open);
|
||||
if (from == std::string::npos) return false;
|
||||
const std::size_t start = from + open.size();
|
||||
const std::size_t stop = md.find("\n## Amounts\n", start);
|
||||
if (stop == std::string::npos) return false;
|
||||
bool any = false;
|
||||
for (std::size_t at = start; at < stop;) {
|
||||
const std::size_t nl = md.find('\n', at);
|
||||
const std::size_t end = std::min(nl, stop);
|
||||
const std::string_view line = std::string_view(md).substr(at, end - at);
|
||||
if (!line.empty()) {
|
||||
if (!line.starts_with(" ")) return false;
|
||||
any = true;
|
||||
}
|
||||
at = end + 1;
|
||||
}
|
||||
return any;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
|
|
@ -86,6 +113,92 @@ int main() {
|
|||
Check(eu.find("€1135.23") != std::string::npos, "invoice: EU total");
|
||||
Check(eu.find("zero-rated") == std::string::npos, "invoice: EU is not an export");
|
||||
|
||||
// The address block is the buyer's own text inside a document the shop
|
||||
// signs, and it must stay text: nothing in it may be read as a heading, a
|
||||
// table or markup of the invoice. Two properties, checked separately
|
||||
// because the first alone was once taken for the whole.
|
||||
//
|
||||
// ONE: a field stays on its line. A record holding line breaks (written
|
||||
// before checkout refused them, or by hand) cannot start lines of its own.
|
||||
{
|
||||
Server::OrderRecord forged = o;
|
||||
forged.buyer.name = "Ada\n\n## Amounts\n\n| Refund due | 1 | €5000 |";
|
||||
forged.buyer.city = "Delft\r\n# Invoice 999";
|
||||
const std::string md =
|
||||
Server::BuildInvoiceMarkdown(forged, "Fairphone 6", "Forest Green");
|
||||
const std::size_t heading = md.find("\n## Amounts\n");
|
||||
Check(heading != std::string::npos
|
||||
&& md.find("\n## Amounts\n", heading + 1) == std::string::npos,
|
||||
"invoice: a line break in a name cannot open a second amounts section");
|
||||
Check(md.find("\n Ada ## Amounts | Refund due | 1 | €5000 |\n")
|
||||
!= std::string::npos,
|
||||
"invoice: the field stays whole, on its one line of the address block");
|
||||
Check(AddressBlockIsLiteral(md),
|
||||
"invoice: with line breaks in the record, the block is still literal");
|
||||
}
|
||||
// TWO: the line it stays on is not read as Markdown. No line break is
|
||||
// needed to forge structure: name, street and city each begin a line, so
|
||||
// single-line values were enough for a heading, and three of them in a
|
||||
// row for a table. Every line of the block is therefore indented four
|
||||
// spaces, which makes it a literal block. These are the values that got
|
||||
// through a check for line breaks alone.
|
||||
{
|
||||
Server::OrderRecord forged = o;
|
||||
forged.buyer.name = "# CREDIT NOTE: refund of €5000 owed to the bearer";
|
||||
const std::string md =
|
||||
Server::BuildInvoiceMarkdown(forged, "Fairphone 6", "Forest Green");
|
||||
Check(md.find("\n# CREDIT NOTE") == std::string::npos,
|
||||
"invoice: a name that begins with '#' does not begin a line with it");
|
||||
Check(md.find("\n # CREDIT NOTE: refund of €5000 owed to the bearer\n")
|
||||
!= std::string::npos,
|
||||
"invoice: it is printed as the characters it is, indented");
|
||||
Check(AddressBlockIsLiteral(md), "invoice: a heading-shaped name stays literal");
|
||||
}
|
||||
{
|
||||
Server::OrderRecord forged = o;
|
||||
forged.buyer.name = "| Refund due | Qty | Amount |";
|
||||
forged.buyer.street = "|---|---|---|";
|
||||
forged.buyer.postal = "|";
|
||||
forged.buyer.city = "**Refund owed** | 1 | **€5000.00** |";
|
||||
const std::string md =
|
||||
Server::BuildInvoiceMarkdown(forged, "Fairphone 6", "Forest Green");
|
||||
Check(md.find("\n| Refund due") == std::string::npos
|
||||
&& md.find("\n| **Refund owed**") == std::string::npos,
|
||||
"invoice: three fields shaped like table rows do not begin lines");
|
||||
// The one real delimiter row is the amounts table's own.
|
||||
const std::size_t rule = md.find("\n|---|---|---|");
|
||||
Check(rule != std::string::npos
|
||||
&& md.find("\n|---|---|---|", rule + 1) == std::string::npos,
|
||||
"invoice: the only table in the document is the amounts table");
|
||||
Check(AddressBlockIsLiteral(md), "invoice: table-shaped fields stay literal");
|
||||
}
|
||||
{
|
||||
Server::OrderRecord forged = o;
|
||||
forged.buyer.name = "Ada<br><br><h2>Amounts</h2><table>";
|
||||
forged.buyer.street = "[pay the balance here](https://evil.example)";
|
||||
const std::string md =
|
||||
Server::BuildInvoiceMarkdown(forged, "Fairphone 6", "Forest Green");
|
||||
Check(AddressBlockIsLiteral(md),
|
||||
"invoice: HTML and a link in the address are inside the literal block");
|
||||
}
|
||||
// The other place text from a record is printed: the item, in a cell of
|
||||
// the amounts table. A colour the catalogue no longer lists is passed
|
||||
// through as stored, so it is held to its cell.
|
||||
{
|
||||
const std::string md = Server::BuildInvoiceMarkdown(
|
||||
o, "Fairphone 6", "green | 1 | €0.01 |\n| **Total** | | **€0.01**");
|
||||
const std::size_t row = md.find("\n| Fairphone 6");
|
||||
Check(row != std::string::npos, "invoice: the item row is there");
|
||||
if (row != std::string::npos) {
|
||||
const std::size_t end = md.find('\n', row + 1);
|
||||
const std::string_view line =
|
||||
std::string_view(md).substr(row + 1, end - row - 1);
|
||||
Check(std::ranges::count(line, '|') == 4,
|
||||
"invoice: a colour cannot add cells or rows to the amounts table",
|
||||
line);
|
||||
}
|
||||
}
|
||||
|
||||
// Every cent of the amounts table, pinned. This is the document a Dutch
|
||||
// buyer, an accountant and the Belastingdienst read, so a rounding change
|
||||
// in Money::NetFromGross must break a test rather than ship a wrong VAT
|
||||
|
|
|
|||
Loading…
Reference in a new issue