Skip to content

Commit c4c5dd8

Browse files
committed
[grid] Preventing XSS attack.
Fixes #10430
1 parent 49c7c3f commit c4c5dd8

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

java/src/org/openqa/selenium/grid/web/ResourceHandler.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.openqa.selenium.remote.http.UrlPath;
2727

2828
import java.io.UncheckedIOException;
29+
import java.net.MalformedURLException;
30+
import java.net.URL;
2931
import java.util.Optional;
3032
import java.util.stream.Collectors;
3133

@@ -67,9 +69,16 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
6769
Optional<Resource> result = resource.get(req.getUri());
6870

6971
if (!result.isPresent()) {
72+
String errorMessage;
73+
try {
74+
new URL(req.getUri());
75+
errorMessage = "Unable to find " + req.getUri();
76+
} catch (MalformedURLException ignore) {
77+
errorMessage = "Unable to find resource, invalid path in url.";
78+
}
7079
return new HttpResponse()
7180
.setStatus(HTTP_NOT_FOUND)
72-
.setContent(utf8String("Unable to find " + req.getUri()));
81+
.setContent(utf8String(errorMessage));
7382
}
7483

7584
Resource resource = result.get();

0 commit comments

Comments
 (0)