Repository navigation
Description
Describe the bug
With LNbits >= 1.0 as the payments processor, every LNbits webhook to /callbacks/lnbits is rejected with 400, so a paid admission invoice is not confirmed when the payment arrives. It is only confirmed by the maintenance worker on its next poll (UPDATE_INVOICE_INTERVAL = 60000), up to a minute later. Meanwhile the invoice page keeps showing "waiting for payment" after the user has already paid; in our case the user gave up and paid a second invoice.
Two problems on the way, both in /callbacks/lnbits:
- The body is a JSON string, not an object. LNbits sends the webhook with
json=payment.json()(1.5.x, 1.6.x;json=payment.model_dump_json()on current LNbits main,lnbits/core/services/notifications.py).payment.json()already returns a serialized string, and httpx JSON-encodes it again, so the request body is:The route uses the default"{\"checking_id\": \"...\", \"payment_hash\": \"...\", \"amount\": 199000, ...}"json()parser (strict: true), which rejects a top-level string withSyntaxError→400before the controller runs. - The body schema is
.strict()with onlypayment_hash. LNbits always posts its whole payment object (checking_id,payment_hash,wallet_id,amount,fee,bolt11,status,time,extra, ...), so even an object body would get400 Malformed body.
To Reproduce
- Configure the relay with
payments.processor: lnbitsand an LNbits >= 1.0 instance. - Request an admission invoice and pay it.
- LNbits records
webhook_status = 400for the payment; the relay logs the error below; the invoice turnscompletedonly on the next maintenance poll.
Expected behavior
The webhook is accepted and the invoice is confirmed right after the payment.
System
- OS: Ubuntu 22.04
- Platform: docker
- Version: nostream 3.4.1 in production; the code path is unchanged on
main(87bc6c8). LNbits 1.6.2.
Logs
SyntaxError: Unexpected token '"', ""{\"checki"... is not valid JSON
at JSON.parse (<anonymous>)
at createStrictSyntaxError (/app/node_modules/.pnpm/body-parser@1.20.4/node_modules/body-parser/lib/types/json.js:169:10)
at parse (/app/node_modules/.pnpm/body-parser@1.20.4/node_modules/body-parser/lib/types/json.js:86:15)
nginx: "POST /callbacks/lnbits?hmac=... HTTP/1.1" 400 1195 "-" "LNbits/1.6.2"
Proposed fix
Commit 8748958 in Perlover/nostream fix/lnbits-callback-body, based on current main, with a changeset:
- route:
json({ strict: false })for/lnbits; - controller: if the body is a string,
JSON.parseit (invalid JSON →400 Malformed body); - schema: drop
.strict()from the body schema, so the extra LNbits fields are stripped and onlypayment_hash(64 lowercase hex) is validated.
Nothing from the body is trusted beyond the hash: the query hmac is still required and the invoice state is still fetched from LNbits. Tests: a router test that posts the double-encoded body (fails with 400 without the fix), controller tests for the string and the object body and for a non-JSON string, schema tests for the full payment object. The new tests fail without the fix; the rest of the unit suite is unchanged.
Additional context
The double encoding is on the LNbits side, but even if LNbits fixes it, every LNbits 1.x already deployed keeps sending the string, so the relay should accept both forms.
Activity
Perlover commentedon Nov 6, 2026
I couldn't open a pull request from the fork (
CreatePullRequestisn't permitted for my account here), so the fix is linked above: branchPerlover:fix/lnbits-callback-body, commit8748958, based onmainwith a changeset. Happy to adjust it.fix(payments): accept LNbits 1.x callback bodies (#1067)