|
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;
|
@@ -97,6 +98,13 @@ public class WebSocketMessageBrokerConfigTests {
|
97 | 98 |
|
98 | 99 | private static final String CONFIG_LOCATION_PREFIX = "classpath:org/springframework/security/config/websocket/WebSocketMessageBrokerConfigTests";
|
99 | 100 |
|
| 101 | + /* |
| 102 | + * Token format: "token" length random pad bytes + "token" (each byte UTF8 ^= 1). |
| 103 | + */ |
| 104 | + private static final byte[] XOR_CSRF_TOKEN_BYTES = new byte[] { 1, 1, 1, 1, 1, 117, 110, 106, 100, 111 }; |
| 105 | + |
| 106 | + private static final String XOR_CSRF_TOKEN_VALUE = Base64.getEncoder().encodeToString(XOR_CSRF_TOKEN_BYTES); |
| 107 | + |
100 | 108 | public final SpringTestContext spring = new SpringTestContext(this);
|
101 | 109 |
|
102 | 110 | @Autowired(required = false)
|
@@ -125,7 +133,7 @@ public void sendWhenNoIdSpecifiedThenIntegratesWithClientInboundChannel() {
|
125 | 133 | public void sendWhenAnonymousMessageWithConnectMessageTypeThenPermitted() {
|
126 | 134 | this.spring.configLocations(xml("NoIdConfig")).autowire();
|
127 | 135 | SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT);
|
128 |
| - headers.setNativeHeader(this.token.getHeaderName(), this.token.getToken()); |
| 136 | + headers.setNativeHeader(this.token.getHeaderName(), XOR_CSRF_TOKEN_VALUE); |
129 | 137 | this.clientInboundChannel.send(message("/permitAll", headers));
|
130 | 138 | }
|
131 | 139 |
|
@@ -197,7 +205,7 @@ public void sendWhenNoIdSpecifiedThenIntegratesWithAuthorizationManager() {
|
197 | 205 | public void sendWhenAnonymousMessageWithConnectMessageTypeThenAuthorizationManagerPermits() {
|
198 | 206 | this.spring.configLocations(xml("NoIdAuthorizationManager")).autowire();
|
199 | 207 | SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT);
|
200 |
| - headers.setNativeHeader(this.token.getHeaderName(), this.token.getToken()); |
| 208 | + headers.setNativeHeader(this.token.getHeaderName(), XOR_CSRF_TOKEN_VALUE); |
201 | 209 | this.clientInboundChannel.send(message("/permitAll", headers));
|
202 | 210 | }
|
203 | 211 |
|
|
0 commit comments