Skip to content

Commit 3f7f57c

Browse files
committed
[java] Adding remote-allow-origins for Chrome
Fixes #11750
1 parent d60cb15 commit 3f7f57c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.HashMap;
3333
import java.util.List;
3434
import java.util.Map;
35+
import java.util.Optional;
3536
import java.util.Set;
3637
import java.util.TreeMap;
3738
import java.util.stream.Stream;
@@ -74,6 +75,11 @@ public class ChromiumOptions<T extends ChromiumOptions<?>> extends AbstractDrive
7475
public ChromiumOptions(String capabilityType, String browserType, String capability) {
7576
this.capabilityName = capability;
7677
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=*");
7783
}
7884

7985
/**
@@ -125,6 +131,20 @@ public T addArguments(String... arguments) {
125131
* @param arguments The arguments to use when starting Chrome.
126132
*/
127133
public T addArguments(List<String> arguments) {
134+
/*
135+
--remote-allow-origins is being added by default since Chrome 111. We need to check
136+
if the argument already exists and then remove it.
137+
*/
138+
String remoteAllowOrigins = "remote-allow-origins";
139+
Optional<String> newArg = arguments.stream()
140+
.filter(arg -> arg.contains(remoteAllowOrigins))
141+
.findFirst();
142+
Optional<String> existingArg = args.stream()
143+
.filter(arg -> arg.contains(remoteAllowOrigins))
144+
.findFirst();
145+
if (newArg.isPresent() && existingArg.isPresent()) {
146+
args.remove(existingArg.get());
147+
}
128148
args.addAll(arguments);
129149
return (T) this;
130150
}

java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ void driversCanBeConfiguredWithASpecificArguments() {
467467
assertThat(reported.get(0).asMap()).asInstanceOf(MAP)
468468
.extractingByKey(ChromeOptions.CAPABILITY).asInstanceOf(MAP)
469469
.extractingByKey("args").asInstanceOf(LIST)
470-
.containsExactly("--homepage=https://www.selenium.dev");
470+
.containsAnyOf("--homepage=https://www.selenium.dev");
471471
}
472472

473473
@Test

0 commit comments

Comments
 (0)