Skip to content

Commit 5234080

Browse files
authored
Merge pull request github#13097 from egregius313/egregius313/java/webgoat/ssrf-regex-fix
Java: Add constraint to `HostnameSanitizingPrefix` to prevent false negatives in SSRF queries
2 parents ee36d32 + 2d69f81 commit 5234080

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Updated the regular expression in the `HostnameSanitizer` sanitizer in the `semmle.code.java.security.RequestForgery` library to better detect strings prefixed with a hostname.
5+

java/ql/lib/semmle/code/java/security/RequestForgery.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ private class HostnameSanitizingPrefix extends InterestingPrefix {
7979
// the host or entity addressed: for example, anything containing `?` or `#`, or a slash that
8080
// doesn't appear to be a protocol specifier (e.g. `http://` is not sanitizing), or specifically
8181
// the string "/".
82-
exists(
83-
this.getStringValue()
84-
.regexpFind(".*([?#]|[^?#:/\\\\][/\\\\]).*|[/\\\\][^/\\\\].*|^/$", 0, offset)
85-
)
82+
exists(this.getStringValue().regexpFind("([?#]|[^?#:/\\\\][/\\\\])|^/$", 0, offset))
8683
}
8784

8885
override int getOffset() { result = offset }

java/ql/test/query-tests/security/CWE-918/SanitizationTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
116116
HttpRequest unsafer9 = HttpRequest.newBuilder(new URI(unsafeUri9)).build(); // $ SSRF
117117
client.send(unsafer9, null);
118118

119+
String unsafeUri10 = String.format("%s://%s:%s%s", "http", "myserver.com", "80", request.getParameter("baduri10"));
120+
HttpRequest unsafer10 = HttpRequest.newBuilder(new URI(unsafeUri10)).build(); // $ SSRF
121+
client.send(unsafer10, null);
119122
} catch (Exception e) {
120123
// TODO: handle exception
121124
}

0 commit comments

Comments
 (0)