|
32 | 32 | import java.util.HashMap;
|
33 | 33 | import java.util.List;
|
34 | 34 | import java.util.Map;
|
| 35 | +import java.util.Optional; |
35 | 36 | import java.util.Set;
|
36 | 37 | import java.util.TreeMap;
|
37 | 38 | import java.util.stream.Stream;
|
@@ -74,6 +75,11 @@ public class ChromiumOptions<T extends ChromiumOptions<?>> extends AbstractDrive
|
74 | 75 | public ChromiumOptions(String capabilityType, String browserType, String capability) {
|
75 | 76 | this.capabilityName = capability;
|
76 | 77 | 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=*"); |
77 | 83 | }
|
78 | 84 |
|
79 | 85 | /**
|
@@ -125,6 +131,20 @@ public T addArguments(String... arguments) {
|
125 | 131 | * @param arguments The arguments to use when starting Chrome.
|
126 | 132 | */
|
127 | 133 | 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 | + } |
128 | 148 | args.addAll(arguments);
|
129 | 149 | return (T) this;
|
130 | 150 | }
|
|
0 commit comments