Skip to content

Stop Workers Cache from serving authenticated API responses - #13

Merged
gskril merged 1 commit into
mainfrom
fix-api-cache
Oct 19, 2026
Merged

gskril merged 1 commit into
mainfrom
fix-api-cache

Conversation

@gskril

@gskril gskril commented Oct 19, 2026

Copy link
Copy Markdown
Owner

wrangler.toml enables 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 no Cache-Control header (2 hours for a 200), and it serves cache hits without running the Worker.

So once an authenticated /api/list response was cached:

  • the middleware's x-admin-secret check was skipped for later requests to that path, and
  • new uploads didn't show up in list (from the CLI or Raycast) until the cached copy expired.

Fix

  • Middleware now sets Cache-Control: private, no-store on every /api/* response, including 401 and 503 errors, which tells Workers Cache to skip caching.
  • Updated the wrangler.toml comment.

/cdn and 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.
  • Ran the built Worker locally with wrangler dev and a throwaway secret:
    • /api/list with no secret returns 401 with Cache-Control: private, no-store.
    • Authenticated /api/list and /api/create return 200 with Cache-Control: private, no-store.
    • /cdn/<key> is unchanged (public, max-age=31536000).

🤖 Generated with Claude Code

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>
@gskril
gskril merged commit e5e436c into main Oct 19, 2026
4 checks passed
@gskril
gskril deleted the fix-api-cache branch October 19, 2026 22:00
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.

1 participant