Add an option to set an Origin whitelist for Websocket and SockJS
This commit introduces a new OriginHandshakeInterceptor. It filters Origin header value against a list of allowed origins. AbstractSockJsService as been modified to: - Reject CORS requests with forbidden origins - Disable transport types that does not support CORS when an origin check is required - Use the Origin request header value instead of "*" for Access-Control-Allow-Origin response header value (mandatory when Access-Control-Allow-Credentials=true) - Return CORS header only if the request contains an Origin header It is possible to configure easily this behavior thanks to JavaConfig API WebSocketHandlerRegistration#addAllowedOrigins(String...) and StompWebSocketEndpointRegistration#addAllowedOrigins(String...). It is also possible to configure it using the websocket XML namespace. Please notice that this commit does not change the default behavior: cross origin requests are still enabled by default. Issues: SPR-12226
This commit is contained in:
@@ -474,6 +474,24 @@
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="allowed-origins" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Configure allowed {@code Origin} header values. Multiple origins may be specified
|
||||
as a comma-separated list.
|
||||
|
||||
This check is mostly designed for browser clients. There is noting preventing other
|
||||
types of client to modify the Origin header value.
|
||||
|
||||
When SockJS is enabled and allowed origins are restricted, transport types that do not
|
||||
use {@code Origin} headers for cross origin requests (jsonp-polling, iframe-xhr-polling,
|
||||
iframe-eventsource and iframe-htmlfile) are disabled. As a consequence, IE6/IE7 won't be
|
||||
supported anymore and IE8/IE9 will only be supported without cookies.
|
||||
|
||||
By default, all origins are allowed.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
@@ -641,6 +659,24 @@
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="allowed-origins" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Configure allowed {@code Origin} header values. Multiple origins may be specified
|
||||
as a comma-separated list.
|
||||
|
||||
This check is mostly designed for browser clients. There is noting preventing other
|
||||
types of client to modify the Origin header value.
|
||||
|
||||
When SockJS is enabled and allowed origins are restricted, transport types that do not
|
||||
use {@code Origin} headers for cross origin requests (jsonp-polling, iframe-xhr-polling,
|
||||
iframe-eventsource and iframe-htmlfile) are disabled. As a consequence, IE6/IE7 won't be
|
||||
supported anymore and IE8/IE9 will only be supported without cookies.
|
||||
|
||||
By default, all origins are allowed.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:choice>
|
||||
|
||||
Reference in New Issue
Block a user