Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.stream.Stream;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.tomcat.websocket.Constants;
import org.apache.tomcat.websocket.WsSession;
Expand Down Expand Up @@ -128,9 +127,8 @@ public WebSocketConnection(WebSocketScope scope, Session session) {
if (isDebug) {
log.debug("ws session: {}", wsSession);
}
// the websocket session id will be used for hash code comparison, its the only usable value currently
//wsSessionId = session.getId();
wsSessionId = RandomStringUtils.insecure().nextAlphabetic(11); // random 11 char string
// use the websocket session id for comparisons and lookups
wsSessionId = session.getId();
hashCode = wsSessionId.hashCode();
log.info("ws id: {} hashCode: {}", wsSessionId, hashCode);
// get extensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public boolean checkOrigin(String originHeaderValue) {
log.debug("checkOrigin: {}", originHeaderValue);
// if CORS is enabled
if (crossOriginPolicy) {
if (originHeaderValue == null) {
log.info("Origin header is missing and cross-origin policy is enabled");
return false;
}
log.debug("allowedOrigins: {}", Arrays.toString(allowedOrigins));
// allow "*" == any / all or origin suffix matches
Optional<String> opt = Stream.of(allowedOrigins).filter(origin -> "*".equals(origin) || origin.endsWith(originHeaderValue)).findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,11 @@ private static class EndpointComparator implements Comparator<WsRemoteEndpointIm
public int compare(WsRemoteEndpointImplServer o1, WsRemoteEndpointImplServer o2) {
long t1 = o1.getTimeoutExpiry();
long t2 = o2.getTimeoutExpiry();
if (t1 < t2) {
return -1;
} else if (t1 == t2) {
return 0;
} else {
return 1;
if (t1 == t2) {
// fall back to identity hash to keep ordering stable and unique when timeouts match
return Integer.compare(System.identityHashCode(o1), System.identityHashCode(o2));
}
return Long.compare(t1, t2);
}

}
Expand Down