Repository navigation
Harden generated worker and site config - #188
Merged
Merged
Conversation
The worker answered cross-origin preflights and API responses with Access-Control-Allow-Origin: *, although the Notion client only calls the domain from the same origin and notion.site sends no CORS headers. JS chunk requests now drop the query string from the cache key and the upstream fetch, so a random query can no longer bypass the cache and force a new rewrite. Foreign page checks are also kept in the edge cache, so new isolates don't ask Notion again; failed checks are still not cached. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The site is not a single-page app, so the SPA not-found handling served the landing page with status 200 for any path. Serve a 404 page instead, add baseline security headers via _headers, and update the compatibility date. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Fixes from a review against the Cloudflare Workers best practices.
Generated worker (
src/code.ts)/api/*responses withAccess-Control-Allow-Origin: *. The Notion client calls the custom domain from the same origin, and notion.site itself sends no CORS headers to other origins, so this only let third-party pages call the proxied API from a browser.OPTIONSnow returns just anAllowheader.fetchJsdrops the query string from the edge cache key and the upstream fetch. Chunk URLs are content-hashed, and before this change any random query (/_assets/x.js?1) bypassed the cache and forced a new fetch and rewrite.caches.default(1 day, keyed byCACHE_VERSION), so a new isolate doesn't send anothergetPublicPageDatarequest before serving an unmapped page. Failed checks are still served and never cached, as before.Site (
wrangler.jsonc,public/)not_found_handlingis now404-page, with a newpublic/404.html. The site isn't a single-page app, so the SPA setting returned the landing page with status 200 for any unknown path (soft 404).public/_headerswithX-Content-Type-Options,X-Frame-Options: DENY,Referrer-PolicyandPermissions-Policy. Production currently sends none of them.compatibility_dateto 2026-10-28. The Worker is assets-only, so this has no runtime effect.Not changed: I also considered adding
frame-ancestorsto the generated worker, because it deletes Notion's CSP. It isn't needed: Notion's HTML responses carryX-Frame-Options: SAMEORIGIN, and the worker passes that through (checked on sensitive-information.classmethod.live).Verification
npm test: 12 tests pass. Four tests are new, andforward()now also asserts that there is no CORS header. Against the oldsrc/code.ts, the three new behavior tests and the eight API tests fail. The fourth new test (failed checks are not cached) passes on both versions; it guards against regressions.npm run check:renderagainst live Notion: no FAIL. Four checks areNOTION, meaning they fail on notion.site too: database views, database rows, database item, and navigation.npm run build, thenwrangler devon the site:/and/ja/return 200./jaredirects to/ja/./this-does-not-existand/ja/nopereturn 404 with the new page._headersare present.After merge