Skip to content

AllowOriginFunc is set, but the content of AllowedOrigins is not ignoredΒ #80

@macbesu

Description

@macbesu

The last sentence of the following description in the README does not seem to be strict (when AllowCredentials:true is set).

AllowOriginFunc func (origin string) bool: A custom function to validate the origin. It takes the origin as an argument and returns true if allowed, or false otherwise. If this option is set, the content of AllowedOrigins is ignored.

I wrote the following code:

r := gin.Default()

r.Use(cors.New(cors.Options{
  AllowedOrigins: []string{"*"}, // I also wrote other origins
  AllowCredentials: true,
  AllowOriginFunc: func(origin string) bool { // I thought this function can cover AllowedOrigins
    return true
  },
}))

When I made a request to the server, my browser console reported a cross-domain error:

image

If I comment out AllowedOrigins: []string{"*"}, there will be no problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions