Skip to content

[BUG] LNbits >= 1.0 webhook is rejected with 400: body is a JSON-encoded string and the schema is strict #1066

Closed

Description

@Perlover

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:

  1. 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:
    "{\"checking_id\": \"...\", \"payment_hash\": \"...\", \"amount\": 199000, ...}"
    
    The route uses the default json() parser (strict: true), which rejects a top-level string with SyntaxError → 400 before the controller runs.
  2. The body schema is .strict() with only payment_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 get 400 Malformed body.

To Reproduce

  1. Configure the relay with payments.processor: lnbits and an LNbits >= 1.0 instance.
  2. Request an admission invoice and pay it.
  3. LNbits records webhook_status = 400 for the payment; the relay logs the error below; the invoice turns completed only 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.parse it (invalid JSON → 400 Malformed body);
  • schema: drop .strict() from the body schema, so the extra LNbits fields are stripped and only payment_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

  1. Perlover commented on Nov 6, 2026

    @Perlover
    ContributorAuthor

    I couldn't open a pull request from the fork (CreatePullRequest isn't permitted for my account here), so the fix is linked above: branch Perlover:fix/lnbits-callback-body, commit 8748958, based on main with a changeset. Happy to adjust it.

  2. self-assigned this
    on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions