Disable CORS credentials by default
Access-Control-Allow-Credentials CORS header, used to allow cookies with CORS requests, is not set to true anymore by default when enabling CORS with @CrossOrigin or global CORS configuration in order to provide a more secured default CORS configuration. The related allowCredentials property now requires to be set to true explicitly in order to support cookies with CORS requests. Issue: SPR-16130
This commit is contained in:
@@ -24,6 +24,13 @@ implementation (https://github.com/spring-projects/spring-framework/blob/master/
|
||||
by default) in order to add the relevant CORS response headers (like `Access-Control-Allow-Origin`)
|
||||
based on the CORS configuration you have provided.
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
Be aware that cookies are not allowed by default to avoid increasing the surface attack of
|
||||
the web application (for example via exposing sensitive user-specific information like
|
||||
CSRF tokens). Set `allowedCredentials` property to `true` in order to allow them.
|
||||
====
|
||||
|
||||
|
||||
[[webflux-cors-controller]]
|
||||
== @CrossOrigin
|
||||
@@ -146,7 +153,7 @@ public class WebConfig implements WebFluxConfigurer {
|
||||
.allowedMethods("PUT", "DELETE")
|
||||
.allowedHeaders("header1", "header2", "header3")
|
||||
.exposedHeaders("header1", "header2")
|
||||
.allowCredentials(false).maxAge(3600);
|
||||
.allowCredentials(true).maxAge(3600);
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
@@ -27,6 +27,13 @@ implementation (https://github.com/spring-projects/spring-framework/blob/master/
|
||||
by default) in order to add the relevant CORS response headers (like `Access-Control-Allow-Origin`)
|
||||
based on the CORS configuration you have provided.
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
Be aware that cookies are not allowed by default to avoid increasing the surface attack of
|
||||
the web application (for example via exposing sensitive user-specific information like
|
||||
CSRF tokens). Set `allowedCredentials` property to `true` in order to allow them.
|
||||
====
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
Since CORS requests are automatically dispatched, you *do not need* to change the
|
||||
@@ -165,7 +172,7 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
.allowedMethods("PUT", "DELETE")
|
||||
.allowedHeaders("header1", "header2", "header3")
|
||||
.exposedHeaders("header1", "header2")
|
||||
.allowCredentials(false).maxAge(3600);
|
||||
.allowCredentials(true).maxAge(3600);
|
||||
}
|
||||
}
|
||||
----
|
||||
@@ -197,7 +204,7 @@ It is also possible to declare several CORS mappings with customized properties:
|
||||
allowed-origins="http://domain1.com, http://domain2.com"
|
||||
allowed-methods="GET, PUT"
|
||||
allowed-headers="header1, header2, header3"
|
||||
exposed-headers="header1, header2" allow-credentials="false"
|
||||
exposed-headers="header1, header2" allow-credentials="true"
|
||||
max-age="123" />
|
||||
|
||||
<mvc:mapping path="/resources/**"
|
||||
|
||||
Reference in New Issue
Block a user