Skip to content

fix(caddy): exempt hashed assets from rate limit and cache them immutably - #63

Merged
UsamaSadiq merged 1 commit into
foss-sandboxfrom
usama/foss-840-caddy-asset-ratelimit
Nov 30, 2026
Merged

UsamaSadiq merged 1 commit into
foss-sandboxfrom
usama/foss-840-caddy-asset-ratelimit

Conversation

@UsamaSadiq

Copy link
Copy Markdown
Collaborator

Description

  • Fixes a regression from the v1.5.x sync, found on staging: signed-in users get HTTP 429 on pm. for about 50 seconds after loading a page. Part of FOSS-840, train FOSS-838.
  • Cause: upstream's move from nginx to Caddy (refactor: migrate admin and web from nginx to Caddy makeplane/plane#9716) added a per-client-IP rate_limit of 300 requests per minute with no path matcher, and hashed assets are served without Cache-Control. After a deploy the browser revalidates about 400 chunks per page load (304s count), crosses 300/min, and the next document request gets 429. The whole office shares one egress IP, so one user's reload can block colleagues. Prod still runs nginx (v1.4.3), so this would have reached prod with the v26.11.3 promotion. Upstream preview has no fix.
  • apps/web/caddy/Caddyfile and apps/admin/caddy/Caddyfile (admin uses /god-mode/assets/*):
    @hashedAssets {
    	path /assets/*
    	file
    }
    header @hashedAssets Cache-Control "public, max-age=31536000, immutable"
    
    @htmlDocuments path / *.html
    header @htmlDocuments Cache-Control "no-cache"
    @spaRoutes not file
    header @spaRoutes Cache-Control "no-cache"
    
    @rateLimited not path /assets/*
    rate_limit @rateLimited { ... }
    • Hashed assets that exist as files are cached for a year and skip the limiter. Vite names them assets/[name]-[hash]; nothing copied verbatim from public/ lands under /assets.
    • HTML documents and the SPA fallback get no-cache, so a deploy is picked up on the next load. A missing /assets/<name> falls back to index.html, gets no-cache and stays rate-limited (the limiter runs after try_files, per upstream's order rate_limit before file_server).
    • The limiter itself is unchanged (300 events per minute, keyed on {client_ip}) for every other path.
  • Known, pre-existing and out of scope: an old chunk name after a deploy returns index.html with 200 instead of 404.

Testing

  • Custom Caddy built like the Dockerfiles (caddy:2.11.7-builder-alpine + xcaddy --with github.com/mholt/caddy-ratelimit): caddy validate passes for both files
  • Web: /, /index.html, SPA routes and missing assets return no-cache; existing /assets/* return public, max-age=31536000, immutable; 500 rapid asset requests all 200; 320 requests to / give 296 x 200 and 24 x 429
  • Admin: /god-mode/ and SPA routes no-cache, /god-mode/assets/* immutable and exempt
  • Adversarial review APPROVE (re-ran both files with the limit lowered to 5 and real requests)
  • Staging gate: reload a signed-in Plane page repeatedly on rc.4 with no 429

AI disclosure

  • Prepared with Anthropic Claude (Claude Code).
  • I reviewed the diff and this description and can answer for the change.

…ably

The per-IP limiter covered every request, so a post-deploy page load revalidating ~400 chunks behind a shared office IP hit 429. Hashed assets now skip the limiter and get a one-year immutable Cache-Control; HTML documents get no-cache.
@UsamaSadiq
UsamaSadiq merged commit a184332 into foss-sandbox Nov 30, 2026
1 check passed
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