Closed
Description
Thanks for raising a Spring Boot issue. What sort of issue are you raising?
Bug report
Spring boot version: 1.5.8
General issue description:
When a request is send from chrome using XMLHttpRequest, an origin header is added, which causes spring to report invalid CORS request, even though it's not actually a CORS request. See this SO question: https://stackoverflow.com/questions/15512331/chrome-adding-origin-header-to-same-origin-request
Adding the CrossOrigin annotation to the controller doesn't help.
You have to add something like this to your WebSecurity configuration:
@Bean
fun corsConfigurationSource(): CorsConfigurationSource {
val source = UrlBasedCorsConfigurationSource()
val conf = CorsConfiguration()
conf.addAllowedHeader("*")
conf.addAllowedMethod("*")
conf.addAllowedOrigin("*")
source.registerCorsConfiguration("/**", conf)
return source
}
In my opinion Spring shouldn't give a 403, just because an origin header is present, chrome adds it to all POST requests, not just the Preflight Request.
Metadata
Metadata
Assignees
Labels
No labels