2026-08-05 04:18:37 +02:00
# Deploying catcrafts.net
Two artifacts come out of CI and land in two different places, on purpose.
| | goes to | served by |
|---|---|---|
| wasm bundle + static assets | `/srv/catcrafts.net` | Caddy `file_server` |
| `catcrafts-server` + `content/` | `/srv/catcrafts-app` | itself, on `127.0.0.1:8081` |
They are kept apart because the web root is **publicly served and mirrored with
`rsync --delete` ** on every push. Anything runtime-owned that lives there is
both published to the internet and destroyed on the next deploy — which matters
now for the content files and matters a great deal once the shop has a database
and bank credentials.
Runtime state goes in a third place, `/var/lib/catcrafts` , created by the
2026-08-14 02:50:58 +02:00
service's `StateDirectory=` . Today that is `orders.jsonl` (the order event log),
2026-08-17 11:36:54 +02:00
`orders.jsonl.shipping.json` (the cached carrier rate table) and
`orders.jsonl.financials.json` (the published running totals behind the public
/financials page — see "The open financials page"). Neither payment provider
needs stored state — both authenticate with a bearer token per request.
2026-08-05 04:18:37 +02:00
**Two things on this box cannot be regenerated.** Everything else — the wasm
bundle, the content, the binary — comes back from a rebuild.
The first is `orders.jsonl` . It is the ledger: every order and every status
transition, append-only, and the audit trail the tax records lean on. Back it
up:
```sh
install -d -m 0700 /var/backups/catcrafts
cp /var/lib/catcrafts/orders.jsonl \
/var/backups/catcrafts/orders-$(date -u +%F).jsonl
```
It contains names, addresses and email addresses, so it is personal data: keep
it 0600, keep it off the web root, and encrypt it before it leaves the machine.
2026-08-13 23:34:19 +02:00
(The cached shipping table is deliberately NOT worth backing up: delete it and
2026-08-17 11:36:54 +02:00
the next Sendcloud refresh rebuilds it. The financials aggregates file is a few
hundred bytes the owner's tooling rewrites — keep a copy with the ledger backup
all the same, since nothing on this box can regenerate it.)
2026-08-05 04:18:37 +02:00
The second is `/srv/catcrafts-app/media` — the mirrored post images and screen
recordings. Usually reproducible from `content/posts.json` , but **not if a source
instance has deleted the file since**, and for these posts the media * is * the
content. It lives on the app mount rather than the web root specifically so
`rsync --delete` cannot reach it, and CI only ever adds to it. Worth including in
the same backup.
## Why the backend speaks plaintext HTTP/1.1
Caddy terminates TLS and reverse-proxies to loopback. The backend uses
Crafter.Network's `ListenerHTTP1` rather than its HTTP/3 `ListenerHTTP` for one
concrete reason: **Caddy cannot `reverse_proxy` to an h3 upstream. ** Port 8081
must never be exposed directly.
deploy: the bank callback's controls are in the Caddy example
The README says a bank callback is not signed and that three controls
in Caddy "all have to stay in place": a source-IP allowlist, a path of
which only the non-secret prefix is in the web server's config, and
log_skip. Caddyfile.example had none of them. A host set up from it
proxied the callback to the backend from anyone and wrote the secret
path to the access log, which feeds the public analytics page.
The example now has the block: /hooks/bunq/* answers 403 to anything
outside the bank's range, is kept out of the log, and is proxied. It
adapts with Caddy 2.11.7 and sorts ahead of the catch-all. Both proxy
blocks carry a 64 KiB request_body cap, the same as the backend's.
catcrafts-analytics drops /hooks lines from the public tier as well, so
the public page does not rest on that one directive.
The README no longer says the backend binds loopback, because it does
not: ListenerHTTP1 takes a port and no address and binds every IPv4
interface, while the server logs 127.0.0.1 (Crafter.Network issue 11
asks for the address). The firewall on 8081 is what the per-peer limit,
the callback's allowlist and the request-size bound rest on, with the
two commands that check it.
It also documents what the earlier commits changed: the claims file
and what to do with a payment that named two orders, the rule that a
reference names one order, a payment being counted once whatever the
credits file holds, and the ledger being held in memory.
The server's copies of the Caddyfile and of the analytics script are
installed by hand and are not changed by a deploy.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-26 11:05:35 +01:00
**The backend does not enforce that itself, and its startup line is wrong
about it.** `ListenerHTTP1` takes a port and no address, and binds every IPv4
interface (`0.0.0.0` ), while the server logs `listening on 127.0.0.1` . Until
the listener can be given `127.0.0.1`
([Crafter.Network issue #11 ](https://forgejo.catcrafts.net/Catcrafts/Crafter.Network/issues/11 )),
the host firewall is the only thing keeping the port private. Three things
rest on it:
- the per-peer checkout limit, which trusts the address Caddy puts in
`X-Forwarded-For` ;
- the bank callback's source-IP allowlist, which lives in Caddy and is simply
skipped by anyone who can reach the backend directly;
- the bound on what one request can make the server hold. The backend's own
64 KiB limit is on the decoded body. A chunked request sent straight to the
port can pad its chunk framing and have one connection hold hundreds of
megabytes for 64 KiB of body (reproduced in review, 2026-11-26). Caddy's
`request_body` cap is what refuses an oversized request before it gets
there, and the parser itself is Crafter.Network's to fix.
So check it after any firewall change:
```sh
ss -ltn 'sport = :8081' # on the box: shows 0.0.0.0:8081
curl -m 5 http://<this host>:8081/api/healthz # from anywhere else: must time out
```
2026-08-05 04:18:37 +02:00
## One-time host setup
```sh
# 1. service account, no login, no home
useradd --system --no-create-home --shell /usr/sbin/nologin catcrafts
# 2. directories
mkdir -p /srv/catcrafts.net /srv/catcrafts-app
chown catcrafts:catcrafts /srv/catcrafts-app
# The web root stays writable by whatever uid the runner container uses.
# 3. units
cp deploy/catcrafts-server.service /etc/systemd/system/
cp deploy/catcrafts-deploy.service /etc/systemd/system/
cp deploy/catcrafts-deploy.path /etc/systemd/system/
systemctl daemon-reload
systemctl enable --now catcrafts-deploy.path
# catcrafts-server is started by the first deploy; enable it so it survives a
# reboot:
systemctl enable catcrafts-server
# 4. Caddy — merge deploy/Caddyfile.example into your site config
caddy validate --config /etc/caddy/Caddyfile
systemctl reload caddy
```
## Runner configuration
CI: build with the Crafter.Build Flatpak on a repo-scoped privileged runner
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>
2026-10-12 16:32:57 +02:00
The deploy job runs on a privileged runner registered to this repository alone
2026-10-17 00:22:50 +02:00
(`runs-on: catcrafts-deploy` ), not on the shared `arch-latest` runner.
crafter-build is the Crafter.Build Flatpak, and bubblewrap inside the job
container needs the privilege; imsd's package job is set up the same way. The
label is this repository's own on purpose: a job goes to whichever runner
carrying its label polls first, and imsd's `flatpak` label is also on the
organisation-wide `cx33-org-flatpak` runner (since 2026-10-14), which has no
mounts and defaults to an alpine image. Crafter.Build's run 550 (2026-10-16)
landed there and failed before building. On the box since 2026-10-12:
CI: build with the Crafter.Build Flatpak on a repo-scoped privileged runner
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>
2026-10-12 16:32:57 +02:00
* `/etc/forgejo-runner/config-catcrafts.yaml` : label
2026-10-17 00:22:50 +02:00
`catcrafts-deploy:docker://archlinux:latest` (was `flatpak` until
2026-10-17), `privileged: true` , cache proxy on port 34570. Labels live in
this file; the runner declares them at start, so a label change is an edit
plus a service restart, never a re-registration.
CI: build with the Crafter.Build Flatpak on a repo-scoped privileged runner
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>
2026-10-12 16:32:57 +02:00
* `forgejo-runner-catcrafts.service` , a copy of the imsd unit, working
directory `/var/lib/forgejo-runner-catcrafts` . Its `.runner` is the
registration: scope `Catcrafts/catcrafts.net` , name
`cx43-catcrafts-net-privileged` .
* docker volume `catcrafts-flatpak-system` , mounted at `/var/lib/flatpak` in
the job container: the installed Flatpak and its Sdk, about 4 GB, so a
deploy downloads neither. Deleting the volume only costs the next run that
download.
To register it afresh (a lost `.runner` ): as the forgejo user in
`/var/lib/forgejo` , `forgejo -c /etc/forgejo/app.ini actions
generate-runner-token --scope Catcrafts/catcrafts.net`, then as forgejo-runner
in the working directory, `forgejo-runner register --no-interactive -c
/etc/forgejo-runner/config-catcrafts.yaml --instance
https://forgejo.catcrafts.net --token <token> --name
cx43-catcrafts-net-privileged`.
Inside the crafter-build sandbox the job container's top-level directories are
visible at the same paths (`/deploy-app` , `/workspace` , `/opt` , `/root` ), but
`/tmp` is the sandbox's own: a file a step writes under `/tmp` does not exist
for a suite, and the other way round. The media mirror lives on `/deploy-app`
and cast is installed under `/opt` for that reason.
Both deploy mounts are required, in that runner's config:
2026-08-05 04:18:37 +02:00
```yaml
container:
CI: build with the Crafter.Build Flatpak on a repo-scoped privileged runner
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>
2026-10-12 16:32:57 +02:00
privileged: true
options: "--volume /var/www/catcrafts.net:/deploy --volume /srv/catcrafts-app:/deploy-app --volume catcrafts-flatpak-system:/var/lib/flatpak"
valid_volumes:
- /var/www/catcrafts.net
- /srv/catcrafts-app
- catcrafts-flatpak-*
2026-08-05 04:18:37 +02:00
```
The deploy steps fail with an explanatory message if either is missing, rather
than silently succeeding into the container's own filesystem.
## How the restart happens
CI runs **inside a container ** and has no access to the host's systemd. Rather
than give the runner host root or a polkit rule — both of which grant far more
authority than "restart one service" needs — the last deploy step writes
`/srv/catcrafts-app/.deploy-stamp` , and `catcrafts-deploy.path` on the host
reacts.
2026-08-15 00:54:05 +02:00
`catcrafts-deploy.service` runs `catcrafts-server --render /` as `ExecStartPre`
before restarting. The unit tests already gated the deploy in CI
(`crafter-build test --product=server` ); this on-host check covers what CI
CI: build with the Crafter.Build Flatpak on a repo-scoped privileged runner
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>
2026-10-12 16:32:57 +02:00
cannot — the dynamic loader finding libmsquic, libc++, libc++abi and libunwind
next to the binary on this machine and a page rendering from the deployed
content — so **a broken binary leaves the working server running ** instead of
replacing it. The binary links the Flatpak's libc++, not the host's, which is
why the deploy ships those three libraries into `/srv/catcrafts-app` alongside
libmsquic; the rpath from `project.cpp` finds them there.
2026-08-05 04:18:37 +02:00
The binary is installed as `catcrafts-server.new` and `mv` d into place, so a
request arriving mid-copy never hits a truncated executable.
## If the backend is down
2026-08-05 04:32:52 +02:00
Caddy's `handle_errors` fallback serves the static `index.html` ,
2026-08-05 04:18:37 +02:00
so the site degrades to the client-rendered wasm app rather than showing a 502.
Content still renders; what is lost is server-side rendering and real status
codes — an unknown path becomes a soft 404 again until the backend returns.
## Posts and their media
`content/posts-sources.json` holds the account and a **community allowlist ** .
Only listed communities are fetched, so joining a new one does not silently
publish it to the site — add a line first.
```sh
media: publish to our own origin instead of mirroring a file host
A 167 MB screen recording uploaded to catbox.moe hit fetch-media.sh's 64 MB
MAX_BYTES, so curl refused it, the entry kept its third-party URL, and e2e
failed "/posts media origin" on a file we had on disk the whole time. Raising
the cap would have papered over it: the mirror step still depends on someone
else's server being up, fast, and still holding the file.
Invert it. tools/publish-media.sh uploads a recording to the media mount under
its content hash BEFORE the post exists and prints the URL to post, and
fetch-media.sh adopts an own-origin URL by rewriting it to /media/<hash> with no
request at all — no size cap, no third party in the build.
Also here, because publishing exposed them:
* Rotation. Phones record 1920x1080 and attach a display matrix rather than
rotating pixels, so an untouched file reports landscape while playing
portrait and width/height reserve exactly the wrong box. publish-media.sh
bakes rotation into the frames; fetch-media.sh swaps the dimensions on a
quarter-turn matrix for anything mirrored straight from a phone.
* Posters. pict-rs will not thumbnail AV1, so a self-hosted video usually
arrives with no poster. publish-media.sh uploads <hash>.poster.webp beside
the video and fetch-media.sh falls back to it — a real thumbnail still wins.
* The workflow comment claiming a file on the mount is never downloaded again
was wrong: the name is the hash of the bytes, so third-party media is
re-fetched every build and only the write is skipped.
Transcoding to AV1 is what makes self-hosting cheap: that clip was 78 s of a
dark room at 17 Mbps, and denoise + AV1 gives the same picture in 15 MB. Note
<video> carries a single src with no fallback, so AV1 excludes Safari < 17;
--raw skips the transcode when that matters.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 01:16:17 +02:00
tools/publish-media.sh FILE # BEFORE posting: uploads to /media, prints the URL
tools/fetch-posts.sh # writes content/posts.json
tools/fetch-media.sh # mirrors the media, rewrites posts.json to /media/... paths
2026-08-05 04:18:37 +02:00
```
Order matters: the second reads what the first wrote. CI runs both before the
build. Neither fails the build on a network error — a fediverse outage leaves the
previous `posts.json` in place, and a single failed download leaves that one entry
pointing at its original URL rather than losing the post.
2026-08-10 01:37:26 +02:00
### The full body, and its inline media
Each post is hosted whole at `/posts/<slug>` , with the card on `/posts` linking
to it — the writing is what the site is about, and a page this site can name as
canonical is the only version a search engine can be pointed at. The comments
are * not * mirrored: every post page links out to the thread, which is where the
discussion belongs.
The body stays Markdown in `posts.json` and is rendered by
`Catcrafts.Shared:Markdown` at page-render time, never converted to HTML by the
shell. That is deliberate: the renderer is inside the escaping guarantee, and
text fetched from someone else's server must not be able to become markup
anywhere else. Raw HTML in a body is always shown as text.
`fetch-media.sh` mirrors what the body embeds as well as the headline file, and
rewrites the URLs **inside the Markdown ** , so a post page loads nothing
third-party either. It also writes a `body_media` list per post — dimensions,
poster frame and format renditions for each inline file, which Markdown syntax
has nowhere to carry. Slugs come from the title; a duplicate title takes the
post's numeric id as a suffix, so an old post's URL is never renumbered by a new
one. Re-running the script is a no-op: local paths are adopted from the mount
rather than re-fetched.
### The image format ladder
Every mirrored still image is transcoded to two siblings named after its content
hash, and `Catcrafts.Shared:Media` serves all three as one `<picture>` — so the
browser fetches **exactly one ** :
| tier | file | size vs. WebP | who gets it |
|---|---|---|---|
| `<source type="image/avif">` | `<hash>.avif` | **76% ** | almost everyone |
| `<source type="image/webp">` | `<hash>.webp` (the mirrored original) | 100% | Safari 14– 16 |
| `<img src>` | `<hash>.png` | **875% ** | neither of the above |
The middle tier is why the PNG being ~9× the WebP does not matter: it is free
(the mirror already downloaded that file) and it is what the small number of
non-AVIF browsers actually land on. The PNG is the floor nothing can refuse.
AVIF is encoded at `crf 26, cpu-used 6, yuv444p` — measured at SSIM 0.997
against the source and still smaller than it. Full chroma is deliberate: these
are screenshots of text, and re-subsampling chroma that pict-rs already
subsampled once fringes coloured text visibly, for about 3% more bytes.
Encoding is skipped when the sibling is already on the mount, so only genuinely
new images cost encoder time (~0.5 s each). Animated sources are left alone
entirely — one moving GIF beats three copies of its first frame. Video posters
are skipped too: `poster` takes exactly one URL, so a `<video>` cannot negotiate
a format the way `<picture>` can and the renditions would be unreachable.
Both encodes pin `-c:v` and then **verify the codec that actually came out ** .
That check earned its place immediately: `-f image2 out.png` without an explicit
codec makes ffmpeg fall back to the muxer default, which is MJPEG — it silently
produced a full set of lossy JPEGs under `.png` names, served to browsers as
`image/png` . A rendition that fails the check is discarded and its tier dropped.
media: publish to our own origin instead of mirroring a file host
A 167 MB screen recording uploaded to catbox.moe hit fetch-media.sh's 64 MB
MAX_BYTES, so curl refused it, the entry kept its third-party URL, and e2e
failed "/posts media origin" on a file we had on disk the whole time. Raising
the cap would have papered over it: the mirror step still depends on someone
else's server being up, fast, and still holding the file.
Invert it. tools/publish-media.sh uploads a recording to the media mount under
its content hash BEFORE the post exists and prints the URL to post, and
fetch-media.sh adopts an own-origin URL by rewriting it to /media/<hash> with no
request at all — no size cap, no third party in the build.
Also here, because publishing exposed them:
* Rotation. Phones record 1920x1080 and attach a display matrix rather than
rotating pixels, so an untouched file reports landscape while playing
portrait and width/height reserve exactly the wrong box. publish-media.sh
bakes rotation into the frames; fetch-media.sh swaps the dimensions on a
quarter-turn matrix for anything mirrored straight from a phone.
* Posters. pict-rs will not thumbnail AV1, so a self-hosted video usually
arrives with no poster. publish-media.sh uploads <hash>.poster.webp beside
the video and fetch-media.sh falls back to it — a real thumbnail still wins.
* The workflow comment claiming a file on the mount is never downloaded again
was wrong: the name is the hash of the bytes, so third-party media is
re-fetched every build and only the write is skipped.
Transcoding to AV1 is what makes self-hosting cheap: that clip was 78 s of a
dark room at 17 Mbps, and denoise + AV1 gives the same picture in 15 MB. Note
<video> carries a single src with no fallback, so AV1 excludes Safari < 17;
--raw skips the transcode when that matters.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 01:16:17 +02:00
### Publish the media first, then post it
**The recommended flow is to put a recording on catcrafts.net before writing the
post, and use that URL as the post's link.** Run `tools/publish-media.sh
media: H.264 fallback beside every AV1, and the post links the H.264
The AV1-only publish lasted four hours in the wild: the first viewer on
mobile Safari got "bad media error" from the raw file, because a post's
link is fetched raw — Lemmy apps and browsers play that exact URL, with
no <source> negotiation in front of it. The previous commit's note
("--raw ... if that audience matters") had it backwards: the audience
that cannot play AV1 is not a per-post judgement call, it is whoever
happens to open the thread on an iPhone.
So publish-media.sh now emits two encodings and points the post at the
compatible one:
* Every video transcode also produces <hash>.h264.mp4 (x264 crf 23,
same denoise, same frames), uploaded beside the AV1 under the AV1's
hash — the poster's sibling-naming trick, reused, so fetch-media.sh
finds it by name with nothing to look up.
* The printed URL to paste into the post is the H.264 one. pict-rs
can thumbnail it too, so instance thumbnails come back as a bonus.
fetch-media.sh adopting an own-origin .h264.mp4 URL swaps the AV1 back
in as the page's primary when it is on the mount, and records the H.264
as `fallback` in posts.json. The renderer turns a non-empty fallback
into a <source> pair: the AV1 first with an explicit codecs parameter —
both files are video/mp4, so the parameter is the only thing that lets
a non-AV1 browser skip to the file it can play — and the H.264 second.
Browsers with AV1 keep downloading the small file; Safari before 17
gets one that plays instead of an element that will not.
e2e gains the matching conditional gate: a page offering an av01
<source> must offer an .h264.mp4 one, so an AV1 video can never again
ship without its fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-08 03:14:51 +02:00
recording.mp4`; it transcodes to AV1 * and * an H.264 sibling, uploads both to the
media mount under the AV1's content hash, and prints a
`https://catcrafts.net/media/<hash>.h264.mp4` URL to paste into the post. The
H.264 one on purpose: a post's link is fetched raw — Lemmy apps and browsers play
that exact file, with no negotiation in front of it — so it must be the encoding
everything can play. (An AV1 link posted before this existed drew "bad media
error" reports from iPhones within hours.)
media: publish to our own origin instead of mirroring a file host
A 167 MB screen recording uploaded to catbox.moe hit fetch-media.sh's 64 MB
MAX_BYTES, so curl refused it, the entry kept its third-party URL, and e2e
failed "/posts media origin" on a file we had on disk the whole time. Raising
the cap would have papered over it: the mirror step still depends on someone
else's server being up, fast, and still holding the file.
Invert it. tools/publish-media.sh uploads a recording to the media mount under
its content hash BEFORE the post exists and prints the URL to post, and
fetch-media.sh adopts an own-origin URL by rewriting it to /media/<hash> with no
request at all — no size cap, no third party in the build.
Also here, because publishing exposed them:
* Rotation. Phones record 1920x1080 and attach a display matrix rather than
rotating pixels, so an untouched file reports landscape while playing
portrait and width/height reserve exactly the wrong box. publish-media.sh
bakes rotation into the frames; fetch-media.sh swaps the dimensions on a
quarter-turn matrix for anything mirrored straight from a phone.
* Posters. pict-rs will not thumbnail AV1, so a self-hosted video usually
arrives with no poster. publish-media.sh uploads <hash>.poster.webp beside
the video and fetch-media.sh falls back to it — a real thumbnail still wins.
* The workflow comment claiming a file on the mount is never downloaded again
was wrong: the name is the hash of the bytes, so third-party media is
re-fetched every build and only the write is skipped.
Transcoding to AV1 is what makes self-hosting cheap: that clip was 78 s of a
dark room at 17 Mbps, and denoise + AV1 gives the same picture in 15 MB. Note
<video> carries a single src with no fallback, so AV1 excludes Safari < 17;
--raw skips the transcode when that matters.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 01:16:17 +02:00
`fetch-media.sh` recognises its own origin and **adopts ** such a URL: it rewrites
it to `/media/<hash>` and probes the local file for dimensions, downloading
nothing. That is not just an optimisation — it removes the whole class of build
failure where the media step depends on a third party. A 167 MB recording on a
file host once hit `MAX_BYTES` (64 MB), so the entry kept its original URL, and
2026-08-15 00:54:05 +02:00
the deploy then failed the "media origin" check (ShouldServePostPages) on a file that was sitting on
media: publish to our own origin instead of mirroring a file host
A 167 MB screen recording uploaded to catbox.moe hit fetch-media.sh's 64 MB
MAX_BYTES, so curl refused it, the entry kept its third-party URL, and e2e
failed "/posts media origin" on a file we had on disk the whole time. Raising
the cap would have papered over it: the mirror step still depends on someone
else's server being up, fast, and still holding the file.
Invert it. tools/publish-media.sh uploads a recording to the media mount under
its content hash BEFORE the post exists and prints the URL to post, and
fetch-media.sh adopts an own-origin URL by rewriting it to /media/<hash> with no
request at all — no size cap, no third party in the build.
Also here, because publishing exposed them:
* Rotation. Phones record 1920x1080 and attach a display matrix rather than
rotating pixels, so an untouched file reports landscape while playing
portrait and width/height reserve exactly the wrong box. publish-media.sh
bakes rotation into the frames; fetch-media.sh swaps the dimensions on a
quarter-turn matrix for anything mirrored straight from a phone.
* Posters. pict-rs will not thumbnail AV1, so a self-hosted video usually
arrives with no poster. publish-media.sh uploads <hash>.poster.webp beside
the video and fetch-media.sh falls back to it — a real thumbnail still wins.
* The workflow comment claiming a file on the mount is never downloaded again
was wrong: the name is the hash of the bytes, so third-party media is
re-fetched every build and only the write is skipped.
Transcoding to AV1 is what makes self-hosting cheap: that clip was 78 s of a
dark room at 17 Mbps, and denoise + AV1 gives the same picture in 15 MB. Note
<video> carries a single src with no fallback, so AV1 excludes Safari < 17;
--raw skips the transcode when that matters.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 01:16:17 +02:00
our own disk the entire time.
media: H.264 fallback beside every AV1, and the post links the H.264
The AV1-only publish lasted four hours in the wild: the first viewer on
mobile Safari got "bad media error" from the raw file, because a post's
link is fetched raw — Lemmy apps and browsers play that exact URL, with
no <source> negotiation in front of it. The previous commit's note
("--raw ... if that audience matters") had it backwards: the audience
that cannot play AV1 is not a per-post judgement call, it is whoever
happens to open the thread on an iPhone.
So publish-media.sh now emits two encodings and points the post at the
compatible one:
* Every video transcode also produces <hash>.h264.mp4 (x264 crf 23,
same denoise, same frames), uploaded beside the AV1 under the AV1's
hash — the poster's sibling-naming trick, reused, so fetch-media.sh
finds it by name with nothing to look up.
* The printed URL to paste into the post is the H.264 one. pict-rs
can thumbnail it too, so instance thumbnails come back as a bonus.
fetch-media.sh adopting an own-origin .h264.mp4 URL swaps the AV1 back
in as the page's primary when it is on the mount, and records the H.264
as `fallback` in posts.json. The renderer turns a non-empty fallback
into a <source> pair: the AV1 first with an explicit codecs parameter —
both files are video/mp4, so the parameter is the only thing that lets
a non-AV1 browser skip to the file it can play — and the H.264 second.
Browsers with AV1 keep downloading the small file; Safari before 17
gets one that plays instead of an element that will not.
e2e gains the matching conditional gate: a page offering an av01
<source> must offer an .h264.mp4 one, so an AV1 video can never again
ship without its fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-08 03:14:51 +02:00
Adopting a `<hash>.h264.mp4` URL swaps the AV1 sibling back in as the page's
primary `<source>` when it is on the mount, keeping the H.264 as the fallback
`<source>` . So the post links the compatible file, while browsers that can take
AV1 download the small one — the `codecs` parameter on the first source is what
lets the rest skip it.
media: publish to our own origin instead of mirroring a file host
A 167 MB screen recording uploaded to catbox.moe hit fetch-media.sh's 64 MB
MAX_BYTES, so curl refused it, the entry kept its third-party URL, and e2e
failed "/posts media origin" on a file we had on disk the whole time. Raising
the cap would have papered over it: the mirror step still depends on someone
else's server being up, fast, and still holding the file.
Invert it. tools/publish-media.sh uploads a recording to the media mount under
its content hash BEFORE the post exists and prints the URL to post, and
fetch-media.sh adopts an own-origin URL by rewriting it to /media/<hash> with no
request at all — no size cap, no third party in the build.
Also here, because publishing exposed them:
* Rotation. Phones record 1920x1080 and attach a display matrix rather than
rotating pixels, so an untouched file reports landscape while playing
portrait and width/height reserve exactly the wrong box. publish-media.sh
bakes rotation into the frames; fetch-media.sh swaps the dimensions on a
quarter-turn matrix for anything mirrored straight from a phone.
* Posters. pict-rs will not thumbnail AV1, so a self-hosted video usually
arrives with no poster. publish-media.sh uploads <hash>.poster.webp beside
the video and fetch-media.sh falls back to it — a real thumbnail still wins.
* The workflow comment claiming a file on the mount is never downloaded again
was wrong: the name is the hash of the bytes, so third-party media is
re-fetched every build and only the write is skipped.
Transcoding to AV1 is what makes self-hosting cheap: that clip was 78 s of a
dark room at 17 Mbps, and denoise + AV1 gives the same picture in 15 MB. Note
<video> carries a single src with no fallback, so AV1 excludes Safari < 17;
--raw skips the transcode when that matters.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 01:16:17 +02:00
The transcode matters as much as the hosting. Phone recordings are wildly
oversized for what they show — that same 167 MB clip was 78 s of a dark room at
17 Mbps, and denoising into AV1 gives the same picture in 15 MB. It also **bakes
in the rotation**: phones record landscape and attach a display matrix, so an
untouched file reports 1920x1080 while playing portrait, and the `width` /`height`
attributes then reserve exactly the wrong box. (`fetch-media.sh` swaps the
dimensions when it sees a quarter-turn matrix, so a straight-from-phone mirror is
correct too — but transcoding means nothing downstream has to know.)
Two things to know about publishing AV1:
media: H.264 fallback beside every AV1, and the post links the H.264
The AV1-only publish lasted four hours in the wild: the first viewer on
mobile Safari got "bad media error" from the raw file, because a post's
link is fetched raw — Lemmy apps and browsers play that exact URL, with
no <source> negotiation in front of it. The previous commit's note
("--raw ... if that audience matters") had it backwards: the audience
that cannot play AV1 is not a per-post judgement call, it is whoever
happens to open the thread on an iPhone.
So publish-media.sh now emits two encodings and points the post at the
compatible one:
* Every video transcode also produces <hash>.h264.mp4 (x264 crf 23,
same denoise, same frames), uploaded beside the AV1 under the AV1's
hash — the poster's sibling-naming trick, reused, so fetch-media.sh
finds it by name with nothing to look up.
* The printed URL to paste into the post is the H.264 one. pict-rs
can thumbnail it too, so instance thumbnails come back as a bonus.
fetch-media.sh adopting an own-origin .h264.mp4 URL swaps the AV1 back
in as the page's primary when it is on the mount, and records the H.264
as `fallback` in posts.json. The renderer turns a non-empty fallback
into a <source> pair: the AV1 first with an explicit codecs parameter —
both files are video/mp4, so the parameter is the only thing that lets
a non-AV1 browser skip to the file it can play — and the H.264 second.
Browsers with AV1 keep downloading the small file; Safari before 17
gets one that plays instead of an element that will not.
e2e gains the matching conditional gate: a page offering an av01
<source> must offer an .h264.mp4 one, so an AV1 video can never again
ship without its fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-08 03:14:51 +02:00
* Browsers without AV1 (Safari before 17, Apple hardware older than A17/M3) get
the `<hash>.h264.mp4` sibling: on the site via the second `<source>` , on the
fediverse because that sibling * is * the posted URL. `--raw` skips the
transcode and the fallback both, so a raw AV1 upload recreates the
will-not-play problem — use it for files that are already universally
playable.
media: publish to our own origin instead of mirroring a file host
A 167 MB screen recording uploaded to catbox.moe hit fetch-media.sh's 64 MB
MAX_BYTES, so curl refused it, the entry kept its third-party URL, and e2e
failed "/posts media origin" on a file we had on disk the whole time. Raising
the cap would have papered over it: the mirror step still depends on someone
else's server being up, fast, and still holding the file.
Invert it. tools/publish-media.sh uploads a recording to the media mount under
its content hash BEFORE the post exists and prints the URL to post, and
fetch-media.sh adopts an own-origin URL by rewriting it to /media/<hash> with no
request at all — no size cap, no third party in the build.
Also here, because publishing exposed them:
* Rotation. Phones record 1920x1080 and attach a display matrix rather than
rotating pixels, so an untouched file reports landscape while playing
portrait and width/height reserve exactly the wrong box. publish-media.sh
bakes rotation into the frames; fetch-media.sh swaps the dimensions on a
quarter-turn matrix for anything mirrored straight from a phone.
* Posters. pict-rs will not thumbnail AV1, so a self-hosted video usually
arrives with no poster. publish-media.sh uploads <hash>.poster.webp beside
the video and fetch-media.sh falls back to it — a real thumbnail still wins.
* The workflow comment claiming a file on the mount is never downloaded again
was wrong: the name is the hash of the bytes, so third-party media is
re-fetched every build and only the write is skipped.
Transcoding to AV1 is what makes self-hosting cheap: that clip was 78 s of a
dark room at 17 Mbps, and denoise + AV1 gives the same picture in 15 MB. Note
<video> carries a single src with no fallback, so AV1 excludes Safari < 17;
--raw skips the transcode when that matters.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 01:16:17 +02:00
* Lemmy's `pict-rs` will not generate a thumbnail from an AV1 file, so a
self-hosted video usually arrives with no `poster` . `publish-media.sh` uploads
a poster frame beside the video, named `<video-hash>.poster.webp` , and
`fetch-media.sh` falls back to that sibling when the instance supplied nothing.
media: H.264 fallback beside every AV1, and the post links the H.264
The AV1-only publish lasted four hours in the wild: the first viewer on
mobile Safari got "bad media error" from the raw file, because a post's
link is fetched raw — Lemmy apps and browsers play that exact URL, with
no <source> negotiation in front of it. The previous commit's note
("--raw ... if that audience matters") had it backwards: the audience
that cannot play AV1 is not a per-post judgement call, it is whoever
happens to open the thread on an iPhone.
So publish-media.sh now emits two encodings and points the post at the
compatible one:
* Every video transcode also produces <hash>.h264.mp4 (x264 crf 23,
same denoise, same frames), uploaded beside the AV1 under the AV1's
hash — the poster's sibling-naming trick, reused, so fetch-media.sh
finds it by name with nothing to look up.
* The printed URL to paste into the post is the H.264 one. pict-rs
can thumbnail it too, so instance thumbnails come back as a bonus.
fetch-media.sh adopting an own-origin .h264.mp4 URL swaps the AV1 back
in as the page's primary when it is on the mount, and records the H.264
as `fallback` in posts.json. The renderer turns a non-empty fallback
into a <source> pair: the AV1 first with an explicit codecs parameter —
both files are video/mp4, so the parameter is the only thing that lets
a non-AV1 browser skip to the file it can play — and the H.264 second.
Browsers with AV1 keep downloading the small file; Safari before 17
gets one that plays instead of an element that will not.
e2e gains the matching conditional gate: a page offering an av01
<source> must offer an .h264.mp4 one, so an AV1 video can never again
ship without its fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-08 03:14:51 +02:00
A thumbnail the instance * did * provide always wins. (Posting the H.264 URL
also means pict-rs can thumbnail it again, so instance thumbnails come back.)
media: publish to our own origin instead of mirroring a file host
A 167 MB screen recording uploaded to catbox.moe hit fetch-media.sh's 64 MB
MAX_BYTES, so curl refused it, the entry kept its third-party URL, and e2e
failed "/posts media origin" on a file we had on disk the whole time. Raising
the cap would have papered over it: the mirror step still depends on someone
else's server being up, fast, and still holding the file.
Invert it. tools/publish-media.sh uploads a recording to the media mount under
its content hash BEFORE the post exists and prints the URL to post, and
fetch-media.sh adopts an own-origin URL by rewriting it to /media/<hash> with no
request at all — no size cap, no third party in the build.
Also here, because publishing exposed them:
* Rotation. Phones record 1920x1080 and attach a display matrix rather than
rotating pixels, so an untouched file reports landscape while playing
portrait and width/height reserve exactly the wrong box. publish-media.sh
bakes rotation into the frames; fetch-media.sh swaps the dimensions on a
quarter-turn matrix for anything mirrored straight from a phone.
* Posters. pict-rs will not thumbnail AV1, so a self-hosted video usually
arrives with no poster. publish-media.sh uploads <hash>.poster.webp beside
the video and fetch-media.sh falls back to it — a real thumbnail still wins.
* The workflow comment claiming a file on the mount is never downloaded again
was wrong: the name is the hash of the bytes, so third-party media is
re-fetched every build and only the write is skipped.
Transcoding to AV1 is what makes self-hosting cheap: that clip was 78 s of a
dark room at 17 Mbps, and denoise + AV1 gives the same picture in 15 MB. Note
<video> carries a single src with no fallback, so AV1 excludes Safari < 17;
--raw skips the transcode when that matters.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 01:16:17 +02:00
An own-origin URL naming a file that is **not ** on the mount is deliberately left
pointing at its original URL rather than rewritten. That is a post published
2026-08-15 00:54:05 +02:00
without its media, and failing the origin check (ShouldServePostPages) loudly beats shipping a 404
media: publish to our own origin instead of mirroring a file host
A 167 MB screen recording uploaded to catbox.moe hit fetch-media.sh's 64 MB
MAX_BYTES, so curl refused it, the entry kept its third-party URL, and e2e
failed "/posts media origin" on a file we had on disk the whole time. Raising
the cap would have papered over it: the mirror step still depends on someone
else's server being up, fast, and still holding the file.
Invert it. tools/publish-media.sh uploads a recording to the media mount under
its content hash BEFORE the post exists and prints the URL to post, and
fetch-media.sh adopts an own-origin URL by rewriting it to /media/<hash> with no
request at all — no size cap, no third party in the build.
Also here, because publishing exposed them:
* Rotation. Phones record 1920x1080 and attach a display matrix rather than
rotating pixels, so an untouched file reports landscape while playing
portrait and width/height reserve exactly the wrong box. publish-media.sh
bakes rotation into the frames; fetch-media.sh swaps the dimensions on a
quarter-turn matrix for anything mirrored straight from a phone.
* Posters. pict-rs will not thumbnail AV1, so a self-hosted video usually
arrives with no poster. publish-media.sh uploads <hash>.poster.webp beside
the video and fetch-media.sh falls back to it — a real thumbnail still wins.
* The workflow comment claiming a file on the mount is never downloaded again
was wrong: the name is the hash of the bytes, so third-party media is
re-fetched every build and only the write is skipped.
Transcoding to AV1 is what makes self-hosting cheap: that clip was 78 s of a
dark room at 17 Mbps, and denoise + AV1 gives the same picture in 15 MB. Note
<video> carries a single src with no fallback, so AV1 excludes Safari < 17;
--raw skips the transcode when that matters.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 01:16:17 +02:00
inside a `<video>` tag.
2026-08-05 04:18:37 +02:00
**`fetch-media.sh` wants `ffprobe` ** (Arch: `ffmpeg` ) to read pixel dimensions,
which become the `width` /`height` attributes that stop the page reflowing as
several 5 MB recordings arrive. It degrades to no dimensions without it —
2026-08-15 00:54:05 +02:00
so the ShouldServePostPages suite asserts they are present, and a build host
missing the package fails at the test gate instead of quietly shipping a janky
page.
2026-08-05 04:18:37 +02:00
**Only the post's main media is used.** Lemmy distinguishes the media a post * is *
(`post.url` , with `post.thumbnail_url` as its generated still) from images merely
embedded in the body. Only the former is mirrored — a post whose pictures are
body-only renders as text, which is correct. Videos get the thumbnail as their
`poster` ; without it a `preload="metadata"` video is a black box until someone
presses play.
**Thread links point at the community's instance, not the author's.** A post's
`ap_id` is on the account's own instance, but the discussion is in the community,
which is federated elsewhere and has its own local id for the same thread. So
`fetch-posts.sh` resolves each `ap_id` through the community instance's
`resolve_object` and stores that URL. One request per post, at build time; a
failure falls back to the `ap_id` , which still reaches a readable copy.
Media is **mirrored, not hotlinked ** . Three reasons: the privacy notice says
everything the browser loads comes from catcrafts.net and should stay true;
hotlinking would send every visitor's IP to the source instance; and these posts
are their media, so a deleted upstream file would gut the page. Filenames are the
content hash, which is why the cache lifetime can be a year.
2026-08-20 20:15:47 +02:00
## Payments: bank transfer and EURC
2026-08-05 04:18:37 +02:00
2026-08-13 23:34:19 +02:00
Checkout offers the buyer **two choices ** , each served by its own rail:
| Choice | Rail | Env var | What the buyer gets |
|----------|----------|---------------------|-----------------------------------------|
2026-08-20 20:15:47 +02:00
| `bank` | transfer | `TRANSFER_IBAN` | a plain SEPA transfer to our own account |
2026-08-15 00:54:05 +02:00
| `crypto` | EURC | `EURC_CHAINS` | self-hosted EURC on the configured EVM chains |
2026-08-13 23:34:19 +02:00
2026-08-20 20:15:47 +02:00
**Both rails are self-hosted, and that is deliberate rather than
incidental.** On 2026-08-20 the shop's hosted payment provider closed its
account after a risk review, with no appeal and no reason given beyond
"outside our acceptance criteria". Every payment method the shop offered
through that provider died in one email. The rails above cannot be switched
off by a third party: one is a transfer to our own bank account, the other is
an address we generated ourselves. The hosted rail's implementation has been
removed from the tree — the decision was final, and a dead integration costs a
CI gate, a secret, and confusion about which rail is actually serving.
What this costs, stated honestly so nobody re-litigates it from memory: there
is no iDEAL and there are no cards. iDEAL requires an acquiring contract with
a bank (or a PSP), which is the same kind of relationship that just ended, and
cards additionally require PCI DSS SAQ D plus an EMVCo-certified 3DS server.
In the last measured week before the change, cards and Bancontact were 40% of
donation value, so this is a real loss of reach and not a free win.
2026-08-15 00:54:05 +02:00
The slots are independent. Set one and the form offers only that method;
2026-08-13 23:34:19 +02:00
set both and the buyer picks; set neither and checkout answers 503 with an
honest message — the whole site still works, degraded rather than down. A
2026-08-20 20:15:47 +02:00
mode whose configuration is missing is a **startup refusal ** , not a silent
2026-08-15 00:54:05 +02:00
downgrade: a checkout that 502s at the last step is worse than one that
never offered.
2026-08-20 20:15:47 +02:00
### The bank-transfer rail
No processor and no credential: the buyer sends a normal SEPA transfer to our
IBAN quoting the order's reference, and the server settles the order when a
matching credit appears on the account. The order page is the payment page.
- `TRANSFER_IBAN=NL..` — the account the money lands in. Setting this IS
selecting the rail, the same convention as `EURC_CHAINS` .
- `TRANSFER_BENEFICIARY='J. van der Graaf'` — **the account-holder name
exactly as the bank holds it, character for character.** Not the trading
name. Since 2025-10-09 every euro-area transfer is name-checked against the
IBAN by Verification of Payee, and the payer sees a mismatch warning at the
moment of paying; a friendly-looking "Catcrafts" here would scare buyers off
at the last step. Startup refuses without it, because an order page missing
this loses the money rather than the sale.
- `TRANSFER_BIC` — optional. Shown on the order page only when set, and
labelled "only if your bank asks for it, usually outside Europe". Inside SEPA
an IBAN alone has been sufficient since 2016, so an unconditional BIC row is
just one more field for a Dutch buyer to fill in and mistype; a payer sending
by SWIFT from outside SEPA genuinely cannot proceed without it.
- `TRANSFER_WINDOW_HOURS` (default 336, i.e. 14 days) — how long an order
waits before it lapses. Generous on purpose: a non-instant transfer from
outside the euro area can legitimately take a business day, and there is no
provider-side expiry forcing our hand. A lapsed order is **not ** bounced
money: the IBAN stays ours, a late payment still arrives, and it is settled
with `--mark-paid` . The server logs exactly this when it lapses one.
- `TRANSFER_CREDITS` (default `<orders>.transfer-credits.jsonl` ) — where the
rail reads incoming credits from. One JSON object per line:
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
`{"id":"…","reference":"…","amount_minor":2500,"method":"sepa"}` . In place of
`method` a line may carry the bank's own word for the payment and the bank
it is of (`"bank":"bunq","kind":"EBA_SCT/SCT"` ), which the server puts into
the `via` words itself: that is what the hourly pull ships. A missing file
is an empty list, not an error, since a shop that has taken no transfers yet
has no file.
2026-08-20 20:15:47 +02:00
bank: the hourly pull asks nostrod, and holds no bunq key
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>
2026-11-25 14:21:48 +01:00
#### Filling the credits file
2026-08-20 20:15:47 +02:00
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
Two things write it, and neither puts a bank key on the web host: the bank's
callback, which the server receives itself, and an hourly pull on a trusted
bank: the hourly pull asks nostrod, and holds no bunq key
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>
2026-11-25 14:21:48 +01:00
machine, which asks nostrod and ships the result. The next section has both.
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
Every line carries the bank's own id for the payment. The callback skips an id
the file already holds, and the pull replaces the file with one line per
deploy: the bank callback's controls are in the Caddy example
The README says a bank callback is not signed and that three controls
in Caddy "all have to stay in place": a source-IP allowlist, a path of
which only the non-secret prefix is in the web server's config, and
log_skip. Caddyfile.example had none of them. A host set up from it
proxied the callback to the backend from anyone and wrote the secret
path to the access log, which feeds the public analytics page.
The example now has the block: /hooks/bunq/* answers 403 to anything
outside the bank's range, is kept out of the log, and is proxied. It
adapts with Caddy 2.11.7 and sorts ahead of the catch-all. Both proxy
blocks carry a 64 KiB request_body cap, the same as the backend's.
catcrafts-analytics drops /hooks lines from the public tier as well, so
the public page does not rest on that one directive.
The README no longer says the backend binds loopback, because it does
not: ListenerHTTP1 takes a port and no address and binds every IPv4
interface, while the server logs 127.0.0.1 (Crafter.Network issue 11
asks for the address). The firewall on 8081 is what the per-peer limit,
the callback's allowlist and the request-size bound rest on, with the
two commands that check it.
It also documents what the earlier commits changed: the claims file
and what to do with a payment that named two orders, the rule that a
reference names one order, a payment being counted once whatever the
credits file holds, and the ledger being held in memory.
The server's copies of the Caddyfile and of the analytics script are
installed by hand and are not changed by a deploy.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-26 11:05:35 +01:00
payment, so a payment that both deliver is meant to be in the file once. The
rail does not depend on that: it counts an id once however many lines carry
it, because two lines can still happen (a callback landing while the pull is
replacing the file, an address registered twice at the bank), and summed they
would settle an order on half its price. When it sees a duplicate it says so
in the journal, once per order:
```
transfer: CC-… is quoted by a payment the credits file lists 1 time(s) too many. …
```
Seen regularly, that means the callback address is registered more than once:
`nostro callbacks --connector NAME` lists what is, and there should be one.
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
The server knows no bank. What a bank posts is read by `ReadCallback` , and how
a payment arrived is said by `PaymentMethodOf` , both of the module
`Nostro.Money` of [Nostro ](https://forgejo.catcrafts.net/Catcrafts/Nostro ),
which `project.cpp` builds in at the commit of a Nostro release. That module
holds no credential. Which bank it is is configuration, in two places:
`--banks=` in `project.cpp` , for what the build can read, and
`BANK_CALLBACK_BANK` on the server, for what arrives.
2026-08-20 20:15:47 +02:00
2026-08-21 04:52:25 +02:00
#### How settlement actually reaches the shop
Two paths, and the split is deliberate.
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
**Primary: the bank's callback.** The bank posts a notification when money
lands; the backend has the payment read, appends it to the credits file, and
the reconciler settles from there. Normally seconds end to end. In
`payments.env` :
- `BANK_CALLBACK_PATH=/hooks/bunq/<long random>` : the secret address the bank
posts to. Unset means the endpoint does not exist.
- `BANK_CALLBACK_BANK=bunq` : whose callbacks arrive there, as a Nostro
connector names the bank. Without it the endpoint stays off, and the startup
log says so: an endpoint that answered the bank and credited nothing would
look like working.
- `TRANSFER_IBAN` , above, is also the account a payment has to be on.
The startup log confirms it with `bank callback: enabled on a secret path` .
Where the bank posts is registered at the bank, with Nostro (1.1.0 or later),
on the machine where nostrod holds the connection:
```sh
nostro callbacks --connector NAME # what is registered, each address whole
nostro callbacks add --connector NAME # asks for the https address at a prompt
nostro callbacks remove --connector NAME # asks for the address, as listed
```
Each asks for your password, the listing too: the address is a secret. The
listing shows what is registered whoever set it. The registration in place on
2026-11-25 was made with a script this repo carried until then, and
`nostro callbacks` had not been run against it yet.
**A callback is not signed.** bunq's are not: verified against doc.bunq.com,
there is no HMAC and no server signature, and certificate pinning
authenticates us to bunq rather than bunq to us. So the endpoint's
deploy: the bank callback's controls are in the Caddy example
The README says a bank callback is not signed and that three controls
in Caddy "all have to stay in place": a source-IP allowlist, a path of
which only the non-secret prefix is in the web server's config, and
log_skip. Caddyfile.example had none of them. A host set up from it
proxied the callback to the backend from anyone and wrote the secret
path to the access log, which feeds the public analytics page.
The example now has the block: /hooks/bunq/* answers 403 to anything
outside the bank's range, is kept out of the log, and is proxied. It
adapts with Caddy 2.11.7 and sorts ahead of the catch-all. Both proxy
blocks carry a 64 KiB request_body cap, the same as the backend's.
catcrafts-analytics drops /hooks lines from the public tier as well, so
the public page does not rest on that one directive.
The README no longer says the backend binds loopback, because it does
not: ListenerHTTP1 takes a port and no address and binds every IPv4
interface, while the server logs 127.0.0.1 (Crafter.Network issue 11
asks for the address). The firewall on 8081 is what the per-peer limit,
the callback's allowlist and the request-size bound rest on, with the
two commands that check it.
It also documents what the earlier commits changed: the claims file
and what to do with a payment that named two orders, the rule that a
reference names one order, a payment being counted once whatever the
credits file holds, and the ledger being held in memory.
The server's copies of the Caddyfile and of the analytics script are
installed by hand and are not changed by a deploy.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-26 11:05:35 +01:00
authentication is the controls around it, all of which have to stay in place.
The first three are one block of `deploy/Caddyfile.example` , "the bank's
callback": merge it with the rest of that file. A Caddyfile without it still
proxies the callback to the backend, from anyone, and logs the secret path.
2026-08-21 04:52:25 +02:00
1. **Source-IP allowlist ** for `185.40.108.0/22` in the Caddyfile. This is the
strong one: forging requires completing a TLS handshake from inside that
range. bunq warns the range may change; if it does, callbacks 403 and
deploy: the bank callback's controls are in the Caddy example
The README says a bank callback is not signed and that three controls
in Caddy "all have to stay in place": a source-IP allowlist, a path of
which only the non-secret prefix is in the web server's config, and
log_skip. Caddyfile.example had none of them. A host set up from it
proxied the callback to the backend from anyone and wrote the secret
path to the access log, which feeds the public analytics page.
The example now has the block: /hooks/bunq/* answers 403 to anything
outside the bank's range, is kept out of the log, and is proxied. It
adapts with Caddy 2.11.7 and sorts ahead of the catch-all. Both proxy
blocks carry a 64 KiB request_body cap, the same as the backend's.
catcrafts-analytics drops /hooks lines from the public tier as well, so
the public page does not rest on that one directive.
The README no longer says the backend binds loopback, because it does
not: ListenerHTTP1 takes a port and no address and binds every IPv4
interface, while the server logs 127.0.0.1 (Crafter.Network issue 11
asks for the address). The firewall on 8081 is what the per-peer limit,
the callback's allowlist and the request-size bound rest on, with the
two commands that check it.
It also documents what the earlier commits changed: the claims file
and what to do with a payment that named two orders, the rule that a
reference names one order, a payment being counted once whatever the
credits file holds, and the ledger being held in memory.
The server's copies of the Caddyfile and of the analytics script are
installed by hand and are not changed by a deploy.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-26 11:05:35 +01:00
settlement stops — it fails closed. It is only as strong as Caddy being
the one way in: a request that reaches port 8081 directly never meets this
rule, and the backend's listener does not bind loopback on its own (see
"Why the backend speaks plaintext HTTP/1.1"), so the firewall on that port
is part of this control.
2026-08-21 04:52:25 +02:00
2. **A secret path. ** Caddy matches only the non-secret prefix `/hooks/bunq/*` ,
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
so the secret lives solely in `BANK_CALLBACK_PATH` in `payments.env` and not
2026-08-21 04:52:25 +02:00
in the web server config. The backend compares it in constant time, and a
non-POST to it falls through to an ordinary 404 rather than a distinctive
405 — a different answer there would confirm a guessed path.
3. * * `log_skip` on that prefix.** Without it the secret would be written to the
access log and then ingested into the GoAccess database and shown in its
deploy: the bank callback's controls are in the Caddy example
The README says a bank callback is not signed and that three controls
in Caddy "all have to stay in place": a source-IP allowlist, a path of
which only the non-secret prefix is in the web server's config, and
log_skip. Caddyfile.example had none of them. A host set up from it
proxied the callback to the backend from anyone and wrote the secret
path to the access log, which feeds the public analytics page.
The example now has the block: /hooks/bunq/* answers 403 to anything
outside the bank's range, is kept out of the log, and is proxied. It
adapts with Caddy 2.11.7 and sorts ahead of the catch-all. Both proxy
blocks carry a 64 KiB request_body cap, the same as the backend's.
catcrafts-analytics drops /hooks lines from the public tier as well, so
the public page does not rest on that one directive.
The README no longer says the backend binds loopback, because it does
not: ListenerHTTP1 takes a port and no address and binds every IPv4
interface, while the server logs 127.0.0.1 (Crafter.Network issue 11
asks for the address). The firewall on 8081 is what the per-peer limit,
the callback's allowlist and the request-size bound rest on, with the
two commands that check it.
It also documents what the earlier commits changed: the claims file
and what to do with a payment that named two orders, the rule that a
reference names one order, a payment being counted once whatever the
credits file holds, and the ledger being held in memory.
The server's copies of the Caddyfile and of the analytics script are
installed by hand and are not changed by a deploy.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-26 11:05:35 +01:00
top-URLs panel, i.e. leaked to anyone who opens `/analytics/` . The
analytics script drops `/hooks` lines from the public tier as well
(`CENSOR_RE` ), so the public page does not rest on this one directive; the
raw log and the private tier do, which is why it stays. If it was ever
missing while callbacks arrived, the path is in the retained logs: set a
new `BANK_CALLBACK_PATH` , register it with `nostro callbacks` , and rebuild
the public analytics DB (the procedure is at the top of the script).
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
4. **The account. ** A bank posts to whatever address any of its customers
registered. Someone with an account at bunq could register this address for
an account of their own and pay themselves, and the callback that follows
would be bunq's own, from bunq's range. So only a payment on
`TRANSFER_IBAN` is credited.
The handler deliberately does the least it can: have one payment read, append
it, answer 200. It makes no settlement decision, so a forged callback can at
worst manufacture a credit line — it cannot bypass the reference match or the
covering-amount rule, and nothing ships without a human either way. And a
credit line that never was a payment is gone at the next pull, which replaces
the file with what the bank says is on the account.
Every callback leaves one line in the journal, with nothing of the payer in it:
```
bank callback: credited 25.00 via sepa (id …)
bank callback: nothing credited: the payment was credited before, or …
bank callback: nothing credited: the payment is not money coming in
bank callback: nothing credited: the payment is on another account than the shop's
bank callback: nothing credited: the body was refused: <the reader's sentence>
```
2026-08-21 04:52:25 +02:00
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
`the body was refused` where a payment was expected is the line to act on: the
bank sent a shape Nostro's reader does not take. The pull still settles that
payment, the sentence names the check that failed, and the fix is Nostro's.
**How a payment arrived** is the ledger's `via` : `sepa` (a credit transfer),
`ideal` , `card` , `directdebit` , `swift` , and `internal` for a payment from
another account at the bank itself. A kind the table has no word for is not
guessed at and shows as the bank's own word: `ADYEN` is a bunq.me payment link,
which either a card or iDEAL may have paid. That column is what tells you
whether an order is safe to ship: a credit transfer is final, a card payment
can be reversed for months. Orders settled before 2026-11-25 say `bunq` where
newer ones say `internal` , and would have said `MASTERCARD` for `card` .
**Backstop: the hourly pull.** Not optional. A bank retries a callback a few
times (bunq: five, a minute apart) and then drops it permanently, so a payment
arriving while the backend restarts — every deploy is a restart — is lost to
the callback with no error anywhere. `deploy/catcrafts-credits.timer` runs
`pull-and-ship-credits.sh` hourly to turn that from a missing donation into an
hour of delay. It is also the one path that asks the bank with the bank's own
authentication.
**The pull holds no key.** A key that can read a bank account can as a rule
also pay from it (a bunq API key can, and bunq offers no read-only scope), so
the pull holds none. The bank connection lives in
[nostrod ](https://forgejo.catcrafts.net/Catcrafts/Nostro ) on a trusted machine,
under a system user of its own, and * * `tools/pull-and-ship-credits.sh` ** asks it
over the system bus for the account's recent transactions (`Transactions` on
`net.catcrafts.Nostro1` , the interface Nostro publishes for other programs).
nostrod lets a program look without a password and lets nothing pay or change
anything without one, which is the read-only scope the bank lacks. A systemd
USER timer runs the script (`deploy/catcrafts-credits.{service,timer}` , install
instructions in the service file).
bank: the hourly pull asks nostrod, and holds no bunq key
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>
2026-11-25 14:21:48 +01:00
The script turns nostrod's answer into credit lines and ships **incoming
credits only** to the file the rail reads. Outgoing lines are supplier payments
and card spending: the matcher ignores negative amounts, so shipping them would
put the business's outgoing payment history on a public-facing host for no
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
settlement benefit. A line carries the payment's kind as the bank wrote it and
the bank's name as nostrod has it, and the server puts that into the `via`
words above, so the script knows no bank either. It ships nothing when the read
failed, and it never overwrites the remote with an empty file, so a failure
leaves the server settling from the last good copy rather than from nothing.
2026-08-20 23:33:50 +02:00
bank: the hourly pull asks nostrod, and holds no bunq key
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>
2026-11-25 14:21:48 +01:00
Each run ships the last 90 days (`CREDITS_DAYS` ). That is the longest
`TRANSFER_WINDOW_HOURS` the server accepts, so no order can still be waiting
for an older credit. nostrod keeps the account's whole history and answers for
any window, so a machine that was off for weeks leaves no hole in what it
ships.
Setting it up, once, on that machine: install Nostro (its README), connect the
account with `nostro connectors add bunq` , and check that `nostro accounts`
lists the IBAN in `TRANSFER_IBAN` . `tools/pull-and-ship-credits.sh --dry-run`
then prints the lines it would ship, and ships nothing.
**Who may look.** As nostrod ships, a program may look without a password only
in an active local session: while you are logged in at that machine. A user
timer counts as part of that session, so the pull works while you are logged
in, and is refused with nobody logged in or over SSH (the script says so when
it happens). To let it run regardless, an administrator adds a polkit rule:
```js
// /etc/polkit-1/rules.d/50-catcrafts-credits.rules
polkit.addRule(function(action, subject) {
if (action.id == "net.catcrafts.Nostro1.View" && subject.user == "YOUR_USER") {
return polkit.Result.YES;
}
});
```
That lets every program running as that user look at the accounts, session or
not, and polkit cannot tell this script from any other of them. It lets none of
them pay: paying and changing stay behind the password. With the rule in place,
`loginctl enable-linger` makes the timer run with nobody logged in at all.
**Why the server does not read the bank itself.** Besides the key policy above,
a standard bunq API key works only from the address it was registered at, and
**bunq enforces that on every request, not only at device registration**.
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
Verified the hard way on 2026-08-20, with the reader this repo had then:
registering the server's address in the device's `permitted_ips` did not help
(the device registered fine from home with both addresses listed), and every
read from the server still came back `"Incorrect API key or IP address"` .
bank: the hourly pull asks nostrod, and holds no bunq key
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>
2026-11-25 14:21:48 +01:00
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
Latency, so nobody wonders: through the callback a fresh order confirms within
the reconciler's own 60 s cadence of the money landing. A payment the callback
bank: the hourly pull asks nostrod, and holds no bunq key
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>
2026-11-25 14:21:48 +01:00
lost waits for the next hourly pull on top of that. Orders more than two hours
old back off to a ten-minute poll, so an older one can take that long.
2026-08-20 23:33:50 +02:00
Two operational notes. The timer only runs while that machine is awake, so
`Persistent=true` makes it pull once on waking rather than silently skipping
bank: the hourly pull asks nostrod, and holds no bunq key
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>
2026-11-25 14:21:48 +01:00
every window it missed. And when the connection in nostrod stops working
(`nostro connectors` says whether it does: a revoked key, or an IP-restricted
key after the home address changed), the pull fails and its unit says so, but
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
nothing tells the shop. Settlement then rests on the callback alone, so a
bank: the hourly pull asks nostrod, and holds no bunq key
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>
2026-11-25 14:21:48 +01:00
failing `catcrafts-credits` unit is worth noticing.
2026-08-20 20:15:47 +02:00
The file source stays regardless — it is how the suites drive real settlement
with no network, and it is the manual escape hatch for settling a transfer by
hand. `--mark-paid` remains the other one.
deploy: the bank callback's controls are in the Caddy example
The README says a bank callback is not signed and that three controls
in Caddy "all have to stay in place": a source-IP allowlist, a path of
which only the non-secret prefix is in the web server's config, and
log_skip. Caddyfile.example had none of them. A host set up from it
proxied the callback to the backend from anyone and wrote the secret
path to the access log, which feeds the public analytics page.
The example now has the block: /hooks/bunq/* answers 403 to anything
outside the bank's range, is kept out of the log, and is proxied. It
adapts with Caddy 2.11.7 and sorts ahead of the catch-all. Both proxy
blocks carry a 64 KiB request_body cap, the same as the backend's.
catcrafts-analytics drops /hooks lines from the public tier as well, so
the public page does not rest on that one directive.
The README no longer says the backend binds loopback, because it does
not: ListenerHTTP1 takes a port and no address and binds every IPv4
interface, while the server logs 127.0.0.1 (Crafter.Network issue 11
asks for the address). The firewall on 8081 is what the per-peer limit,
the callback's allowlist and the request-size bound rest on, with the
two commands that check it.
It also documents what the earlier commits changed: the claims file
and what to do with a payment that named two orders, the rule that a
reference names one order, a payment being counted once whatever the
credits file holds, and the ledger being held in memory.
The server's copies of the Caddyfile and of the analytics script are
installed by hand and are not changed by a deploy.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-26 11:05:35 +01:00
Four matching properties worth knowing. The first three are pinned in
`ShouldMatchBankTransfers` (the third over HTTP as well, in
`ShouldSettleBankTransfers` ), the fourth in `ShouldFoldTheOrderLedger` :
2026-08-20 20:15:47 +02:00
* **The reference matches in whatever form the payer typed it.** Both sides
are reduced to upper-case alphanumerics and the match is on the reference
* body * , so `CC-2B6457` , `cc2b6457` , `CC 2B 64 57` and the structured
`RF70CC2B6457` all settle the same order. The order page prints the
structured ISO 11649 form as well, because banks with a dedicated
payment-reference field validate its check digits and refuse a mistyped one
* before the money leaves * — which is what makes unattended matching safe.
* **Partial payments accumulate.** Two credits quoting one reference are
summed, which is what makes the page's "send the rest the same way" true.
Outgoing amounts are ignored, so a refund quoting the reference cannot pay
for the order it refunded.
deploy: the bank callback's controls are in the Caddy example
The README says a bank callback is not signed and that three controls
in Caddy "all have to stay in place": a source-IP allowlist, a path of
which only the non-secret prefix is in the web server's config, and
log_skip. Caddyfile.example had none of them. A host set up from it
proxied the callback to the backend from anyone and wrote the secret
path to the access log, which feeds the public analytics page.
The example now has the block: /hooks/bunq/* answers 403 to anything
outside the bank's range, is kept out of the log, and is proxied. It
adapts with Caddy 2.11.7 and sorts ahead of the catch-all. Both proxy
blocks carry a 64 KiB request_body cap, the same as the backend's.
catcrafts-analytics drops /hooks lines from the public tier as well, so
the public page does not rest on that one directive.
The README no longer says the backend binds loopback, because it does
not: ListenerHTTP1 takes a port and no address and binds every IPv4
interface, while the server logs 127.0.0.1 (Crafter.Network issue 11
asks for the address). The firewall on 8081 is what the per-peer limit,
the callback's allowlist and the request-size bound rest on, with the
two commands that check it.
It also documents what the earlier commits changed: the claims file
and what to do with a payment that named two orders, the rule that a
reference names one order, a payment being counted once whatever the
credits file holds, and the ledger being held in memory.
The server's copies of the Caddyfile and of the analytics script are
installed by hand and are not changed by a deploy.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-26 11:05:35 +01:00
* **A payment is spent once.** A transfer that settled one order pays for no
other, however many references its description quotes. Before the rail
reports an order paid it writes which payment settled it, by the bank's id,
to `<credits>.claims` (default
`/var/lib/catcrafts/orders.jsonl.transfer-credits.jsonl.claims` ), and every
later match leaves a claimed payment out. It cannot live in the credits
file, which the pull replaces every hour. This used to be a "known
limitation": the rail only logged a transfer that quoted two orders and
settled both. It was a way to pay once for several orders (place three,
send one transfer naming all three; found in review on 2026-11-26), and
what a description looks like is no defence, because the payer writes it.
* **A reference names one order.** The reference is 24 bits of the order
token, short on purpose because a person types it, and two orders sharing
one would both be paid by a transfer quoting it. Checkout therefore mints
its token against every reference the ledger has ever held, lapsed and
cancelled orders included: their payments are still in the bank's history.
What the first of those means in practice. A payer who really does send ONE
transfer for two orders gets the first of them settled; the other keeps
waiting, and the journal says so once per order and per run of the server:
```
transfer: CC-… is quoted by 1 payment(s) whose money already settled another order, …
```
Settle that one with `--mark-paid` after looking at the amount. The amount is
not split across orders automatically; at this volume a human finishing the
rare case is proportionate. A settlement on a payment that * looks * as if it
names a second order is logged too, as a pointer, and decides nothing: a name
followed by a date has the same shape as a reference.
The claims file is small and append-only, like the ledger. Keep it with the
ledger backup. Without it nothing is lost that the bank does not also have,
but a payment that named several orders could then settle a second one of
them. If it cannot be written (a full disk, wrong ownership after a restore)
the rail settles nothing and says why, rather than settle on money it cannot
mark as spent. If it is there and cannot be READ at startup, the bank rail
does not start at all, for the same reason: the journal names the file, and
checkout offers only the other rail until it is fixed and the server
restarted.
How far "written before the order is reported paid" goes: it holds across a
crash or a restart of the server at any moment. Neither this file nor the
ledger is fsynced, so a power cut can keep one line and lose the other.
2026-08-20 20:15:47 +02:00
2026-08-15 00:54:05 +02:00
### The EURC rail
No processor, no API key, no account anywhere: the buyer sends EURC (Circle's
euro stablecoin, pegged 1:1 — the token amount IS the euro total) to an
address from a pool this shop generated offline, and the server notices by
polling `balanceOf` over JSON-RPC at a finalized block. The order page is the
payment page. Three pieces of configuration:
- `EURC_CHAINS=/etc/catcrafts/eurc-chains.json` — which chains to watch.
Selecting this rail IS setting this variable. One EVM address is valid on
every chain at once, so the buyer pays on whichever is cheapest; **file
order is display order** — put the cheap chain (Base) first, and its
`note` ("lowest network fees") is the nudge the buyer sees.
```json
{"chains": [
{"name": "base", "rpc": "https://mainnet.base.org",
"contract": "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42",
"chain_id": 8453, "note": "lowest network fees"},
{"name": "ethereum", "rpc": "https://ethereum-rpc.publicnode.com",
"contract": "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
"chain_id": 1}
]}
```
Contract addresses come from Circle's own list
(developers.circle.com/stablecoins/eurc-contract-addresses) and nowhere
else — matching the CONTRACT, not the ticker, is what makes a fake "EURC"
worthless here. EURC exists on Ethereum, Base, Avalanche, Cronos and World
Chain (not Arbitrum/Optimism/Polygon/BNB).
- `EURC_POOL` (default `<orders>.eurc-addresses` ) — one receiving address
per line, `#` comments allowed. Generated by the wallet at home; the box
holds NO key, NO xpub, and can only hand out addresses it was given.
**Copy addresses, never retype ** : the server cannot verify the EIP-55
checksum, so a retyped-but-still-hex address is accepted and published.
**Append only ** : `<pool>.cursor` is an index into this file, so reordering
re-issues addresses already bound to old orders. Duplicates and malformed
lines are startup refusals; exhaustion too — the low-water warning fires
at 25 left.
- `EURC_WINDOW_HOURS` (default 24) — how long an order may sit unpaid. A
lapsed window is NOT bounced money: the address stays ours, a late payment
still lands there (the server logs exactly this), and it is settled by
hand with `--mark-paid` .
2026-08-05 04:18:37 +02:00
```sh
2026-08-20 20:15:47 +02:00
# Neither rail has a credential, so neither has a "test mode" to rehearse in:
# what selects each one is naming where the money lands. To rehearse the crypto
# rail against worthless tokens, point EURC_CHAINS at a testnet chains file
# (Ethereum Sepolia / Base Sepolia contracts are in Circle's list). To rehearse
# the bank rail, run it and write a credits line by hand — see the transfer
# section above, or tools/dev-credit.sh locally.
2026-08-05 04:18:37 +02:00
install -d -m 0755 /etc/catcrafts
cat > /etc/catcrafts/payments.env <<'ENV'
2026-08-20 20:15:47 +02:00
TRANSFER_IBAN=NL..
TRANSFER_BENEFICIARY=exactly as the bank holds it
TRANSFER_BIC=BUNQNL2A
2026-08-15 00:54:05 +02:00
EURC_CHAINS=/etc/catcrafts/eurc-chains.json
2026-08-05 04:18:37 +02:00
ENV
chmod 0600 /etc/catcrafts/payments.env
systemctl restart catcrafts-server
2026-08-20 20:15:47 +02:00
journalctl -u catcrafts-server | tail # "payments: bank=transfer crypto=eurc"
2026-08-05 04:18:37 +02:00
```
Mechanics worth knowing:
2026-08-13 23:34:19 +02:00
* The reconciler polls each open order against **the rail that issued its
link** — the ledger records `pay_choice` per order for exactly this reason.
2026-08-20 20:15:47 +02:00
the bank rail every 60 s (and it shares ONE account read across the whole
sweep, so a dozen open orders is still one request), the EURC rail every
30 s (a finalized block will not arrive faster), both backing off with age. Arriving back on the order page
is ignored as evidence by design: only the rail's own authenticated read of
the bank account, or its RPC check on-chain, moves an order to paid, and the paid event
2026-08-15 00:54:05 +02:00
records the method (`ideal` , `creditcard` , `eurc-base` , …) in the ledger.
* **Unpaid orders lapse automatically** and the buyer just orders again.
2026-08-20 20:15:47 +02:00
the bank rail closes its window after 14 days; the EURC rail after
2026-08-15 00:54:05 +02:00
`EURC_WINDOW_HOURS` (24 by default). A lapsed EURC order is NOT bounced
money — see above.
* The shop **holds EURC ** : crypto revenue sits at the pool addresses until
swept, and nothing lands on the bank account until it is sold for euros at
an exchange. Bookkeeping note: a EURC sale is still a euro sale on the
invoice — EURC is euro-denominated, so there is no rate and no revaluation —
but the financials bank-callback never sees it, so crypto sales exist in
the ledger only until the sweep's SEPA leg arrives.
2026-08-05 04:18:37 +02:00
* Card money stays disputable for months even after "paid": before shipping a
2026-08-20 20:15:47 +02:00
large or exported order, glance at the `via` column in `--orders` . Bank
transfers and EURC are final; `creditcard` is the one with a tail. This is
the one real advantage of the crypto rail — no chargebacks — and it matters
most on exactly the non-EU orders where cards get declined.
* **iDEAL's finality has an expiry date, and it is inside the launch window.**
Written here because it invalidates the obvious shipping rule: "iDEAL says
paid, so it is safe to post" stops being true as iDEAL becomes Wero through
2026-2027. Wero carries a **120-calendar-day dispute window ** for online
purchases (goods not delivered, not as described), and the bank acts as
facilitator, NOT as insurer — verified in bunq's business terms ch. 8.1, and
it is a scheme property rather than one provider's policy, so changing PSP
does not avoid it. Consequence for whoever runs this shop: treat a settled
iDEAL/Wero order like a card order, not like a bank transfer, and keep the
proof-of-dispatch that a dispute is answered with.
* Neither rail has onboarding, a KYB review, or an account that a provider can
close. That is the reason both exist. The imprint, terms and privacy pages
still have to be real, of course, and ShouldStayScriptFree fails the build if
a PLACEHOLDER marker ever reaches a rendered page again.
2026-08-13 23:34:19 +02:00
* Accepting crypto for goods does **not ** make this shop a CASP under MiCA —
2026-08-15 00:54:05 +02:00
no custody for others, no transfer for third parties, so no licence is
required, with or without a processor. Cashing EURC out to the bank goes
through an exchange, and THAT party must be a MiCA-authorised CASP (check
the ESMA register) — but it stands after the checkout, not in it.
2026-08-13 23:34:19 +02:00
* VAT is unchanged by payment method: the sale is priced and invoiced in euro
and taxed on the euro value, whichever rail settled it.
2026-08-20 20:15:47 +02:00
### Payment rail suites in CI
Every deploy exercises both rails end to end, as a mandatory gate. What differs
between them is whether a real counterparty is involved, and that difference is
a fact about the rails rather than a difference in standard.
**`ShouldSettleBankTransfers` needs nothing and always runs.** A self-hosted
rail has no provider to authenticate to, so there is nothing to call and no
secret to hold. The suite drives the REAL transfer rail — not a stand-in — and
bank: the hourly pull asks nostrod, and holds no bunq key
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>
2026-11-25 14:21:48 +01:00
plays the part of the bank by writing a credits line, the same file the
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
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>
2026-11-25 15:08:42 +01:00
bank's callback and the hourly pull fill in production. It covers the whole
lifecycle: the order page's account details, the reference in all the mangled
forms a payer might type, partial payments accumulating, an outgoing amount
being ignored, and the reconciler flipping the order to paid with the right
`via` .
**`ShouldReceiveBankCallbacks` is its counterpart for the callback endpoint**,
and needs nothing either: it plays the bank by posting to the endpoint. An
order settles from a callback, a payment on another account or one the reader
refuses credits nothing, and the server's log repeats nothing a callback
carried. What the reader makes of each shape is pinned in
`ShouldReadBankCallbacks` .
2026-08-20 20:15:47 +02:00
**`ShouldSettleEurcOnTestnet` is the one live-counterparty suite**: a €1
donation paid with 1 real testnet EURC on Ethereum Sepolia, settled by the same
two-endpoint quorum as mainnet. It is a deliberate caution-over-convenience
trade — a public RPC hiccup can fail a deploy (re-run the workflow), but the
rail code can never drift from the chain unnoticed. Locally it skips unless
`EURC_E2E_PRIVATE_KEY` is exported; in CI a missing secret is a failure,
checked as the workflow's first step.
There used to be a second live suite, against the hosted bank provider's
test-mode API. It went when the account did, on 2026-08-20.
One Forgejo secret feeds this (repo → Settings → Actions → Secrets):
2026-08-20 01:36:42 +02:00
* `EURC_E2E_PRIVATE_KEY` — a throwaway Ethereum Sepolia key
(`cast wallet new` ), used ONLY for this: it holds worthless testnet tokens,
never mainnet funds. Fund it with testnet EURC at
<https://faucet.circle.com> — **network set to Ethereum Sepolia ** , one claim
is ~20 EURC — and Sepolia ETH for gas from the pk910 PoW faucet
(<https://sepolia-faucet.pk910.de>, no account, it mines in a browser tab;
one ~0.05 ETH claim covers hundreds of transfers). **Each deploy spends
1 EURC plus gas**, and the suite's receiving addresses are random — the
EURC is gone after the run. When the wallet runs dry the EURC suite fails
at `cast send` with the faucet pointers in its output; top up and re-run.
The workflow installs Foundry's `cast` for the transfer — the server itself
cannot sign transactions, by design. The EURC suite watches `block_tag:
"latest"` (not production's ` finalized`) because Sepolia finality is ~13
minutes; the rail's reorg warning in that suite's server log is expected. To
prove the funded wallet end-to-end before it gates a deploy, run the suite
live once from a dev shell:
```sh
EURC_E2E_PRIVATE_KEY=0x... crafter-build test ShouldSettleEurcOnTestnet --product=server
```
2026-08-20 20:15:47 +02:00
## Opening the shop: what is owed before the status flips
Launch is one line in `Catcrafts.Shared-Content.cppm` (`p.status` from
`coming-soon` to `available` ), and the comment above that line repeats this
list. Both items are invisible today because the only purchasable thing is the
donation, which ships nothing and is a gift rather than a purchase.
1. **The withdrawal button (herroepingsknop) — legally required, currently
absent.** Since **19 June 2026 ** , art. 11a of the Consumer Rights Directive,
implemented as **art. 6:230oa BW ** , requires a clearly labelled button in the
online interface by which a consumer can withdraw from a distance contract.
Pointing them at an email address, which is what the terms page does today,
is no longer sufficient on its own. The button must stay available for the
whole withdrawal period, ask only for what identifies the order, **not **
require creating an account, and confirm immediately on a durable medium.
**Sanction for not having one: the withdrawal period extends from 14 days to
2026-09-05 18:38:39 +02:00
twelve months**, so every EU sale of goods stays unwindable for a year.
2026-08-20 20:15:47 +02:00
The order page is the natural home, since it already identifies exactly one
order through an unguessable link and therefore needs no login. Sketch:
`POST /order/<token>/withdraw` , a button rendered while the window is open
on orders where the right applies, a `withdrawn` event in the ledger, and the
confirmation through the existing mailer.
Note this is easy to miss because the directive that introduced it is
otherwise about financial services; the ACM states it applies to webshops.
Worth confirming with a lawyer in the same pass as anything else.
2. **The shipping rate table. ** Covered in the next section: with no
`SENDCLOUD_*` credentials and no cache file there is no table, and checkout
refuses every order that ships.
2026-08-13 23:34:19 +02:00
## Shipping rates: Sendcloud (REQUIRED to sell)
Sendcloud is the only source of shipping prices. There is no compiled-in
fallback table: a country the carrier has no rate for is a country the shop
cannot post a parcel to, so checkout **refuses ** it rather than quoting a price
that would then have to be refunded or absorbed. The consequence is blunt and
intended — **with no rate table, every checkout refuses ** , and the server says
so at startup:
2026-08-05 04:18:37 +02:00
2026-08-13 23:34:19 +02:00
```
shipping: NO RATE TABLE — checkout will refuse every order until Sendcloud answers
```
2026-08-05 04:18:37 +02:00
```sh
# credentials from Sendcloud: Settings -> Integrations -> API
2026-08-13 23:34:19 +02:00
cat >> /etc/catcrafts/payments.env <<'ENV'
2026-08-05 04:18:37 +02:00
SENDCLOUD_PUBLIC_KEY=...
SENDCLOUD_SECRET_KEY=...
SENDCLOUD_METHOD='PostNL Parcels non-EU,DPD Home'
ENV
systemctl restart catcrafts-server
journalctl -u catcrafts-server | grep shipping: # "table refreshed (N countries...)"
```
`SENDCLOUD_METHOD` is a comma-separated list of name substrings, merged in
2026-08-13 23:34:19 +02:00
order with the FIRST FILTER to cover a country winning it — put the postal
method first so non-EU destinations get post rates (a courier method that also
covers Norway or Switzerland would otherwise price them at courier rates, €54
instead of €19), and the courier second to fill the EU.
Every method matching a filter is kept, not just the first: Sendcloud lists the
same service once per **weight band ** , so the matches for `DPD Home` are that
service's ladder. A parcel is priced at the cheapest band that can carry it,
where the weight is the product's boxed unit weight (`shipWeightGrams` in
Catcrafts.Shared-Content.cppm) times the quantity ordered. That also sets the
quantity ceiling: one order is one parcel, so an order heavier than every band
is refused with the number that * would * fit, and the buy form's `max` shows the
best case across destinations.
A method that publishes no `max_weight` is skipped rather than treated as
unlimited — same principle, no invented numbers.
### The cache is the resilience layer
The fetched table is cached next to the orders file (`<orders>.shipping.json` )
and read at startup **whether or not credentials are configured ** , so a
Sendcloud outage keeps selling at the last known prices. Format is
`country -> [[maxWeightGrams, consumerCents], …]` , prices already VAT-inclusive
(EU rates are grossed up once, at fetch, so the shop nets the carrier's cost).
That also means a hand-written cache file is a complete rate table, which is how
2026-08-15 00:54:05 +02:00
dev and the black-box suites run with no Sendcloud account at all. A cache written by
2026-08-13 23:34:19 +02:00
an older build (flat `country -> cents` , no weight bands) is ignored on load and
replaced by the next refresh — those numbers were an unknown weight band and
re-serving them would price parcels by guess.
2026-08-15 00:54:05 +02:00
This integration is UNTESTED against the live API until credentials exist —
the response parser is covered by the ShouldParseSendcloudRates test, the fetch around it is thin. **Verify one real fetch before opening the shop ** : check that
2026-08-13 23:34:19 +02:00
the logged country count and the weight bands match what the Sendcloud panel
shows, because that table is now the difference between a shop that sells and
one that refuses everything.
2026-08-05 04:18:37 +02:00
The buyer sees whatever the server will charge: the checkout page embeds the
2026-08-13 23:34:19 +02:00
active table into its live total (picking the same band, refusing in the same
places), and the amount is computed server-side at order time from the same
data.
2026-08-05 04:18:37 +02:00
## Invoice signing (GPG)
Paid orders offer a clearsigned markdown invoice at `/order/<token>/invoice.md` .
Numbering continues the pre-shop administration: one series per customer — a
random UUID as the customer number, invoices counting sequentially within it
(`f57c6512-…-3` ), keyed by the buyer's email. Art. 226(2) permits "one or more
series"; completeness is provable by reconciling the append-only ledger against
the payment provider's records. The signature makes the invoice verifiable
forever, independent of this server — which is why the order page tells buyers
to download it rather than promising to host receipts indefinitely.
One-time key setup on the server, as the service user:
```sh
sudo -u catcrafts env GNUPGHOME=/var/lib/catcrafts/gnupg \
gpg --batch --passphrase '' --quick-gen-key 'Catcrafts invoices <invoices@catcrafts .net>' default default never
# export the PUBLIC key and commit it to the repo so buyers can verify:
sudo -u catcrafts env GNUPGHOME=/var/lib/catcrafts/gnupg \
gpg --armor --export invoices@catcrafts .net > invoice-key.asc
```
Then in `/etc/catcrafts/payments.env` :
```
INVOICE_GPG_KEY=invoices@catcrafts .net
```
and `Environment=GNUPGHOME=/var/lib/catcrafts/gnupg` in the service unit (see
catcrafts-server.service). The key has no passphrase because the service signs
unattended; the keyring lives in the 0700 StateDirectory. With a key configured,
a signing failure is a 500 — an unsigned invoice is never served by accident.
Without one (dev), invoices carry a visible UNSIGNED marker.
2026-08-09 00:14:09 +02:00
## Order email (confirmation + invoice)
A paid order gets one confirmation email with the clearsigned invoice
attached — plain text plus a markdown attachment, no HTML part, no remote
resources, nothing the privacy notice would have to explain. The mailer
watches the ledger, so every path to paid (reconciler, arrival poll, a manual
`--mark-paid` even on a later restart) results in exactly one email: the
`notified` event, appended only after the mail command accepts the message,
is what stops a resend.
Delivery shells out to a **sendmail-compatible command ** rather than speaking
SMTP itself, for the same reason invoices shell out to gpg: TLS, AUTH and
deliverability are exactly what msmtp already does well, and the volume is a
handful of messages per week. Deliverability stays the mailbox provider's
problem (SPF/DKIM are theirs), and no third party beyond the provider that
already handles `info@catcrafts.net` ever sees order data — which is what the
privacy page implies.
```sh
apt install msmtp
cat > /etc/msmtprc <<'CONF'
defaults
auth on
tls on
tls_starttls on
account catcrafts
host smtp.your-mail-provider.example
port 587
from info@catcrafts .net
user info@catcrafts .net
passwordeval cat /etc/catcrafts/smtp-password
account default : catcrafts
CONF
chmod 0644 /etc/msmtprc
# msmtp runs as the service user, so the password file must be readable by
# it — unlike payments.env, which only root (systemd) reads.
install -o catcrafts -g catcrafts -m 0600 /dev/null /etc/catcrafts/smtp-password
# ...then put the SMTP password in that file.
```
Then in `/etc/catcrafts/payments.env` :
```
MAIL_COMMAND=msmtp -t
MAIL_FROM=Catcrafts <info@catcrafts .net>
```
and `systemctl restart catcrafts-server` — the journal should say
`mail: order confirmations via 'msmtp -t'` . Unset, no email is sent and the
order page plus the invoice download remain the buyer's receipt: degraded,
not down, like every optional integration here.
Worth knowing:
* A failed handoff retries with exponential backoff (1 min doubling to a cap
of ~an hour), forever — a broken relay delays the email, it never eats it.
Watch `journalctl -u catcrafts-server | grep 'mail:'` after changing config.
* With a signing key configured, a gpg failure means the email WAITS — an
unsigned invoice never leaves by accident, same rule as the download.
* Send a real test: `--rail=fake` locally with `MAIL_COMMAND` pointing at
2026-08-15 00:54:05 +02:00
msmtp and your own address in the order form, or just run the
ShouldProcessCheckout suite (`crafter-build test ShouldProcessCheckout
--product=server`), which captures the messages with a fake sendmail and
verifies the attached signature.
2026-08-09 00:14:09 +02:00
2026-08-05 04:18:37 +02:00
## Reading the orders ledger
```sh
catcrafts-server --orders /var/lib/catcrafts/orders.jsonl
```
```
orders: 2
reference status total cc created token
CC-3F9A2C paid 595.00 NL 2026-08-04T14:02:11Z 3f9a2c…
CC-91B04D awaiting_payment 534.34 CA 2026-08-04T15:40:03Z 91b04d…
```
2026-08-13 23:34:19 +02:00
Manual transitions exist for the cases automation cannot see — a payment
2026-08-05 04:18:37 +02:00
confirmed out-of-band, the parcel handed to the carrier, a refund:
```sh
catcrafts-server --orders /var/lib/catcrafts/orders.jsonl --mark-paid <token>
catcrafts-server --orders /var/lib/catcrafts/orders.jsonl --mark-shipped <token>
catcrafts-server --orders /var/lib/catcrafts/orders.jsonl --cancel <token>
```
Each appends a status event to the log — nothing is ever rewritten, so the
file remains its own audit trail. Deleting personal data on request is an edit
of the fields the seven-year fiscal retention does not cover.
deploy: the bank callback's controls are in the Caddy example
The README says a bank callback is not signed and that three controls
in Caddy "all have to stay in place": a source-IP allowlist, a path of
which only the non-secret prefix is in the web server's config, and
log_skip. Caddyfile.example had none of them. A host set up from it
proxied the callback to the backend from anyone and wrote the secret
path to the access log, which feeds the public analytics page.
The example now has the block: /hooks/bunq/* answers 403 to anything
outside the bank's range, is kept out of the log, and is proxied. It
adapts with Caddy 2.11.7 and sorts ahead of the catch-all. Both proxy
blocks carry a 64 KiB request_body cap, the same as the backend's.
catcrafts-analytics drops /hooks lines from the public tier as well, so
the public page does not rest on that one directive.
The README no longer says the backend binds loopback, because it does
not: ListenerHTTP1 takes a port and no address and binds every IPv4
interface, while the server logs 127.0.0.1 (Crafter.Network issue 11
asks for the address). The firewall on 8081 is what the per-peer limit,
the callback's allowlist and the request-size bound rest on, with the
two commands that check it.
It also documents what the earlier commits changed: the claims file
and what to do with a payment that named two orders, the rule that a
reference names one order, a payment being counted once whatever the
credits file holds, and the ledger being held in memory.
The server's copies of the Caddyfile and of the analytics script are
installed by hand and are not changed by a deploy.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-26 11:05:35 +01:00
Neither needs a restart. The running server holds the ledger folded in memory
(an order page or `/financials` is a lookup, not a read of the whole history)
and folds the file again whenever its size or modification time has changed,
which a CLI transition and an edit in any editor both do. The first request
after one takes the length of a fold: between a third and two thirds of a
second for 40 000 orders, in two measurements. The file is the ledger and the
server's copy is a reading of it; memory for that copy is 3 to 4 KB an order.
Two changes it cannot see, both narrow. One leaves BOTH the size and the
modification time as they were: a same-length edit by a tool that then puts
the old time back (`touch -r` , a sync tool patching in place). The other is a
same-length edit that lands in the few microseconds in which the server is
itself appending a line, because the server takes the file's new time as its
own doing. A person with an editor will not hit that one; a script rewriting
fields in a loop could. Nothing here does either, and a restart reads the
file afresh.
2026-08-17 11:36:54 +02:00
## The open financials page
2026-08-14 02:50:58 +02:00
`/financials` publishes running totals only: sales, donations, and expenses
2026-08-17 11:36:54 +02:00
as one flat list of categories. Sales — and donations made through the shop —
fold out of `orders.jsonl` on every request and need no setup at all.
The bank side (donations to the bank account, and the expense categories) is
`orders.jsonl.financials.json` , written by the owner's own tooling off this
box and re-read on every request: updating the file is all it takes to update
the page. Aggregates by construction — category totals and an as-of date are
all the file can carry, which is the page's privacy design. No bank credential
of any kind lives on this box.
(A bunq mutation callback used to keep these numbers live; it was retired
2026-08-17 — webhook deregistered, endpoint removed. The code and its
documentation are in git history if a bank feed ever comes back.)
2026-08-14 02:50:58 +02:00
2026-08-05 04:18:37 +02:00
## Verifying a deploy
```sh
systemctl status catcrafts-server
curl -s localhost:8081/api/healthz # ok + content counts
# real status codes, which a client-side router cannot produce
curl -o /dev/null -w '%{http_code}\n' https://catcrafts.net/nope # 404
curl -o /dev/null -w '%{http_code}\n' https://catcrafts.net/blog # 301
# the SEO check: content present with no JavaScript involved
curl -s https://catcrafts.net/projects | grep -c '<script' # 0
curl -s https://catcrafts.net/projects | grep -o '<title>[^<]*'
```
2026-08-08 02:50:52 +02:00
## Analytics
Server-side only — the privacy policy promises request logging and nothing
else, so there is no client-side analytics anywhere on the site. GoAccess
(Debian package) turns Caddy's JSON access logs into two static HTML
reports, each with its own persistent DB and ingest ledger:
- `https://catcrafts.net/analytics/` — **public, censored. ** Visitor IPs are
anonymized at ingest (last octet zeroed before anything reaches its DB),
no HOSTS or full-URL REFERRERS panels, and log lines matching `CENSOR_RE`
in the script never enter its DB at all — the public tier cannot leak
deploy: the bank callback's controls are in the Caddy example
The README says a bank callback is not signed and that three controls
in Caddy "all have to stay in place": a source-IP allowlist, a path of
which only the non-secret prefix is in the web server's config, and
log_skip. Caddyfile.example had none of them. A host set up from it
proxied the callback to the backend from anyone and wrote the secret
path to the access log, which feeds the public analytics page.
The example now has the block: /hooks/bunq/* answers 403 to anything
outside the bank's range, is kept out of the log, and is proxied. It
adapts with Caddy 2.11.7 and sorts ahead of the catch-all. Both proxy
blocks carry a 64 KiB request_body cap, the same as the backend's.
catcrafts-analytics drops /hooks lines from the public tier as well, so
the public page does not rest on that one directive.
The README no longer says the backend binds loopback, because it does
not: ListenerHTTP1 takes a port and no address and binds every IPv4
interface, while the server logs 127.0.0.1 (Crafter.Network issue 11
asks for the address). The firewall on 8081 is what the per-peer limit,
the callback's allowlist and the request-size bound rest on, with the
two commands that check it.
It also documents what the earlier commits changed: the claims file
and what to do with a payment that named two orders, the rule that a
reference names one order, a payment being counted once whatever the
credits file holds, and the ledger being held in memory.
The server's copies of the Caddyfile and of the analytics script are
installed by hand and are not changed by a deploy.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-26 11:05:35 +01:00
what it never ingested. `CENSOR_RE` covers `/api` , * * `/order` ** and
`/hooks` : an order token is the entire capability to read that buyer's
status page and their invoice (name, street, postal code, city), so
publishing the path publishes the buyer, and `/hooks/bunq/<secret>` is the
bank callback's shared secret (Caddy's `log_skip` already keeps it out of
the log; this is the second layer). Keep secrets out of URL * paths *
regardless — query strings are already stripped, paths are not.
2026-08-08 02:50:52 +02:00
- `https://catcrafts.net/analytics/private/` — **uncensored ** (basic auth,
hash in the Caddyfile): full IPs, all panels.
Raw logs keep full IPs either way — that is the request logging the privacy
policy declares; per-IP forensics work from the logs and the private tier,
never from the public page.
Three pieces, all in `deploy/` :
- `catcrafts-analytics` → `/usr/local/bin/` — ingests each rotated
`catcrafts.net-*.log.gz` exactly once into a persistent GoAccess DB
(`/var/lib/goaccess/db` , tracked in `/var/lib/goaccess/ingested` ), then
renders the report from DB + live log. The live file is never persisted,
so its lines don't double-count when Caddy rotates it. History therefore
survives log deletion: the DB keeps aggregates forever.
- `catcrafts-analytics.service` — oneshot, runs as `caddy` (owner of the
0600 logs).
- `catcrafts-analytics.timer` — hourly at :07.
Bot filtering is the load-bearing part: measured on real traffic, 57% of
requests were headerless vulnerability scanners and another 19% self-declared
bots (mostly ClaudeBot) — only ~24% human. `--ignore-crawlers
--unknowns-as-crawlers` drops both groups. The flags in the script apply at
ingest time and the DB stores aggregated data, so changing filters later only
affects new lines — re-ingesting history means deleting
`/var/lib/goaccess/{db,ingested}` and letting the next run rebuild from
whatever raw logs retention still holds (a year, per the Caddyfile).
```sh
apt install goaccess
install -m 755 deploy/catcrafts-analytics /usr/local/bin/
install -m 644 deploy/catcrafts-analytics.{service,timer} /etc/systemd/system/
mkdir -p /etc/goaccess /var/lib/goaccess /var/www/analytics /var/www/analytics-private
install -m 644 deploy/goaccess-browsers.list /etc/goaccess/browsers.list
# own IPs to keep out of the numbers - host-only file, NOT in this repo
echo "203.0.113.7" > /etc/goaccess/exclude-ips
chown -R caddy:caddy /var/lib/goaccess /var/www/analytics /var/www/analytics-private
systemctl daemon-reload && systemctl enable --now catcrafts-analytics.timer
```
2026-08-05 04:18:37 +02:00
## Running it locally
```sh
tools/dev.sh # build both products and serve on :8080
tools/dev.sh --no-build # reuse what is already in bin/
```
That is the whole site: Caddy in front, the backend behind, static assets from
disk, cross-origin headers scoped exactly as in production. Ctrl-C stops both.
Orders from the session go to a temp file and are discarded on exit; the
fake payment rail is active — `touch <workdir>/orders.jsonl.fake-paid` plays
the part of the customer paying.
**Do not run `catcrafts-server --serve` alone and expect a working site.** It
serves pages only — static assets are Caddy's job — so `/styles.css` 404s and
every page renders unstyled. That looks broken but isn't; it is the deployment
split working as designed.
### Other useful commands
```sh
tools/fetch-posts.sh # pull posts from the allowed communities
tools/fetch-media.sh [dir] # mirror their media locally (run after the above)
tools/fetch-rates.sh # ECB reference rates for the indicative prices
2026-08-19 17:19:51 +02:00
crafter-build -r # the wasm app alone, no backend, on :8080
2026-08-05 04:18:37 +02:00
2026-08-19 17:19:51 +02:00
crafter-build test --product=server # every suite: the unit assertions
2026-08-15 00:54:05 +02:00
# AND the black-box HTTP suites, which spawn the
# real server on scratch ports (the CI gate; the
# checkout lifecycle re-arms at launch)
2026-08-05 04:18:37 +02:00
<server>/catcrafts-server --routes # status + title for every route
<server>/catcrafts-server --render /projects # dump one page's HTML
<server>/catcrafts-server --orders FILE # the orders ledger + manual transitions
```
CI: build with the Crafter.Build Flatpak on a repo-scoped privileged runner
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>
2026-10-12 16:32:57 +02:00
`crafter-build` is the Crafter.Build Flatpak (`net.catcrafts.CrafterBuild` ),
and a server binary it builds links the Flatpak's libc++ rather than the
host's. Where the host has no matching libc++, run the binary inside the
sandbox, which is what CI's `crafter-run` wrapper does:
`flatpak run --command=$PWD/<server>/catcrafts-server net.catcrafts.CrafterBuild --routes` .
CI: build with the beta crafter-build Flatpak, chosen through CRAFTER_REF
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>
2026-10-16 23:33:06 +02:00
Which branch of the Flatpak CI builds with is `CRAFTER_REF` at the top of
`.forgejo/workflows/deploy.yaml` . `stable` is published from Crafter.Build's
2026-10-16 23:55:27 +02:00
release tags, `beta` from every push to its master. CI is on `stable` , so the
toolchain moves only with a Crafter.Build release. The site tracks
Crafter.Graphics master, so a Crafter.Graphics change that needs a newer
Crafter.Build API fails the deploy until that API is released (2026-10-12:
the Shader fields 2.1.0 lacked, released in 2.2.0 four days later); `beta` is
the stopgap, and `crafter-build --version` inside it prints which master
commit it is. Note that `flatpak install` of an already-installed ref is a
no-op even when the remote has moved on; `flatpak update` is what moves it,
and the workflow runs both.
CI: build with the beta crafter-build Flatpak, chosen through CRAFTER_REF
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>
2026-10-16 23:33:06 +02:00
2026-08-05 04:18:37 +02:00
### If a `bin/` glob matches two directories
2026-08-19 17:19:51 +02:00
The variant directory name embeds a config hash, and * * `` and
non-`` builds hash differently**: ` ` resolves the Crafter libraries
2026-08-05 04:18:37 +02:00
from sibling working trees, a plain build fetches them from Forgejo. They are
genuinely different configurations and both land in `bin/` .
Mixing them leaves two directories, and any script globbing for one picks
arbitrarily — which in practice means testing a stale binary and believing the
result. Every script here refuses to guess and tells you to `rm -rf bin` . Pick
one mode and stay in it.