fix(journal): validate image uploads against the public origin - #71
Merged
Conversation
Contributor
|
State: removed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before. Pasting or uploading an image in production failed with “Upload images from the journal page.” The September 10 production log at 20:05:32 UTC records this rejection: Caddy terminates HTTPS, but Bun receives an HTTP request URL, so comparing its origin with the browser’s HTTPS origin rejects legitimate uploads before storage.
Now. Image uploads validate the browser origin against the existing configured public URL (
BETTER_AUTH_URL). Pasting and file uploads can pass through the production proxy while cross-origin requests and requests without the upload marker remain rejected.Implementation
The upload boundary supplies the configured public origin to the bounded body reader. Neither the request URL nor forwarded headers can authorize an origin. Regression coverage exercises HTTPS origins over HTTP transport, spoofed host and forwarding headers, missing/null/wrong-scheme origins, and missing/false upload markers. Existing size-limit coverage remains in place.
Verification
Completed checks
Deployed through personal-infra PR #339 and successful exact-commit run https://github.com/davidvornholt/personal-infra/actions/runs/34526622367; both hosts passed activation and service verification.
Production readback confirmed digest
sha256:f6b7051ef8e212927e9ba9ae540ad1cce8be80d01466e76ed7d8dae30da056fd. Authenticated synthetic PNG upload over public HTTPS returned 200, authenticated image readback matched the original bytes, anonymous read redirected to sign-in (303), and the synthetic object was removed.Reproduced the HTTP request URL / HTTPS browser origin mismatch with Bun inside the production container.
Focused image tests: 10 passed, 0 failed.
Web test suite: 631 passed, 0 failed.
Local
DATABASE_URL=… nix develop --command bun run checkagainst disposable PostgreSQL 18: 16 of 17 tasks passed (including lint, types, build, and unit tests). The 218-test browser task timed out on unrelated archive/navigation cases and stalled; terminated it after five minutes. The clean CI gate passed all 17 tasks, including the full browser suite: https://github.com/davidvornholt/postlude/actions/runs/34524804480.Initial local attempts found stale installed dependencies and an incompatible stopped PostgreSQL 17 development container. Installed the frozen lockfile with the declared Bun 1.4.0 and used an isolated PostgreSQL 18 container; preserved existing local data.