gin-contrib / cors

Official CORS gin's middleware
https://gin-gonic.github.io/gin/
MIT License
1.77k stars 181 forks source link

Asterisk wildcard does not work #37

Open jankaszel opened 6 years ago

jankaszel commented 6 years ago

Hello! I tried working with the most-recent master state of this project. Although the * wildcard for Access-Control-Allow-Origin (introduced last year, https://github.com/gin-contrib/cors/commit/f894742c196d528a81bd99556ba819bd06d71a4e) should allow for all origins, it does not: validateOrigin certainly does not check whether an asterisk is present (just a shallow equality check), although it is explicitly stated otherwise in the documentation:

If the special "*" value is present in the list, all origins will be allowed.

I could imagine fixing this by either adding a separate case into validateOrigin, checking for an asterisk value, or setting AllowAllOrigins to true if an asterisk is contained in AllowOrigins.

Besides that, I have two points, the former in relation to this issue:

adrianliechti commented 6 years ago

also router.Use(cors.Default()) seems not to work... maybe this is related?

andriisoldatenko commented 6 years ago

@adrianliechti same for me.

config := cors.DefaultConfig()
config.AllowOrigins = []string{"*"}
router.Use(cors.New(config))

this example works ^

adrianliechti commented 6 years ago

thanks a super lot @andriisoldatenko for this handy hint

carlows commented 5 years ago

I get this from using the wildcard:

bad origin: origins must include http:// or https://