Skip to content

Commit 8cd2c40

Browse files
committed
Improve random source in SockJS server support
Prior to this commit, the SockJs server support would use `java.util.Random` to send a random value to clients when they request the `/info` endpoint. Per protocol, clients can use this value as a source of entropy for generating a random session id. In practice, this is not used by clients. For example, the SockJS javascript client is using a cryptographically safe API to generate session ids. While this has no concrete effect on known clients, this commit improves the random source in the server support by switching to `java.security.SecureRandom`. Closes gh-33632
1 parent 3098974 commit 8cd2c40

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.nio.charset.StandardCharsets;
21+
import java.security.SecureRandom;
2122
import java.util.ArrayList;
2223
import java.util.Arrays;
2324
import java.util.Collection;
@@ -72,7 +73,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
7273
private static final long ONE_YEAR = TimeUnit.DAYS.toSeconds(365);
7374

7475

75-
private static final Random random = new Random();
76+
private static final Random random = new SecureRandom();
7677

7778
protected final Log logger = LogFactory.getLog(getClass());
7879

0 commit comments

Comments
 (0)