-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Java: Add RegexMatch concept and recognise @Pattern annotation as sanitizer
#21310
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
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e6dbd52
Add `RegexExecution` in `Concepts.qll`
owen-mc 44eeee5
Add and improve classes for regex-related methods
owen-mc fa3fba4
Use new regex-related classes (no functional change)
owen-mc a22fd39
Use RegexExecution in sanitizer definitions (expands scope)
owen-mc 1ee5728
Add missing QLDoc
owen-mc 6a8204d
"dataflow" -> "data flow" in QLDoc
owen-mc d0999e3
Add failing test for @Pattern validation
owen-mc bfe26c1
Add @Pattern as RegexExecution => SSRF sanitizer
owen-mc c539c2f
Add change note
owen-mc 5bdf550
Fix QLDocs
owen-mc 106254b
Improve QLDocs
owen-mc 953ff9f
PatternAnnotation.getString() should only be field reads
owen-mc 1fefa98
Rename `RegexMatch` and only include expressions
owen-mc 3c161f9
Make contract of RegexMatch clear
owen-mc c709958
Put imports implementing abstract classes in private module
owen-mc 2e0f244
Improve QLDoc on `RegexMatch.getName()`
owen-mc ca4c988
Remove redundant variable
owen-mc 90befa0
Add failing test for Matcher.matches() edge case
owen-mc 8f8f4c2
Fix Matcher.matches edge case
owen-mc d6b71a3
Extend RegexMatch framework to allow for MatcherMatchesCall edge case
owen-mc 16ddb56
Small refactor for stylistic consistency
owen-mc 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
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,88 @@ | ||
| /** | ||
| * Provides abstract classes representing generic concepts such as file system | ||
| * access or system command execution, for which individual framework libraries | ||
| * provide concrete subclasses. | ||
| */ | ||
| overlay[local?] | ||
| module; | ||
|
|
||
| import java | ||
| private import semmle.code.java.dataflow.DataFlow | ||
|
|
||
| /** | ||
| * A data-flow node that executes a regular expression. | ||
| * | ||
| * Extend this class to refine existing API models. If you want to model new APIs, | ||
| * extend `RegexExecution::Range` instead. | ||
| */ | ||
| class RegexExecution extends DataFlow::Node instanceof RegexExecution::Range { | ||
| /** Gets the data flow node for the regex being executed by this node. */ | ||
| DataFlow::Node getRegex() { result = super.getRegex() } | ||
|
|
||
| /** Gets a dataflow node for the string to be searched or matched against. */ | ||
owen-mc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| DataFlow::Node getString() { result = super.getString() } | ||
|
|
||
| /** | ||
| * Gets the name of this regex execution, typically the name of an executing method. | ||
| * This is used for nice alert messages and should include the module if possible. | ||
owen-mc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| string getName() { result = super.getName() } | ||
| } | ||
|
|
||
| /** Provides classes for modeling new regular-expression execution APIs. */ | ||
owen-mc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| module RegexExecution { | ||
| /** | ||
| * A data flow node that executes a regular expression. | ||
| * | ||
| * Extend this class to model new APIs. If you want to refine existing API models, | ||
| * extend `RegexExecution` instead. | ||
| */ | ||
| abstract class Range extends DataFlow::Node { | ||
| /** Gets the data flow node for the regex being executed by this node. */ | ||
| abstract DataFlow::Node getRegex(); | ||
|
|
||
| /** Gets a data flow node for the string to be searched or matched against. */ | ||
| abstract DataFlow::Node getString(); | ||
|
|
||
| /** | ||
| * Gets the name of this regex execution, typically the name of an executing method. | ||
| * This is used for nice alert messages and should include the module if possible. | ||
| */ | ||
| abstract string getName(); | ||
| } | ||
|
|
||
| private class RangeFromExpr extends Range { | ||
| private RegexExecutionExpr::Range ree; | ||
|
|
||
| RangeFromExpr() { this.asExpr() = ree } | ||
|
|
||
| override DataFlow::Node getRegex() { result.asExpr() = ree.getRegex() } | ||
|
|
||
| override DataFlow::Node getString() { result.asExpr() = ree.getString() } | ||
|
|
||
| override string getName() { result = ree.getName() } | ||
| } | ||
| } | ||
|
|
||
| /** Provides classes for modeling new regular-expression execution APIs. */ | ||
| module RegexExecutionExpr { | ||
| /** | ||
| * An expression that executes a regular expression. | ||
| * | ||
| * Extend this class to model new APIs. If you want to refine existing API models, | ||
| * extend `RegexExecution` instead. | ||
| */ | ||
| abstract class Range extends Expr { | ||
| /** Gets the expression for the regex being executed by this node. */ | ||
| abstract Expr getRegex(); | ||
|
|
||
| /** Gets a expression for the string to be searched or matched against. */ | ||
owen-mc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| abstract Expr getString(); | ||
|
|
||
| /** | ||
| * Gets the name of this regex execution, typically the name of an executing method. | ||
| * This is used for nice alert messages and should include the module if possible. | ||
| */ | ||
| abstract string getName(); | ||
| } | ||
| } | ||
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
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
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
This file was deleted.
Oops, something went wrong.
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.