Repository navigation
Stop Workers Cache from serving authenticated API responses - #13
Merged
Merged
Conversation
Workers Cache caches 200 responses without Cache-Control for 2 hours and serves them without invoking the Worker, skipping the x-admin-secret check. That exposed /api/list to unauthenticated requests and served stale listings. API responses now set `Cache-Control: private, no-store`. 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.
wrangler.tomlenables Workers Cache, which checks the cache before invoking the Worker. The comment there assumed API routes wouldn't be cached because they don't set cacheable headers. In practice, Workers Cache caches responses that have noCache-Controlheader (2 hours for a 200), and it serves cache hits without running the Worker.So once an authenticated
/api/listresponse was cached:x-admin-secretcheck was skipped for later requests to that path, andlist(from the CLI or Raycast) until the cached copy expired.Fix
Cache-Control: private, no-storeon every/api/*response, including 401 and 503 errors, which tells Workers Cache to skip caching.wrangler.tomlcomment./cdnand the other public routes keep their existing caching.The Worker version is part of the Workers Cache key by default, so deploying this starts with an empty cache and drops any cached API responses. No manual purge should be needed.
Testing
pnpm test(20 passing),pnpm check(0 errors),pnpm build.wrangler devand a throwaway secret:/api/listwith no secret returns 401 withCache-Control: private, no-store./api/listand/api/createreturn 200 withCache-Control: private, no-store./cdn/<key>is unchanged (public, max-age=31536000).🤖 Generated with Claude Code