Skip to content

Commit 58f953d

Browse files
committed
Check for Origin header - it's mandatory
1 parent f8fbaee commit 58f953d

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

cors.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
//
44
// You can configure it by passing an option struct to cors.New:
55
//
6-
// c := cors.New(cors.Options{
7-
// AllowedOrigins: []string{"foo.com"},
8-
// AllowedMethods: []string{"GET", "POST", "DELETE"},
9-
// AllowCredentials: true,
10-
// })
6+
// c := cors.New(cors.Options{
7+
// AllowedOrigins: []string{"foo.com"},
8+
// AllowedMethods: []string{"GET", "POST", "DELETE"},
9+
// AllowCredentials: true,
10+
// })
1111
//
1212
// Then insert the handler in the chain:
1313
//
14-
// handler = c.Handler(handler)
14+
// handler = c.Handler(handler)
1515
//
1616
// See Options documentation for more options.
1717
//
@@ -210,7 +210,7 @@ func AllowAll() *Cors {
210210
// as necessary.
211211
func (c *Cors) Handler(next http.Handler) http.Handler {
212212
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
213-
if r.Method == http.MethodOptions && r.Header.Get("Access-Control-Request-Method") != "" {
213+
if r.Method == http.MethodOptions && r.Header.Get("Access-Control-Request-Method") != "" && r.Header.Get("Origin") != "" {
214214
c.logf("Handler: Preflight request")
215215
c.handlePreflight(w, r)
216216
// Preflight requests are standalone and should stop the chain as some other

0 commit comments

Comments
 (0)