Skip to content

Fix JSON decoding with PocketBase rereadable bodies - #17

Merged
Phloraxx merged 1 commit into
mainfrom
hotfix/pocketbase-json-body
Jul 26, 2026
Merged

Fix JSON decoding with PocketBase rereadable bodies#17
Phloraxx merged 1 commit into
mainfrom
hotfix/pocketbase-json-body

Conversation

@Phloraxx

Copy link
Copy Markdown
Owner

Hotfix

Production post-cutover verification found that valid authenticated JSON POST requests were rejected with 400 Invalid JSON body.

Root cause: PocketBase wraps request bodies in an auto-rereadable reader. decodeJSON used a second json.Decoder.Decode call to prove EOF; on a real network request, the PocketBase reader could rewind before that second decode, making the same JSON appear as a second value.

Fix:

  • snapshot the request body once and strictly decode from an immutable byte reader
  • retain unknown-field and single-JSON-value validation
  • add a regression test using a real httptest.Server + HTTP client, not only direct mux requests

Local validation:

  • uncached full Go test suite passed
  • race detector passed
  • go vet passed
  • staticcheck passed
  • govulncheck: no reachable vulnerabilities
  • clean Docker build passed
  • real container/network smoke test returned 201 for authenticated POST /api/payments

This is intentionally limited to two files.

@Phloraxx
Phloraxx merged commit 0cd634d into main Jul 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant