Skip to content

Commit a4eab48

Browse files
committed
Address review comments
1 parent ce37916 commit a4eab48

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,23 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
121121
client.send(unsafer10, null); // $ Alert
122122

123123
// GOOD: sanitisation by regexp validation
124-
String safeUri10 = "https://example.com/";
125124
String param10 = request.getParameter("uri10");
126-
if (param10.matches("[a-zA-Z0-9/_-]+")) {
127-
safeUri10 = safeUri10 + param10;
125+
if (param10.matches("[a-zA-Z0-9_-]+")) {
126+
HttpRequest r10 = HttpRequest.newBuilder(new URI(param10)).build();
127+
client.send(r10, null);
128128
}
129-
HttpRequest r10 = HttpRequest.newBuilder(new URI(safeUri10)).build();
130-
client.send(r10, null);
131-
132129

133130
String param11 = request.getParameter("uri11");
134131
validate(param11);
135-
String safeUri11 = "https://example.com/" + param11;
136-
HttpRequest r11 = HttpRequest.newBuilder(new URI(safeUri11)).build();
132+
HttpRequest r11 = HttpRequest.newBuilder(new URI(param11)).build();
137133
client.send(r11, null);
138134
} catch (Exception e) {
139135
// TODO: handle exception
140136
}
141137
}
142138

143139
private void validate(String s) {
144-
if (!s.matches("[a-zA-Z0-9/_-]+")) {
140+
if (!s.matches("[a-zA-Z0-9_-]+")) {
145141
throw new IllegalArgumentException("Invalid ID");
146142
}
147143
}

0 commit comments

Comments
 (0)