|
20 | 20 | import java.lang.annotation.Retention; |
21 | 21 | import java.lang.annotation.RetentionPolicy; |
22 | 22 | import java.lang.annotation.Target; |
| 23 | +import java.util.Base64; |
23 | 24 | import java.util.HashMap; |
24 | 25 | import java.util.Map; |
25 | 26 | import java.util.function.Supplier; |
@@ -98,6 +99,13 @@ public class WebSocketMessageBrokerConfigTests { |
98 | 99 |
|
99 | 100 | private static final String CONFIG_LOCATION_PREFIX = "classpath:org/springframework/security/config/websocket/WebSocketMessageBrokerConfigTests"; |
100 | 101 |
|
| 102 | + /* |
| 103 | + * Token format: "token" length random pad bytes + "token" (each byte UTF8 ^= 1). |
| 104 | + */ |
| 105 | + private static final byte[] XOR_CSRF_TOKEN_BYTES = new byte[] { 1, 1, 1, 1, 1, 117, 110, 106, 100, 111 }; |
| 106 | + |
| 107 | + private static final String XOR_CSRF_TOKEN_VALUE = Base64.getEncoder().encodeToString(XOR_CSRF_TOKEN_BYTES); |
| 108 | + |
101 | 109 | public final SpringTestContext spring = new SpringTestContext(this); |
102 | 110 |
|
103 | 111 | @Autowired(required = false) |
@@ -126,7 +134,7 @@ public void sendWhenNoIdSpecifiedThenIntegratesWithClientInboundChannel() { |
126 | 134 | public void sendWhenAnonymousMessageWithConnectMessageTypeThenPermitted() { |
127 | 135 | this.spring.configLocations(xml("NoIdConfig")).autowire(); |
128 | 136 | SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT); |
129 | | - headers.setNativeHeader(this.token.getHeaderName(), this.token.getToken()); |
| 137 | + headers.setNativeHeader(this.token.getHeaderName(), XOR_CSRF_TOKEN_VALUE); |
130 | 138 | this.clientInboundChannel.send(message("/permitAll", headers)); |
131 | 139 | } |
132 | 140 |
|
@@ -198,7 +206,7 @@ public void sendWhenNoIdSpecifiedThenIntegratesWithAuthorizationManager() { |
198 | 206 | public void sendWhenAnonymousMessageWithConnectMessageTypeThenAuthorizationManagerPermits() { |
199 | 207 | this.spring.configLocations(xml("NoIdAuthorizationManager")).autowire(); |
200 | 208 | SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT); |
201 | | - headers.setNativeHeader(this.token.getHeaderName(), this.token.getToken()); |
| 209 | + headers.setNativeHeader(this.token.getHeaderName(), XOR_CSRF_TOKEN_VALUE); |
202 | 210 | this.clientInboundChannel.send(message("/permitAll", headers)); |
203 | 211 | } |
204 | 212 |
|
|
0 commit comments