You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using CORSMethodMiddleware in a Subrouter it can add allowed methods from other routes that shouldn't be present.
The issue seems to be that in getAllMethodsForRoute the matcher matches substrings.
Versions
Go version: go version
% go version
go version go1.12.1 darwin/amd64
package version: run git rev-parse HEAD inside the repo
Sorry, I'm not using the repo of mux, but my go.mod has
github.com/gorilla/mux v1.7.3
Steps to Reproduce
How can the bug be triggered?
Create a PathPrefix with a sub router, add two routes with paths where one is a substring of the other. Eg. /hello and /hello/name. Add different allowed methods to these routes.
You can see the allowed methods of both routes when requesting the route with the longer path.
Using the code example below the response header for /test/hello/name looks like
What output or behaviour were you expecting instead?
I would expect to see only the allowed methods of the route in the Access-Control-Allow-Methods which would be Access-Control-Allow-Methods: GET,OPTIONS
Code Snippets
A minimum viable code snippet can be useful! (use backticks to format it).
Describe the bug
When using
CORSMethodMiddleware
in a Subrouter it can add allowed methods from other routes that shouldn't be present.The issue seems to be that in
getAllMethodsForRoute
the matcher matches substrings.Versions
Sorry, I'm not using the repo of mux, but my
go.mod
hasgithub.com/gorilla/mux v1.7.3
Steps to Reproduce
Create a PathPrefix with a sub router, add two routes with paths where one is a substring of the other. Eg.
/hello
and/hello/name
. Add different allowed methods to these routes.You can see the allowed methods of both routes when requesting the route with the longer path.
Using the code example below the response header for
/test/hello/name
looks likeAccess-Control-Allow-Methods: GET,OPTIONS,POST,GET,OPTIONS
Expected behavior
I would expect to see only the allowed methods of the route in the
Access-Control-Allow-Methods
which would beAccess-Control-Allow-Methods: GET,OPTIONS
Code Snippets
The text was updated successfully, but these errors were encountered: