-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[grid] honor client-advertised se:remoteUrl for reachable BiDi/CDP/VNC URLs #17790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 2 commits
b3412c0
9a20e5d
c8274b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,6 +145,7 @@ public class LocalNode extends Node implements Closeable { | |
| private final EventBus bus; | ||
| private final URI externalUri; | ||
| private final URI gridUri; | ||
| private final boolean gridUrlSpecified; | ||
| private final Duration heartbeatPeriod; | ||
| private final HealthCheck healthCheck; | ||
| private final int maxSessionCount; | ||
|
|
@@ -175,6 +176,7 @@ protected LocalNode( | |
| EventBus bus, | ||
| URI uri, | ||
| URI gridUri, | ||
| boolean gridUrlSpecified, | ||
| @Nullable HealthCheck healthCheck, | ||
| int maxSessionCount, | ||
| int drainAfterSessionCount, | ||
|
|
@@ -200,6 +202,7 @@ protected LocalNode( | |
|
|
||
| this.externalUri = Require.nonNull("Remote node URI", uri); | ||
| this.gridUri = Require.nonNull("Grid URI", gridUri); | ||
| this.gridUrlSpecified = gridUrlSpecified; | ||
| this.maxSessionCount = | ||
| Math.min(Require.positive("Max session count", maxSessionCount), factories.size()); | ||
| this.heartbeatPeriod = heartbeatPeriod; | ||
|
|
@@ -1221,10 +1224,12 @@ private Session createExternalSession( | |
| Capabilities toUse = | ||
| ImmutableCapabilities.copyOf(requestCapabilities.merge(other.getCapabilities())); | ||
|
|
||
| URI baseUri = resolvePublicGridUri(toUse); | ||
|
|
||
| // Add se:cdp if necessary to send the cdp url back | ||
| if ((isSupportingCdp || toUse.getCapability("se:cdp") != null) && cdpEnabled) { | ||
| String cdpPath = String.format("/session/%s/se/cdp", other.getId()); | ||
| toUse = new PersistentCapabilities(toUse).setCapability("se:cdp", rewrite(cdpPath)); | ||
| toUse = new PersistentCapabilities(toUse).setCapability("se:cdp", rewrite(cdpPath, baseUri)); | ||
| } else { | ||
| // Remove any se:cdp* from the response, CDP is not supported nor enabled | ||
| MutableCapabilities cdpFiltered = new MutableCapabilities(); | ||
|
|
@@ -1259,7 +1264,7 @@ private Session createExternalSession( | |
| toUse = | ||
| new PersistentCapabilities(toUse) | ||
| .setCapability("se:gridWebSocketUrl", uri) | ||
| .setCapability("webSocketUrl", rewrite(bidiPath)); | ||
| .setCapability("webSocketUrl", rewrite(bidiPath, baseUri)); | ||
| } else { | ||
| // Remove any "webSocketUrl" from the response, BiDi is not supported nor enabled | ||
| MutableCapabilities bidiFiltered = new MutableCapabilities(); | ||
|
|
@@ -1278,23 +1283,43 @@ private Session createExternalSession( | |
| boolean isVncEnabled = toUse.getCapability("se:vncLocalAddress") != null; | ||
| if (isVncEnabled) { | ||
| String vncPath = String.format("/session/%s/se/vnc", other.getId()); | ||
| toUse = new PersistentCapabilities(toUse).setCapability("se:vnc", rewrite(vncPath)); | ||
| toUse = new PersistentCapabilities(toUse).setCapability("se:vnc", rewrite(vncPath, baseUri)); | ||
| } | ||
|
|
||
| return new Session(other.getId(), externalUri, other.getStereotype(), toUse, Instant.now()); | ||
| } | ||
|
|
||
| private URI rewrite(String path) { | ||
| private URI rewrite(String path, URI baseUri) { | ||
| try { | ||
| String scheme = "https".equals(gridUri.getScheme()) ? "wss" : "ws"; | ||
| path = NodeOptions.normalizeSubPath(gridUri.getPath()) + path; | ||
| String scheme = "https".equals(baseUri.getScheme()) ? "wss" : "ws"; | ||
| path = NodeOptions.normalizeSubPath(baseUri.getPath()) + path; | ||
| return new URI( | ||
| scheme, gridUri.getUserInfo(), gridUri.getHost(), gridUri.getPort(), path, null, null); | ||
| scheme, baseUri.getUserInfo(), baseUri.getHost(), baseUri.getPort(), path, null, null); | ||
| } catch (URISyntaxException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| // A configured grid-url always wins; only when the node falls back to its auto-detected address | ||
| // (which may be unreachable behind Docker/proxy) do we use the client-advertised se:remoteUrl. | ||
| private URI resolvePublicGridUri(Capabilities caps) { | ||
| if (gridUrlSpecified) { | ||
| return gridUri; | ||
| } | ||
| Object raw = caps.getCapability("se:remoteUrl"); | ||
| if (raw instanceof String && !((String) raw).isEmpty()) { | ||
| try { | ||
| URI uri = new URI((String) raw); | ||
| if (uri.getHost() != null) { | ||
| return uri; | ||
| } | ||
| } catch (URISyntaxException e) { | ||
| // Fall back to gridUri. | ||
| } | ||
| } | ||
| return gridUri; | ||
| } | ||
|
qodo-code-review[bot] marked this conversation as resolved.
qodo-code-review[bot] marked this conversation as resolved.
|
||
|
|
||
| @Override | ||
| public NodeStatus getStatus() { | ||
| Set<Slot> slots = | ||
|
|
@@ -1457,6 +1482,7 @@ public static class Builder { | |
| private final Secret registrationSecret; | ||
| private final List<SessionSlot> factories; | ||
| private final List<NodeCommandInterceptor> interceptors = new ArrayList<>(); | ||
| private boolean gridUrlSpecified = false; | ||
| private int maxSessions = NodeOptions.DEFAULT_MAX_SESSIONS; | ||
| private int drainAfterSessionCount = NodeOptions.DEFAULT_DRAIN_AFTER_SESSION_COUNT; | ||
| private boolean cdpEnabled = NodeOptions.DEFAULT_ENABLE_CDP; | ||
|
|
@@ -1548,12 +1574,18 @@ public Builder addInterceptor(NodeCommandInterceptor interceptor) { | |
| return this; | ||
| } | ||
|
|
||
| public Builder gridUrlSpecified(boolean configured) { | ||
| this.gridUrlSpecified = configured; | ||
| return this; | ||
| } | ||
|
qodo-code-review[bot] marked this conversation as resolved.
|
||
|
|
||
|
Comment on lines
+1579
to
+1583
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4. Gridurlspecified footgun LocalNode.Builder defaults gridUrlSpecified to false and requires callers to set it separately from the gridUri they pass. Any caller that supplies a configured/public gridUri but forgets to set gridUrlSpecified(true) will silently allow client se:remoteUrl to override what the caller intended to be authoritative. Agent Prompt
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only non-test caller of LocalNode.builder is LocalNodeFactory, and it derives both values from the same source in the same place Additionally forgetting the flag only matters if a session request also carries se:remoteUrl |
||
| public LocalNode build() { | ||
| return new LocalNode( | ||
| tracer, | ||
| bus, | ||
| uri, | ||
| gridUri, | ||
| gridUrlSpecified, | ||
| healthCheck, | ||
| maxSessions, | ||
| drainAfterSessionCount, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.