fix(api): add Access-Control-Max-Age 86400 to CORS preflight (BUG-API-303)#187
Merged
mastermanas805 merged 1 commit intoMay 30, 2026
Merged
Conversation
a3f57b0 to
7f82288
Compare
…-303)
Without Access-Control-Max-Age the browser re-issues an OPTIONS preflight
before every CORS request. An SPA making 5 cross-origin API calls fires
5 extra preflight roundtrips. 24h (86400) is the modern browsers' clamp
ceiling — Chrome caps at 2h, Firefox at 24h, Safari at 7d — so we ask
for the maximum standard value and let each browser apply its own clamp.
The dashboard SPA is the main beneficiary: every authed call from
instanode.dev → api.instanode.dev used to pay the preflight cost. After
this change cooperative browsers cache the preflight result for up to
2h (Chrome) / 24h (Firefox).
Coverage block:
Symptom: OPTIONS preflight responses missing Access-Control-Max-Age
Enumeration: rg -F "fiberCORS" internal/ — 1 emit site in router.go
Sites found: 1
Sites touched: 1
Coverage test: TestCORSPreflight_HasMaxAgeHeader (new file
cors_maxage_test.go) — drives an OPTIONS preflight
through a fiberCORS-mirrored config and asserts
Access-Control-Max-Age=86400 on the response. Fails
today before the router.go change.
Live verified: pending merge + auto-deploy + curl -X OPTIONS -H
"Origin: https://instanode.dev" -H "Access-Control-
Request-Method: POST" https://api.instanode.dev/api/v1/whoami
| grep access-control-max-age
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
7f82288 to
685f4cf
Compare
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
OPTIONSpreflight responses had noAccess-Control-Max-Age, so browsers re-issue a preflight before every CORS request — every authed call frominstanode.dev→api.instanode.devpaid the extra roundtripMaxAge: 86400(24h) on the fiberCORS middleware. Chrome clamps to 2h, Firefox 24h, Safari 7d — we ask for the max standard value and let each browser apply its clampRule-17 coverage block
OPTIONSpreflight missingAccess-Control-Max-Agerg -F 'fiberCORS' internal/— 1 emit site (router.go)TestCORSPreflight_HasMaxAgeHeader(new fileinternal/router/cors_maxage_test.go) — drives an OPTIONS preflight through a config that mirrorsrouter.Newverbatim and assertsAccess-Control-Max-Age=86400on the response. Fails today before therouter.gochange.curl -X OPTIONS -H "Origin: https://instanode.dev" -H "Access-Control-Request-Method: POST" https://api.instanode.dev/api/v1/whoami | grep access-control-max-ageTest plan
go build ./.../go vet ./...go test ./internal/router/... -short -count=1(all pass including the new test)curl -X OPTIONS -H "Origin: https://instanode.dev" ...returnsaccess-control-max-age: 86400