Skip to content

Commit

Permalink
🐛- fix cors * behavior #2338
Browse files Browse the repository at this point in the history
  • Loading branch information
ryand67 committed Feb 20, 2023
1 parent 497eb02 commit d40ad2b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions middleware/cors/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func New(config ...Config) fiber.Handler {

// Check allowed origins
for _, o := range allowOrigins {
if o == "*" && cfg.AllowCredentials {
allowOrigin = origin
if o == "*" {
allowOrigin = "*"
break
}
if o == "*" || o == origin {
if o == origin {
allowOrigin = o
break
}
Expand Down
2 changes: 1 addition & 1 deletion middleware/cors/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func Test_CORS_Wildcard(t *testing.T) {
handler(ctx)

// Check result
utils.AssertEqual(t, "localhost", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowOrigin)))
utils.AssertEqual(t, "*", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowOrigin)))
utils.AssertEqual(t, "true", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowCredentials)))
utils.AssertEqual(t, "3600", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlMaxAge)))
utils.AssertEqual(t, "Authentication", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowHeaders)))
Expand Down

0 comments on commit d40ad2b

Please sign in to comment.