ktor icon indicating copy to clipboard operation
ktor copied to clipboard

Ktor Server CORS Feature - Pattern matching for origin

Open coud opened this issue 6 years ago • 6 comments

Subsystem Server

Is your feature request related to a problem? Please describe. I stumbled upon a problem where I need to allow origin by wildcard or pattern, ex. http://*.example.com so any subdomain is allowed.

Describe the solution you'd like I want to be able to specify a host with a pattern matching like regex or glob style or give us a way to set a custom callback for checking the origin

Motivation to include to ktor There is no way to solve this with the current CORS feature.

coud avatar Jul 02 '20 11:07 coud

Thanks for the feature request! I believe this can be done and we'll try to work on that

Ololoshechkin avatar Jul 02 '20 13:07 Ololoshechkin

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

oleg-larshin avatar Aug 10 '20 15:08 oleg-larshin

Is there any update on this or at least some method of going about this. I've tried overriding/extending the class but unable as it is set to final.

OlafurBJonsson avatar May 20 '21 14:05 OlafurBJonsson

Is there any information on using the fix in 1.6.5? Do we set subdomains to "", or maybe just put the wildcard in the hosts value ".domain.com"?

AndrewWestberg avatar Nov 08 '21 19:11 AndrewWestberg

please add some examples to use it .I tried with full domain name . still no luck
allowHost("localhost:3000") allowHost("xyz.xyz.com", schemes = listOf("http", "https"))

kavithareddyedula avatar Jun 14 '23 16:06 kavithareddyedula

@kavithareddyedula It's not documented on web but it has been possible to prefix * for wildcard subdomains. This is documented in allowHost source code.

please add some examples to use it .I tried with full domain name . still no luck allowHost("localhost:3000") allowHost("xyz.xyz.com", schemes = listOf("http", "https"))

allowHost("*.xyz.com", listOf("http", "https"))

coud avatar Jun 15 '23 06:06 coud