Cors issues with 6.2.0
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Expected Behavior
- Able to configure multiple cors mappings in runtime.groovy
- Able to use Spring Boot cors setting allowedOriginPatterns
### Actual Behaviour
Attempting to configure mappings in runtime.groovy in the style recommended here: https://github.com/grails/grails-core/issues/12719#issuecomment-1263945252 I am unable to get working in 6.2.0. Debugging the code I can see the URL paths have lost the special characters (slashes) which I think is leading to them not being picked up.

Using yaml config the slashes appear in the keys shown. I did try various other groovy syntax to see if I could preserve the path properly but wasn't able to get it working.
In addition I am trying to use the Spring setting allowedOriginPatterns to support wildcard subdomains however it doesn't appear to work. Looking at https://github.com/grails/grails-core/blob/c0ac9667e5d55db544cd62155ad17f8322ca1b25/grails-web-url-mappings/src/main/groovy/grails/web/mapping/cors/GrailsCorsConfiguration.groovy I seems like that setting isn't processed but I cannot find another way to utilise that style of CORS config.
It would be good to find out whether I'm doing something wrong or if this is a bug/improvement, then if there is any possibility of a fix in V6. Thanks
### Steps To Reproduce
Grails 6.2.0
Configuring Cors with multiple urls mappings and wildcard subdomains in runtime.groovy.
For example:
```groovy
grails {
cors {
enabled = true
allowedOrigins = []
allowedOriginPatterns = []
mappings {
"/word/googleOnly" {
allowedOrigins = ['https://www.google.com']
}
"/word/anywhere" {
allowedOrigins = ['*']
}
}
}
}
```
or
```groovy
grails {
cors {
enabled = true
allowedOrigins = []
allowedOriginPatterns = []
mappings {
"/word/googleOnly" {
allowedOriginPatterns = ['https://*.google.com']
}
"/word/anywhere" {
allowedOrigins = ['*']
}
}
}
}
```
### Environment Information
- Grails 6.2.0
- Groovy 3.0.21
- Groovy antlr4 disabled (massive performance hit if not disabled)
### Example Application
_No response_
### Version
6.2.0
Contributor guide
Research direction
Start with the runtime.groovy CORS mapping examples and inspect GrailsCorsConfiguration.groovy, the file named in the report. Reproduce both multiple path mappings and wildcard subdomain patterns on Grails 6.2.0, then verify that mappings retain their paths and allowedOriginPatterns are honored.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100