grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

Cors issues with 6.2.0

Open neilmusgrove opened this issue 1 year ago • 0 comments

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.

image

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:

grails {
    cors {
        enabled = true
        allowedOrigins = []
        allowedOriginPatterns = []
        mappings {
            "/word/googleOnly" {
                allowedOrigins = ['https://www.google.com']
            }
            "/word/anywhere" {
                allowedOrigins = ['*']
            }
        }

    }
}

or

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

neilmusgrove avatar Sep 11 '24 16:09 neilmusgrove