forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Java: Review changes for https://github.com/github/codeql/pull/3653 #1
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
lcartey
merged 11 commits into
lcartey:java/improve-spring-support
from
aschackmull:java/spring-3653
Jul 7, 2020
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6de612a
Java: Split SpringWebRequestGetMethod into its own class.
aschackmull a41c2d8
Java: Make a few predicates private and autoformat SpringController.
aschackmull 2ae15f9
Java: Remove list, map, and StringReplaceMethod flow steps.
aschackmull 2ce0921
Java: Clean up SpringHttp.qll
aschackmull a80e663
Java: Minor typo fix and autoformat
aschackmull 5d8f9a7
Java: Misc grammar fixes.
aschackmull e6658c5
Java: Cleanup TaintTrackingUtil.qll
aschackmull 5e9e7fe
Java: Add some qldoc and minor formatting.
aschackmull b06d1c7
Java: More qldoc and some formatting.
aschackmull ae21de9
Java: Misc grammar and formatting.
aschackmull f98460c
Java: Use SpringHttpEntity class.
aschackmull 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 |
---|---|---|
|
@@ -377,34 +377,19 @@ private predicate taintPreservingQualifierToMethod(Method m) { | |
or | ||
m = any(ProtobufMessageLite p).getAGetterMethod() | ||
or | ||
m instanceof MapMethod and | ||
( | ||
m.getName().regexpMatch("get|entrySet|keySet|values") | ||
) | ||
or | ||
m.getDeclaringType().getSourceDeclaration().getASourceSupertype*().hasQualifiedName("java.util", "List") and | ||
( | ||
m.getName().regexpMatch("get|toArray|subList|spliterator|set|iterator|listIterator") or | ||
(m.getName().regexpMatch("remove") and not m.getReturnType() instanceof BooleanType) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
m instanceof GetterMethod and m.getDeclaringType() instanceof SpringUntrustedDataType | ||
or | ||
m instanceof StringReplaceMethod | ||
m.getDeclaringType() instanceof SpringHttpEntity and | ||
m.getName().regexpMatch("getBody|getHeaders") | ||
or | ||
exists(SpringUntrustedDataType dt | | ||
m.(GetterMethod) = dt.getAMethod() | ||
) | ||
or | ||
exists(SpringHttpEntity sre | | ||
m = sre.getAMethod() and | ||
m.getName().regexpMatch("getBody|getHeaders") | ||
) | ||
or | ||
exists(SpringHttpHeaders headers | | ||
m = headers.getAMethod() | | ||
exists(SpringHttpHeaders headers | m = headers.getAMethod() | | ||
m.getReturnType() instanceof TypeString | ||
or | ||
m.getReturnType().(RefType).getSourceDeclaration().getASourceSupertype*().hasQualifiedName("java.util", "List") and | ||
m.getReturnType().(ParameterizedType).getTypeArgument(0) instanceof TypeString | ||
exists(ParameterizedType stringlist | | ||
m.getReturnType().(RefType).getASupertype*() = stringlist and | ||
stringlist.getSourceDeclaration().hasQualifiedName("java.util", "List") and | ||
stringlist.getTypeArgument(0) instanceof TypeString | ||
) | ||
) | ||
} | ||
|
||
|
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import java | ||
import spring.SpringController | ||
import spring.SpringWeb | ||
import spring.SpringWeb |
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
33 changes: 17 additions & 16 deletions
33
java/ql/src/semmle/code/java/frameworks/spring/SpringHttp.qll
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 |
---|---|---|
@@ -1,39 +1,40 @@ | ||
/** | ||
* Provides classes for working with Spring classes and interfaces from | ||
* `org.springframework.http`. | ||
*/ | ||
|
||
import java | ||
|
||
/** The class `org.springframework.http.HttpEntity` or an instantiation of it. */ | ||
class SpringHttpEntity extends Class { | ||
SpringHttpEntity() { | ||
getSourceDeclaration() | ||
.getErasure() | ||
.(RefType) | ||
.hasQualifiedName("org.springframework.http", "HttpEntity") | ||
this.getSourceDeclaration().hasQualifiedName("org.springframework.http", "HttpEntity") | ||
} | ||
} | ||
|
||
/** The class `org.springframework.http.RequestEntity` or an instantiation of it. */ | ||
class SpringRequestEntity extends Class { | ||
SpringRequestEntity() { | ||
getSourceDeclaration() | ||
.getErasure() | ||
.(RefType) | ||
.hasQualifiedName("org.springframework.http", "RequestEntity") | ||
this.getSourceDeclaration().hasQualifiedName("org.springframework.http", "RequestEntity") | ||
} | ||
} | ||
|
||
/** The class `org.springframework.http.ResponseEntity` or an instantiation of it. */ | ||
class SpringResponseEntity extends Class { | ||
SpringResponseEntity() { | ||
getSourceDeclaration() | ||
.getErasure() | ||
.(RefType) | ||
.hasQualifiedName("org.springframework.http", "ResponseEntity") | ||
this.getSourceDeclaration().hasQualifiedName("org.springframework.http", "ResponseEntity") | ||
} | ||
} | ||
|
||
/** The nested class `BodyBuilder` in `org.springframework.http.ResponseEntity`. */ | ||
class SpringResponseEntityBodyBuilder extends Interface { | ||
SpringResponseEntityBodyBuilder() { | ||
getSourceDeclaration().getEnclosingType() = any(SpringResponseEntity sre) and | ||
hasName("BodyBuilder") | ||
this.getSourceDeclaration().getEnclosingType() instanceof SpringResponseEntity and | ||
this.hasName("BodyBuilder") | ||
} | ||
} | ||
|
||
/** The class `org.springframework.http.HttpHeaders`. */ | ||
class SpringHttpHeaders extends Class { | ||
SpringHttpHeaders() { hasQualifiedName("org.springframework.http", "HttpHeaders") } | ||
} | ||
SpringHttpHeaders() { this.hasQualifiedName("org.springframework.http", "HttpHeaders") } | ||
} |
10 changes: 7 additions & 3 deletions
10
java/ql/src/semmle/code/java/frameworks/spring/SpringWeb.qll
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 |
---|---|---|
@@ -1,15 +1,19 @@ | ||
/** | ||
* Provides classes for working with Spring web requests. | ||
*/ | ||
|
||
import java | ||
|
||
/** An interface for web requests in the Spring framework. */ | ||
class SpringWebRequest extends Class { | ||
SpringWebRequest() { | ||
hasQualifiedName("org.springframework.web.context.request", "WebRequest") | ||
this.hasQualifiedName("org.springframework.web.context.request", "WebRequest") | ||
} | ||
} | ||
|
||
/** An interface for web requests in the Spring framework. */ | ||
class SpringNativeWebRequest extends Class { | ||
SpringNativeWebRequest() { | ||
hasQualifiedName("org.springframework.web.context.request", "NativeWebRequest") | ||
this.hasQualifiedName("org.springframework.web.context.request", "NativeWebRequest") | ||
} | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that
keySet
is not covered inContainerFlow
(unlike the others). However, I believe this is fine for Spring, because aMap
type parameter to a@RequestMapping
method will be unlikely to contain tainted keys, andContainerFlow
only taintsMap
s via thevalue
not thekey
parameter.(ref: https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-arguments)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keySet
is excluded on purpose as we currently otherwise won't be able to distinguish keys and values in a tainted map. If at some point tainted keys become important to track, then we'll most likely attempt this through a more precise modelling via container-content-as-field-flow.