Repository navigation
docs(middleware): correct CORS AllowMethods and AllowHeaders defaults - #3181
Open
ZainnQureshii wants to merge 1 commit into
Open
ZainnQureshii wants to merge 1 commit into
ZainnQureshii wants to merge 1 commit into
Conversation
AllowHeaders said an empty list allows no domains; an empty list makes the preflight response reflect Access-Control-Request-Headers. AllowMethods pointed at DefaultCORSConfig, which v5 removed; it now names the fallback methods used when the router sets no Allow header. 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.
Corrects two
CORSConfigfield comments inmiddleware/cors.gothat no longer match what the middleware does in v5.AllowHeaders. The comment saidDefaults to empty list. No domains allowed for CORS.With an empty list,ToMiddlewareactually copies the request'sAccess-Control-Request-Headersvalue intoAccess-Control-Allow-Headerson the preflight response (theallowHeaders != ""else branch in the preflight handler). That allows every requested header, the opposite of what the comment says. The comment now says so.AllowMethods. The comment saidDefault value DefaultCORSConfig.AllowMethods, butDefaultCORSConfigwas removed in v5 (listed under "Also removed defaults" inAPI_CHANGES_V5.md). The fallback is now named directly: the router'sAllowvalue, orGET, HEAD, PUT, PATCH, POST, DELETE(the listToMiddlewaresets whenAllowMethodsis empty) when the router sets none.Comment-only change. Ran
go vet ./middleware/andgo test ./middleware/ -run CORS(pass).Prepared with AI assistance (Claude Code) and reviewed with GitHub Copilot.
🤖 Generated with Claude Code