Skip to content

Commit ee3e129

Browse files
authored
CORS: reject requests with 401 for non-preflight request with not matching origin header (#2732)
1 parent 45524e3 commit ee3e129

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

middleware/cors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func CORSWithConfig(config CORSConfig) echo.MiddlewareFunc {
262262
// Origin not allowed
263263
if allowOrigin == "" {
264264
if !preflight {
265-
return next(c)
265+
return echo.ErrUnauthorized
266266
}
267267
return c.NoContent(http.StatusNoContent)
268268
}

middleware/cors_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ func TestCorsHeaders(t *testing.T) {
525525
allowedOrigin: "http://example.com",
526526
method: http.MethodGet,
527527
expected: false,
528-
expectStatus: http.StatusOK,
528+
expectStatus: http.StatusUnauthorized,
529529
},
530530
{
531531
name: "non-preflight request, allow specific origin, matching origin header = CORS logic done",

0 commit comments

Comments
 (0)