Upstream fix image cdn cors - #465
Open
WilfordGrimley wants to merge 2 commits into
Open
Conversation
The OPTIONS preflight handler set Access-Control-Allow-Origin, but the real GET responses never did. small/large (served via R2Service) had no CORS header at all, so cross-origin fetch() calls - both the PDF live preview and, from within the PDF render Worker, any consumer fetching these images - failed outright in every browser (confirmed via an isolated main-thread + Worker fetch test in real Firefox and Chromium, no test-harness CORS shim). full happened to "work" only because Google's own response carries a permissive CORS header that passes through unmodified - not something to depend on. Add the header to every actual image response, and add regression tests covering all three size tiers against a mocked upstream response that deliberately has no CORS header of its own. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was no documentation at all for what this Worker does, which endpoints it serves, or which secrets are actually load-bearing versus only used by the scheduled cache-refresh workflow. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Collaborator
|
I'm working on a set of changes which refactors the image CDN pretty heavily & will also fix CORS for GET requests, will probs close this PR to avoid merge conflicts - thanks though! |
Contributor
Author
Awesome! Will any amount of it be cached locally, or still rely on CloudFlare |
4 tasks
WilfordGrimley
referenced
this pull request
in ProxyPrints/ProxyPrints.github.io
Jul 18, 2026
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.
Description
Problem
The OPTIONS preflight handler (
src/handler/cors.ts) setsAccess-Control-Allow-Origin, but the real GET responses never do.small/large(served viaR2Service) have no CORS header at all, so cross-originfetch()calls - both the PDF live preview and, from within the PDF-render Worker, any consumer fetching these images - fail outright in every browser.This isn't theoretical - it's reproducible against the live deployment right now:
fullonly "works" by accident: that header is Google's own response passing through unmodified, not something this Worker sets itself - so it's not something to depend on, and doesn't helpsmall/largeat all since those are served from R2 via a locally-constructedResponsewith no such header. Confirmed the failure mode end-to-end (an isolated main-thread + Workerfetch()test, no test-harness CORS shim) against my own deployment of this same code, in both real Firefox and Chromium.Fix
Add the header to every actual image response in
handleImageRequest, not just the OPTIONS preflight. Also adds a small readme forimage-cdn/, which had no documentation at all.Tests
Added regression tests covering all three size tiers against a mocked upstream response that deliberately carries no CORS header of its own, so this can't silently regress again. Full suite: 48 passed.
Found and fixed while working on a fork (ProxyPrints) - happy to adjust anything to match this repo's conventions.
EOF)
Problem
The OPTIONS preflight handler (
src/handler/cors.ts) setsAccess-Control-Allow-Origin, but the real GET responses never do.small/large(served viaR2Service) have no CORS header at all, so cross-originfetch()calls - both the PDF live preview and, from within the PDF-render Worker, any consumer fetching these images - fail outright in every browser.This isn't theoretical - it's reproducible against the live deployment right now:
fullonly "works" by accident: that header is Google's own response passing through unmodified, not something this Worker sets itself - so it's not something to depend on, and doesn't helpsmall/largeat all since those are served from R2 via a locally-constructedResponsewith no such header. Confirmed the failure mode end-to-end (an isolated main-thread + Workerfetch()test, no test-harness CORS shim) against my own deployment of this same code, in both real Firefox and Chromium.Fix
Add the header to every actual image response in
handleImageRequest, not just the OPTIONS preflight. Also adds a small readme forimage-cdn/, which had no documentation at all.Tests
Added regression tests covering all three size tiers against a mocked upstream response that deliberately carries no CORS header of its own, so this can't silently regress again. Full suite: 48 passed.
Found and fixed while working on a fork (ProxyPrints) - happy to adjust anything to match this repo's conventions.
Checklist
pre-commitand installed the hooks withpre-commit installbefore creating any commits.