A payer could place several orders and send one transfer naming all of
them. Each order looked for its own reference, found it, and saw the
full amount, so every order settled on one payment: three EUR 5 orders
on a single EUR 5 credit, reproduced. The rail logged "settle this one
by hand" and settled each of them. The README called it a known
limitation; it was a way to pay once for several orders.
The rail now records which payment settled which order, by the bank's
id, in <credits>.claims, before it reports the order paid, and a claimed
payment is left out of every other order's sum. The record cannot live
in the credits file, which the pull replaces every hour. It is read back
at start. If it cannot be written the rail settles nothing and says why;
if it is there and cannot be read the rail does not start. A claims
file that ends mid-line gets its line break before the next claim, or
that claim would be lost at the next start and the payment free again.
It does not rest on what a description looks like, because the payer
writes it. The "also quotes another reference" flag stays as a pointer
in the log and decides nothing: a name followed by a date has the same
shape. A payer who really sends one transfer for two orders gets the
first settled and the other by hand, with one line in the journal.
One payment is also counted once however many lines of the credits file
carry its id. Two lines are not meant to happen and were reproduced all
the same (one callback delivered on two connections at once passed the
id check twice), and summed they settle an order on half its price. The
callback's look-then-append is now under a lock as well.
ShouldMatchBankTransfers drives the matcher and the rail itself across
a restart, a torn claims file, an unreadable one and a duplicated line;
ShouldSettleBankTransfers shows over HTTP that one of three orders
settles.
Found in the security review of 2026-11-26; the torn claims file and
the duplicate line by the adversarial review of the first fix.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
The ledger was folded from disk on every call: every order page, every
/financials request, every reconciler sweep, and every two seconds for
the mailer. Each event found its order by walking the orders so far, so
a fold was quadratic. A ledger of 40 000 orders took 11.9 s to fold,
anyone can add orders, and /financials is public and uncached.
Orders are now found through an index, which makes a fold one pass
(0.33 s for the same ledger), and the fold is held in memory. Every
call stats the file, and a different size or modification time means
fold it again, so an append by the CLI from another process and an edit
by hand are seen on the next call without a restart. What this process
appends itself is applied to the held fold by the same function that
folds a line from disk, provided the file grew by exactly what was
written; if it grew by more, another writer's line is in there and the
file is folded again. With 40 000 orders /financials takes about 1 ms
and an order page 0.3 ms. /financials sums from the held fold through
LedgerSales and no longer copies every order to do it.
The file stays the ledger and the held fold a reading of it. It costs 3
to 4 KB of memory an order, and it cannot see a change that leaves both
the size and the modification time as they were.
One thing the writer does differently. A file that ends mid-line, after
a crash during a write, now gets its line break before the next event.
The next event used to be written onto the end of the broken line and
was skipped with it, so a crash cost two events, not one.
The reference a payer quotes is the first six hex digits of the token:
24 bits, where two orders in a few thousand share one often enough to
plan for, and a transfer quoting it would pay for both. Checkout now
mints its token through NewUniqueOrderToken, which reads every
reference the ledger has ever held, lapsed and cancelled orders
included, and holds the reference while the checkout is in flight.
ShouldFoldTheOrderLedger compares the held fold with a fresh one after
appends of every kind, an outside append, a same-size edit, a replaced
file and a torn tail. It hands colliding draws to the mint, since the
real generator collides once in sixteen million. And it races one
outside line against a stream of this process's own appends, which
fails within a few rounds when the size check is removed.
Found in the security review of 2026-11-26.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Two limits that were not limiting.
The listener's default body limit is 512 MiB and nothing set another,
with no cap on connections: one 64 MiB POST took the server from 7 MB
to 72 MB before the handler's own 16 KiB check answered 413. The limit
is now 64 KiB. A request that announces more in Content-Length is
answered 400 from its headers, with none of its body read: a 64 MiB
upload is refused after 786 KB and the server's peak memory does not
move.
That is a limit on the decoded body, and the comment says so. A chunked
request sent straight to the port can pad its chunk framing and still
make one connection hold hundreds of megabytes; the parser that allows
it is Crafter.Network's. Behind Caddy an oversized body is refused by
request_body before it gets here, so this is one more thing that rests
on port 8081 being private.
The per-peer checkout limit was kept per address. Over IPv6 one
subscriber holds a whole prefix, a /56 or a /48, and can submit from a
fresh address every time, so the per-peer cap did nothing and the
global cap was the only limit an IPv6 client met. The key is now the
IPv4 address or the IPv6 /48 (RateLimitKeyFor). An IPv4-mapped address
is keyed as the IPv4 client it is, and something that does not read as
an address is keyed as written, so a peer is never dropped to "no peer"
by its spelling. On a /56 ISP 256 neighbouring households share one
budget of six submissions per ten minutes; that was weighed and taken.
ShouldGuardRequestProvenance pins the key. ShouldServeRoutes drives it
over HTTP: six addresses of one /48 are accepted, a seventh is refused
with 429, the next /48 is not; and a body past 64 KiB is refused with
the server still up afterwards.
Found in the security review of 2026-11-26.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
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>
The script stopped at "crafter-build: command not found": crafter-build
is a shell alias for the Flatpak, and a /bin/sh script does not inherit
aliases. It now calls the Flatpak itself unless a crafter-build command
is on PATH.
The server it builds links the SDK's libc++ and libunwind, so on the
host it does not start (libunwind.so.1 not found). It now runs inside
the Flatpak, like CI's crafter-run, with the temp dir granted so it can
write the order ledger; without the grant every checkout answers 500.
bin/ held builds from the old and the current toolchain, and the
exactly-one rule refused to pick. Every Crafter.Build update adds a
variant directory, so the script now takes the newest and says which,
rather than failing after each update. CI keeps its strict rule.
Stopping it also stops its tail of the server log, which was left
running whenever the script ended without a Ctrl-C. The help text names
/shop/donation and no longer mentions the RF form.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bank-transfer block on the order page now gives two ways to pay.
First a payto link (RFC 8905) that hands the IBAN, the amount, the
account-holder name and the order code to a payment app in one go, then
"Or do a manual transfer" with the same details as before.
The manual details list the order code as the Description and nothing
else. The page used to print the structured RF reference as well, with
a paragraph on which code goes in which field, and that read as two
codes for one payment. Matching never needed the RF form: the matcher
finds the CC- code anywhere in the remittance text, the RF form
included. OrderCryptoPay::structuredReference, which only fed that row,
is gone; CreditorReferenceFromToken stays, with its unit test.
The link is built in the view from the very values the manual details
print, so the two cannot disagree. Url() now lets payto: through, like
ethereum:, and the name is percent-encoded because Url() strips spaces.
ShouldSettleBankTransfers asserts the whole link, including that its
message is the reference the matcher looks for.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The shadow run of 36a635f had Nostro's ReadCallback read a real
callback beside our own parser on 2026-11-25, for order CC-BCD155: the
same id, amount and reference, on the shop's own account. So the reader
takes over, and what this repo carried of bunq goes: the callback
parser, the payment-type table, the API client with its RSA signing,
`--pull-credits`, the mode that read the bank from the server with an
API key, and tools/register-bunq-webhook.sh.
The server now knows no bank. Catcrafts.Server-BankCallback.cpp is the
one unit that imports Nostro.Money: ReadBankCallback has a body read
and says what it comes to, CreditMethodFor says how a payment arrived.
Which bank it is is configuration: --banks= in project.cpp for what the
build can read, BANK_CALLBACK_BANK on the server for what arrives.
What changes for a running shop:
- The endpoint is configured with BANK_CALLBACK_PATH and
BANK_CALLBACK_BANK; BUNQ_WEBHOOK_PATH is no longer read. Without the
bank's name, or without TRANSFER_IBAN, the endpoint stays off and the
startup log says so: one that answered 200 and credited nothing would
look like working. Production's payments.env got both names before
this was pushed.
- Only a payment on TRANSFER_IBAN is credited. A bank posts to whatever
address any of its customers registered, so a callback about someone
else's account can be the bank's own. Until now a payment in a
callback was credited whichever account it was on.
- `via` says `internal` for a payment from another account at the bank
itself, where it said `bunq`, and `card` where it would have said
`MASTERCARD`. A kind without a word is still passed on as the bank
wrote it, now only where that is a plain word.
- Every callback leaves one line in the log, `bank callback: credited
...` or `bank callback: nothing credited: <why>`, with nothing of the
body in it beyond the credit.
- A line of the credits file may carry the bank's kind and the bank
(`"bank":"bunq","kind":"EBA_SCT/SCT"`) in place of `method`, put into
the ledger's words when the file is read. The pull script ships those
and takes the bank's name from nostrod, so it holds no table of a
bank's words either.
Also gone, with their last user: ParseAmountToMinor, PullCreditsInto
and the explicit -lcrypto (Crafter.Network names what it needs).
ShouldReadBankCallbacks replaces ShouldParseBunqPayments and
ShouldCompareCallbackReaders: what a callback comes to for each shape,
each method, the account and the sign, and that no note repeats
anything a body carried. ShouldReceiveBankCallbacks posts to the real
endpoint: an order settles from a callback, one from another account
quoting the same order does not pay for it, and a server without the
bank's name has no endpoint.
Built from scratch and run in a copy of this tree with crafter-build
6.4.1: the server and the wasm bundle build, and every suite passes but
ShouldServePostPages, which fails there for want of mirrored post media
and passed in CI on the commit before this. A dry run of the pull
script against nostrod gave 19 credits with their kinds.
Not tried: a real callback through the new handler, and `nostro
callbacks` against the registration that is in place, which was made
with the script this removes. deploy/README.md has the new setup.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ParseBunqCallback is to be replaced by ReadCallback of Nostro.Money
(Nostro 1.1.0), so that this repo stops carrying bunq's wire format.
That reader is stricter than ours: it wants a time, a counterparty and
the account's own IBAN where ours reads four members, and nobody has
run it on a callback bunq really sent. Ours has settled real payments
since 2026-08. So before anything is swapped, both run.
- The handler is untouched and still decides alone. Once it has
answered and written its credit, Nostro's reader reads the same body
and one line goes to the log: `bank callback shadow: AGREE ...` when
the id, the amount and the reference are the same in both readings,
and `DIFFER ...` with what parted them otherwise.
- The line carries no payment data: no id, amount, name or reference,
only whether values match and a few fixed words. A body holds the
payer's name and IBAN, and may repeat the secret address.
- It is on wherever BUNQ_WEBHOOK_PATH is set, with no setting of its
own.
- project.cpp takes Nostro with --product=money --banks=bunq, at the
commit of its 1.1.0 release: the module alone, which brings no
credential and no Crafter.Network, Crafter.DB or OpenSSL of its own.
ShouldCompareCallbackReaders pins every verdict, and that none repeats
anything a body carried. ShouldReceiveBankCallbacks posts callbacks to
the real endpoint: an order settles from one, a payment Nostro's reader
refuses is credited all the same, and the server's log holds nothing of
what was posted.
Built and run in a copy of this tree with crafter-build 6.4.1: the
server and the wasm bundle build, and every suite passes but
ShouldServePostPages, which fails the same way without this change
where the post media is not mirrored. The binary needs the same shared
libraries as before.
Temporary: once real payments read AGREE the reader takes over, and
this goes together with ParseBunqCallback. deploy/README.md says how to
read the result.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
tools/pull-and-ship-credits.sh ran this repo's own bunq client
(`catcrafts-server --pull-credits`) with the API key from .env: a key
that can initiate payments, where every program run in the checkout
could read it. It now asks nostrod (Nostro) for the account's
transactions over the system bus and turns the answer into the same
credit lines. nostrod lets a program look without a password and lets
nothing pay without one, so the pull holds no credential at all.
- Each run ships the last 90 days (CREDITS_DAYS), the longest window an
order can wait in, in place of an accumulating local copy fed by a
reader that only ever saw the newest 50 payments.
- --dry-run prints what would be shipped and ships nothing.
- deploy/README.md: how the pull works now, the polkit rule a timer
needs to look without a login session, and what the old reader is
still kept for (tools/register-bunq-webhook.sh, until `nostro
callbacks` of Nostro 1.1.0 has been seen to list the shop's webhook).
Checked on 2026-11-21 against the production account, through nostrod:
a dry run gave, for each of the 24 incoming payments the old client had
written, a line byte-identical to the old client's. A real run, with
the ship to the server, has not been made, and the timer is installed
nowhere yet.
No C++ changes: the two edits to sources are to comments.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A job goes to whichever runner carrying its label polls first, and the
`flatpak` label this job shared with imsd's package job is also on the
organisation-wide cx33-org-flatpak runner (registered 2026-10-14), which
has no deploy mounts, no Flatpak volume and defaults to an alpine image.
Crafter.Build's run 550 landed there on 2026-10-16 and failed before
building; runs 549 and 552 of this job reached the right runner only
because it polled first.
The repository's runner now declares `catcrafts-deploy:docker://archlinux:latest`
(a config edit and a service restart; labels are not part of the
registration), and the job asks for that. Nothing else changes.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Crafter.Build 2.2.0 (2026-10-16) releases the Shader `defines` and
`variant` fields Crafter.Graphics master has used since 2026-10-06, so
CRAFTER_REF goes back to //stable and the toolchain moves only with a
Crafter.Build release again, the way imsd's package job has it. The
comments and the README now describe beta as the stopgap for the next
time Crafter.Graphics runs ahead of a release.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Run 533, the first on the Flatpak toolchain, installed the Flatpak, built
the server and passed all 28 suites, then failed building the wasm bundle:
Crafter.Graphics master has used the Shader `defines` and `variant` fields
since 2026-10-06, and the `stable` Flatpak is the 2.1.0 release from three
days before that. Only Crafter.Build master has them, so the toolchain is
its `beta` branch for now, which is also what the rolling `latest` tarball
this job used to download was: a build of master.
The branch is one variable at the top of the job, the way imsd's package
job pins its own (imsd stays on stable; it has no Crafter.Graphics). Flip
it back to //stable once a Crafter.Build release carries the fields. The
wrapper scripts expand the ref at write time, and the install step prints
them along with the Flatpak's branch and commit so a run's log says which
toolchain it used.
Verified locally with beta 2.1.0-10-g4af9280: the wasm bundle builds and
the server suite passes, except ShouldServePostPages, which needs the media
mirror on the deploy mount that only exists in CI.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Crafter.Build's CI publishes only the Flatpak since 2026-10-02, so the
rolling `latest` tarball the Install crafter-build step downloaded is gone
and the 2026-10-12 deploy failed with a 404 before building anything.
Take the route imsd's package job takes. The job runs on `flatpak`, a
privileged runner registered to this repository alone
(forgejo-runner-catcrafts on the box, same arrangement as imsd's), with the
installed Flatpak and its Sdk kept on a docker volume between runs. The
container installs nothing that compiles any more: clang, lld, libc++, the
WASI sysroot, cmake, perl, gpg and OpenSSL all come with the Flatpak and its
Sdk. `crafter-build` is a wrapper around `flatpak run`, `crafter-run` runs a
built binary inside the sandbox, cast is installed under /opt where the
sandbox can see it, and the cache path is the Flatpak's own.
The server binary links the Flatpak's libc++, libc++abi and libunwind, which
are newer than the host's, so the deploy ships them next to the binary the
way it already ships libmsquic; the rpath finds them there. They need at
most GLIBC_2.38, the host has 2.41.
ShouldMatchBankTransfers passed braced lists straight into a std::span
parameter. That compiled only because libc++ 22 had the C++26
span(initializer_list) constructor; the libc++ 23 in the Flatpak does not,
so the lists now go through a vector like the rest of the file.
deploy/README.md documents the runner, the sandbox's private /tmp and how
to run a built binary where the host lacks a matching libc++.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The webhook is deregistered at bunq and the callback endpoint, its parser,
default-deny classifier, dedup ledger and signature check are removed; the
code is in git history if a bank feed ever comes back. /financials keeps
reading the hand-maintained aggregates file, and sales + shop donations
stay live from the order ledger.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>