Skip to content

Upstream fix image cdn cors - #465

Open
WilfordGrimley wants to merge 2 commits into
chilli-axe:masterfrom
ProxyPrints:upstream-fix-image-cdn-cors
Open

Upstream fix image cdn cors#465
WilfordGrimley wants to merge 2 commits into
chilli-axe:masterfrom
ProxyPrints:upstream-fix-image-cdn-cors

Conversation

@WilfordGrimley

Copy link
Copy Markdown
Contributor

Description

Problem

The OPTIONS preflight handler (src/handler/cors.ts) sets Access-Control-Allow-Origin, but the real GET responses never do. small/large (served via R2Service) have 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 - fail outright in every browser.

This isn't theoretical - it's reproducible against the live deployment right now:

  $ curl -sD - -o /dev/null "https://cdn.mpcautofill.com/images/google_drive/small/<id>.jpg" | grep -i access-control
  (no output - header is absent)

  $ curl -sD - -o /dev/null "https://cdn.mpcautofill.com/images/google_drive/full/<id>.jpg" | grep -i access-control
  access-control-allow-origin: *

full only "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 help small/large at all since those are served from R2 via a locally-constructed Response with no such header. Confirmed the failure mode end-to-end (an isolated main-thread + Worker fetch() 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 for image-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) sets Access-Control-Allow-Origin, but the real GET responses never do. small/large (served via R2Service) have 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 - fail outright in every browser.

This isn't theoretical - it's reproducible against the live deployment right now:

$ curl -sD - -o /dev/null "https://cdn.mpcautofill.com/images/google_drive/small/<id>.jpg" | grep -i access-control
(no output - header is absent)

$ curl -sD - -o /dev/null "https://cdn.mpcautofill.com/images/google_drive/full/<id>.jpg" | grep -i access-control
access-control-allow-origin: *

full only "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 help small/large at all since those are served from R2 via a locally-constructed Response with no such header. Confirmed the failure mode end-to-end (an isolated main-thread + Worker fetch() 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 for image-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

  • I have installed pre-commit and installed the hooks with pre-commit install before creating any commits.
  • I have updated any related tests for code I modified or added new tests where appropriate.
  • I have manually tested my changes as follows:
  • I have updated any relevant documentation or created new documentation where appropriate.

WilfordGrimley and others added 2 commits July 11, 2026 06:35
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>
@ndepaola

Copy link
Copy Markdown
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!

@WilfordGrimley

Copy link
Copy Markdown
Contributor Author

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!

Awesome! Will any amount of it be cached locally, or still rely on CloudFlare

WilfordGrimley referenced this pull request in ProxyPrints/ProxyPrints.github.io Jul 18, 2026
… 2026-07-18), note GH Support ticket unverifiable remotely
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.

2 participants