Skip to content

Commit b94e5ca

Browse files
committed
[grid] use only the origin of se:remoteUrl for proxied URLs and guard returned-caps stripping
1 parent 780f91f commit b94e5ca

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

java/src/org/openqa/selenium/grid/node/local/LocalNode.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,12 @@ private URI resolvePublicGridUri(Capabilities caps) {
13311331
String scheme = uri.getScheme();
13321332
if (uri.getHost() != null
13331333
&& ("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme))) {
1334-
return uri;
1334+
// Use only the reachable origin (scheme/userinfo/host/port). se:remoteUrl advertises
1335+
// where the client reached the Grid so proxied URLs get a reachable host/port; the URL's
1336+
// path is the client's HTTP endpoint (e.g. "/wd/hub"), not a Grid sub-path. Folding it in
1337+
// would produce websocket URLs the Node's routes (keyed off the configured grid-url
1338+
// sub-path) do not match. A real reverse-proxy path prefix is configured via grid-url.
1339+
return new URI(scheme, uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
13351340
}
13361341
} catch (URISyntaxException e) {
13371342
// Fall through to the warning below.

java/test/org/openqa/selenium/grid/node/NodeTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,45 @@ void usesClientReachableAddressForProxiedUrlsWhenRemoteUrlProvided() {
229229
.isEqualTo("ws://localhost:9999/session/" + session.getId() + "/se/vnc");
230230
}
231231

232+
@Test
233+
void ignoresRemoteUrlPathWhenBuildingProxiedUrls() {
234+
// The client's URL path (e.g. "/wd/hub") is its HTTP endpoint, not a Grid sub-path; folding it
235+
// into the proxied websocket URLs would produce routes the Node does not serve. Only the
236+
// origin (host/port) of se:remoteUrl is used.
237+
Capabilities request =
238+
new ImmutableCapabilities(
239+
"browserName",
240+
"cheese",
241+
"se:vncLocalAddress",
242+
"localhost:5900",
243+
"se:remoteUrl",
244+
"http://localhost:9999/wd/hub");
245+
246+
Either<WebDriverException, CreateSessionResponse> response =
247+
local.newSession(createSessionRequest(request));
248+
assertThatEither(response).isRight();
249+
250+
Session session = response.right().getSession();
251+
assertThat(String.valueOf(session.getCapabilities().getCapability("se:vnc")))
252+
.isEqualTo("ws://localhost:9999/session/" + session.getId() + "/se/vnc");
253+
}
254+
255+
@Test
256+
void doesNotReturnRemoteUrlInSessionCapabilities() {
257+
Capabilities request =
258+
new ImmutableCapabilities(
259+
"browserName", "cheese", "se:remoteUrl", "http://user:secret@localhost:9999");
260+
261+
Either<WebDriverException, CreateSessionResponse> response =
262+
local.newSession(createSessionRequest(request));
263+
assertThatEither(response).isRight();
264+
265+
// se:remoteUrl is transport-only: it is consumed to build the proxied URLs and must not be
266+
// echoed back in the session capabilities, where its embedded credentials could leak.
267+
Session session = response.right().getSession();
268+
assertThat(session.getCapabilities().getCapability("se:remoteUrl")).isNull();
269+
}
270+
232271
@Test
233272
void preservesCredentialsFromClientAdvertisedRemoteUrl() {
234273
Capabilities request =

0 commit comments

Comments
 (0)