Skip to content

Commit 1b01f26

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: adjust BarrierPrefix to handle prepended chars
1 parent 5ac453e commit 1b01f26

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ private class BarrierPrefix extends InterestingPrefix {
7171
// Matches strings that look like when prepended to untrusted input, they will restrict
7272
// the path of a URL: for example, anything containing `?` or `#`.
7373
exists(this.getStringValue().regexpFind("[?#]", 0, offset))
74+
or
75+
this.(CharacterLiteral).getValue() = ["?", "#"] and offset = 0
7476
}
7577

7678
override int getOffset() { result = offset }

java/ql/test/query-tests/security/CWE-552/UrlForwardTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ protected void doGet2(HttpServletRequest request, HttpServletResponse response)
389389
}
390390
}
391391

392-
// Test `StringBuilder.append` sequence with `?` appended before the user input
392+
// GOOD: char `?` appended before the user input
393393
private static final String LOGIN_URL = "/UI/Login";
394394

395395
public void doPost2(HttpServletRequest request, HttpServletResponse response)
@@ -399,14 +399,13 @@ public void doPost2(HttpServletRequest request, HttpServletResponse response)
399399

400400
String queryString = request.getQueryString();
401401

402-
// should be sanitized due to the `?` appended
403402
forwardUrl.append('?').append(queryString);
404403

405404
String fUrl = forwardUrl.toString();
406405

407406
ServletConfig config = getServletConfig();
408407

409-
RequestDispatcher dispatcher = config.getServletContext().getRequestDispatcher(fUrl); // $ SPURIOUS: hasUrlForward
408+
RequestDispatcher dispatcher = config.getServletContext().getRequestDispatcher(fUrl);
410409
dispatcher.forward(request, response);
411410
}
412411
}

0 commit comments

Comments
 (0)