Skip to content

Commit dfe0784

Browse files
committed
[java] Adding remote-allow-origins argument only when the Java 11 http client is not used.
Fixes #11949
1 parent 1ea3134 commit dfe0784

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

java/src/org/openqa/selenium/chrome/ChromeDriverInfo.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,17 @@ public String getDisplayName() {
4545

4646
@Override
4747
public Capabilities getCanonicalCapabilities() {
48-
// Allowing any origin "*" through remote-allow-origins might sound risky but an attacker
49-
// would need to know the port used to start DevTools to establish a connection. Given
50-
// these sessions are relatively short-lived, the risk is reduced. Also, this will be
51-
// removed when we only support Java 11 and above.
52-
return new ImmutableCapabilities(
53-
CapabilityType.BROWSER_NAME, CHROME.browserName(),
54-
ChromeOptions.CAPABILITY,
55-
ImmutableMap.of("args", ImmutableList.of("--remote-allow-origins=*")));
48+
if (!"jdk-http-client".equalsIgnoreCase(System.getProperty("webdriver.http.factory", ""))) {
49+
// Allowing any origin "*" through remote-allow-origins might sound risky but an attacker
50+
// would need to know the port used to start DevTools to establish a connection. Given
51+
// these sessions are relatively short-lived, the risk is reduced. Only set when the Java
52+
// 11 client is not used.
53+
return new ImmutableCapabilities(
54+
CapabilityType.BROWSER_NAME, CHROME.browserName(),
55+
ChromeOptions.CAPABILITY,
56+
ImmutableMap.of("args", ImmutableList.of("--remote-allow-origins=*")));
57+
}
58+
return new ImmutableCapabilities(CapabilityType.BROWSER_NAME, CHROME.browserName());
5659
}
5760

5861
@Override

java/src/org/openqa/selenium/chromium/ChromiumOptions.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ public class ChromiumOptions<T extends ChromiumOptions<?>> extends AbstractDrive
7575
public ChromiumOptions(String capabilityType, String browserType, String capability) {
7676
this.capabilityName = capability;
7777
setCapability(capabilityType, browserType);
78-
// Allowing any origin "*" might sound risky but an attacker would need to know
79-
// the port used to start DevTools to establish a connection. Given these sessions
80-
// are relatively short-lived, the risk is reduced. Also, this will be removed when
81-
// we only support Java 11 and above.
82-
addArguments("--remote-allow-origins=*");
78+
if (!"jdk-http-client".equalsIgnoreCase(System.getProperty("webdriver.http.factory", ""))) {
79+
// Allowing any origin "*" might sound risky but an attacker would need to know
80+
// the port used to start DevTools to establish a connection. Given these sessions
81+
// are relatively short-lived, the risk is reduced. Only set when the Java 11 client
82+
// is not used.
83+
addArguments("--remote-allow-origins=*");
84+
}
8385
}
8486

8587
/**

java/src/org/openqa/selenium/edge/EdgeDriverInfo.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ public String getDisplayName() {
4444

4545
@Override
4646
public Capabilities getCanonicalCapabilities() {
47-
// Allowing any origin "*" through remote-allow-origins might sound risky but an attacker
48-
// would need to know the port used to start DevTools to establish a connection. Given
49-
// these sessions are relatively short-lived, the risk is reduced. Also, this will be
50-
// removed when we only support Java 11 and above.
51-
return new ImmutableCapabilities(
52-
CapabilityType.BROWSER_NAME, EDGE.browserName(),
53-
EdgeOptions.CAPABILITY,
54-
ImmutableMap.of("args", ImmutableList.of("--remote-allow-origins=*")));
47+
if (!"jdk-http-client".equalsIgnoreCase(System.getProperty("webdriver.http.factory", ""))) {
48+
// Allowing any origin "*" through remote-allow-origins might sound risky but an attacker
49+
// would need to know the port used to start DevTools to establish a connection. Given
50+
// these sessions are relatively short-lived, the risk is reduced. Only set when the Java
51+
// 11 client is not used.
52+
return new ImmutableCapabilities(
53+
CapabilityType.BROWSER_NAME, EDGE.browserName(),
54+
EdgeOptions.CAPABILITY,
55+
ImmutableMap.of("args", ImmutableList.of("--remote-allow-origins=*")));
56+
}
57+
return new ImmutableCapabilities(CapabilityType.BROWSER_NAME, EDGE.browserName());
5558
}
5659

5760
@Override

0 commit comments

Comments
 (0)