From 215cf52cc8a7939f526da74ae1db8c9a65ece67a Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Tue, 24 May 2022 14:52:40 +0200 Subject: [PATCH 1/4] [JENKINS-68542] Rename the header used for connection cookie The previous value was not a valid HTTP header name and could get filtered by reverse proxies such as nginx. --- .../java/org/jenkinsci/remoting/engine/JnlpConnectionState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/remoting/engine/JnlpConnectionState.java b/src/main/java/org/jenkinsci/remoting/engine/JnlpConnectionState.java index 306c19ded..5f2bc14a3 100644 --- a/src/main/java/org/jenkinsci/remoting/engine/JnlpConnectionState.java +++ b/src/main/java/org/jenkinsci/remoting/engine/JnlpConnectionState.java @@ -66,7 +66,7 @@ public class JnlpConnectionState { /** * The property name for the cookie name key. */ - public static final String COOKIE_KEY = "JnlpAgentProtocol.cookie"; + public static final String COOKIE_KEY = "Connection-Cookie"; /** * Socket connection to the agent. From 317786bdbe7b5ac3617c0e4044781e5fd62fc2b3 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Tue, 24 May 2022 15:25:44 +0200 Subject: [PATCH 2/4] Revert "[JENKINS-68542] Rename the header used for connection cookie" This reverts commit 215cf52cc8a7939f526da74ae1db8c9a65ece67a. --- .../java/org/jenkinsci/remoting/engine/JnlpConnectionState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/remoting/engine/JnlpConnectionState.java b/src/main/java/org/jenkinsci/remoting/engine/JnlpConnectionState.java index 5f2bc14a3..306c19ded 100644 --- a/src/main/java/org/jenkinsci/remoting/engine/JnlpConnectionState.java +++ b/src/main/java/org/jenkinsci/remoting/engine/JnlpConnectionState.java @@ -66,7 +66,7 @@ public class JnlpConnectionState { /** * The property name for the cookie name key. */ - public static final String COOKIE_KEY = "Connection-Cookie"; + public static final String COOKIE_KEY = "JnlpAgentProtocol.cookie"; /** * Socket connection to the agent. From 6f6127afffbcf93df3e9d436015cd5f836ac7b6d Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Tue, 24 May 2022 15:53:42 +0200 Subject: [PATCH 3/4] Define a new cookie key to be used for websockets --- src/main/java/hudson/remoting/Engine.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/hudson/remoting/Engine.java b/src/main/java/hudson/remoting/Engine.java index af6fe2132..804670ea7 100644 --- a/src/main/java/hudson/remoting/Engine.java +++ b/src/main/java/hudson/remoting/Engine.java @@ -109,6 +109,11 @@ public class Engine extends Thread { */ public static final String REMOTING_MINIMUM_VERSION_HEADER = "X-Remoting-Minimum-Version"; + /** + * The property name for the cookie name key for websockets. + */ + public static final String WEBSOCKET_COOKIE_KEY = "Connection-Cookie"; + /** * Thread pool that sets {@link #CURRENT}. */ @@ -577,11 +582,11 @@ public void afterResponse(HandshakeResponse hr) { } } try { - List cookies = hr.getHeaders().get(JnlpConnectionState.COOKIE_KEY); + List cookies = hr.getHeaders().get(Engine.WEBSOCKET_COOKIE_KEY); if (cookies != null && !cookies.isEmpty()) { - addedHeaders.put(JnlpConnectionState.COOKIE_KEY, Collections.singletonList(cookies.get(0))); + addedHeaders.put(Engine.WEBSOCKET_COOKIE_KEY, Collections.singletonList(cookies.get(0))); } else { - addedHeaders.remove(JnlpConnectionState.COOKIE_KEY); + addedHeaders.remove(Engine.WEBSOCKET_COOKIE_KEY); } remoteCapability = Capability.fromASCII(hr.getHeaders().get(Capability.KEY).get(0)); LOGGER.fine(() -> "received " + remoteCapability); From f277b15acee68663829c2d0c32fddbc247fc8566 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Tue, 24 May 2022 16:36:25 +0200 Subject: [PATCH 4/4] Rename constant as suggested by Jesse --- src/main/java/hudson/remoting/Engine.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/hudson/remoting/Engine.java b/src/main/java/hudson/remoting/Engine.java index 804670ea7..d02fd73c4 100644 --- a/src/main/java/hudson/remoting/Engine.java +++ b/src/main/java/hudson/remoting/Engine.java @@ -110,9 +110,9 @@ public class Engine extends Thread { public static final String REMOTING_MINIMUM_VERSION_HEADER = "X-Remoting-Minimum-Version"; /** - * The property name for the cookie name key for websockets. + * The header name to be used for the connection cookie when using websockets. */ - public static final String WEBSOCKET_COOKIE_KEY = "Connection-Cookie"; + public static final String WEBSOCKET_COOKIE_HEADER = "Connection-Cookie"; /** * Thread pool that sets {@link #CURRENT}. @@ -582,11 +582,11 @@ public void afterResponse(HandshakeResponse hr) { } } try { - List cookies = hr.getHeaders().get(Engine.WEBSOCKET_COOKIE_KEY); + List cookies = hr.getHeaders().get(Engine.WEBSOCKET_COOKIE_HEADER); if (cookies != null && !cookies.isEmpty()) { - addedHeaders.put(Engine.WEBSOCKET_COOKIE_KEY, Collections.singletonList(cookies.get(0))); + addedHeaders.put(Engine.WEBSOCKET_COOKIE_HEADER, Collections.singletonList(cookies.get(0))); } else { - addedHeaders.remove(Engine.WEBSOCKET_COOKIE_KEY); + addedHeaders.remove(Engine.WEBSOCKET_COOKIE_HEADER); } remoteCapability = Capability.fromASCII(hr.getHeaders().get(Capability.KEY).get(0)); LOGGER.fine(() -> "received " + remoteCapability);