-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Java: CWE-552 Query to detect unsafe request dispatcher usage #7286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
smowton
merged 17 commits into
github:main
from
luchua-bc:java/unsafe-url-forward-dispatch
Jan 18, 2022
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8bcffc2
Query to detect unsafe request dispatcher usage
luchua-bc 29ce0e9
Add sanitizer for virtual method calls
luchua-bc 263dbd3
Optimize the query
luchua-bc cd9a485
Refactor NullOrEmptyCheckGuard
atorralba 81feaae
Refactor PathMatchGuard
atorralba b6886b8
Move code to qll file
atorralba 877c529
Remove the deprecated library keyword
luchua-bc 136fefb
Apply suggestions from code review
atorralba fb1287d
Use dominance instead of getParent
atorralba eb1806c
Split PathMatchGuard into three guards
atorralba a2c98ba
Reordering
atorralba 978ef15
Update method names
luchua-bc 4797fce
Update use cases and qldoc
luchua-bc a3d65a8
Update recommendation in qldoc and make examples more comprehendible
luchua-bc 748008a
Remove dangling reference to UnsafeRequestPath.java
smowton d744cf9
Clean up guard logic:
smowton 1e32514
Avoid using `this` for a non-extending supertype, and remove needless…
smowton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
java/ql/src/experimental/Security/CWE/CWE-552/UnsafeServletRequestDispatch.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// BAD: no URI validation | ||
String returnURL = request.getParameter("returnURL"); | ||
RequestDispatcher rd = sc.getRequestDispatcher(returnURL); | ||
rd.forward(request, response); | ||
|
||
// GOOD: check for a trusted prefix, ensuring path traversal is not used to erase that prefix: | ||
// (alternatively use `Path.normalize` instead of checking for `..`) | ||
if (!returnURL.contains("..") && returnURL.hasPrefix("/pages")) { ... } | ||
// Also GOOD: check for a forbidden prefix, ensuring URL-encoding is not used to evade the check: | ||
// (alternatively use `URLDecoder.decode` before `hasPrefix`) | ||
if (returnURL.hasPrefix("/internal") && !returnURL.contains("%")) { ... } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.