Skip to content

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
merged 17 commits into from
Jan 18, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use dominance instead of getParent
Add clarification comments to PathMatchGuard
  • Loading branch information
atorralba committed Jan 14, 2022
commit fb1287d577d09cfd6710b51c466351e47fd624c4
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,31 @@ private class PathMatchGuard extends UnsafeUrlForwardBarrierGuard {
isExactStringPathMatch(this) and
branch = true
or
// When using an allowlist, that is, checking for known safe paths
// (for example, `path.startsWith(BASE_PATH)`)
// the application needs to protect against path traversal bypasses.
isAllowListCheck(this) and
exists(MethodAccess ma, Expr checked | isPathTraversalCheck(ma, checked) |
DataFlow::localExprFlow(checked, e)
or
ma.getParent*().(BinaryExpr) = this.(MethodAccess).getParent*()
// Either the path traversal check comes before the guard
DataFlow::localExprFlow(checked, e) or
// or both checks are in the same condition
// (for example, `path.startsWith(BASE_PATH) && !path.contains("..")`)
ma.(Guard).controls(this.getBasicBlock(), _) or
this.controls(ma.getBasicBlock(), branch)
) and
branch = true
or
// When using a blocklist, that is, checking for known bad patterns in the path,
// (for example, `path.startsWith("/WEB-INF/")` or `path.contains("..")`)
// the application needs to protect against double URL encoding bypasses.
isDisallowListCheck(this) and
exists(MethodAccess ma, Expr checked | isURLEncodingCheck(ma, checked) |
DataFlow::localExprFlow(checked, e)
or
ma.getParent*().(BinaryExpr) = this.(MethodAccess).getParent*()
// Either the URL encoding check comes before the guard
DataFlow::localExprFlow(checked, e) or
// or both checks are in the same condition
// (for example, `!path.contains("..") && !path.contains("%")`)
ma.(Guard).controls(this.getBasicBlock(), _) or
this.controls(ma.getBasicBlock(), branch)
) and
branch = false
)
Expand Down