Skip to content

fix: do not implicitly allow OPTIONS in isMethodAllowed#41

Open
lihan3238 wants to merge 2 commits into
go-chi:masterfrom
lihan3238:fix-37-options-method
Open

fix: do not implicitly allow OPTIONS in isMethodAllowed#41
lihan3238 wants to merge 2 commits into
go-chi:masterfrom
lihan3238:fix-37-options-method

Conversation

@lihan3238

Copy link
Copy Markdown

Summary

  • Remove the special case in isMethodAllowed that always allows OPTIONS requests regardless of AllowedMethods configuration
  • Non-preflight OPTIONS requests are now subject to the same method check as other HTTP methods
  • Preflight handling is unaffected since handlePreflight checks Access-Control-Request-Method, not the OPTIONS method itself

Test Changes

  • Updated TestIsMethodAllowedReturnsTrueWithOptions to TestIsMethodAllowedRejectsOptionsByDefault: verifies OPTIONS is rejected when not in AllowedMethods
  • Added TestIsMethodAllowedAllowsOptionsWhenExplicit: verifies OPTIONS is allowed when explicitly listed
  • Updated NonPreflightOptions test: now expects no CORS headers when OPTIONS is not in AllowedMethods
  • Added NonPreflightOptionsAllowed test: verifies CORS headers are set when OPTIONS is explicitly in AllowedMethods

Closes #37

Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com

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.

Middleware unduly allow OPTIONS requests

1 participant