-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Java: Promote Insecure TrustManager from experimental #7136
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
atorralba
merged 7 commits into
github:main
from
atorralba:atorralba/promote-insecure-trustmanager
Jan 24, 2022
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7cd05fb
Move from experimental
atorralba ab4dc30
Refactor into libraries
atorralba d58bb47
Refactor tests
atorralba 77c2b43
Add change note and severity score
atorralba 7a1a45f
QLDoc
atorralba c105d71
Update InsecureTrustManager.qhelp
mchammer01 967308f
Change InsecureTrustManagerConfiguration to DataFlow
atorralba 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
25 changes: 25 additions & 0 deletions
25
java/ql/lib/semmle/code/java/security/InsecureTrustManagerQuery.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** Provides taint tracking configurations to be used in Trust Manager queries. */ | ||
|
||
import java | ||
import semmle.code.java.dataflow.FlowSources | ||
import semmle.code.java.security.InsecureTrustManager | ||
|
||
/** | ||
* A configuration to model the flow of an insecure `TrustManager` | ||
* to the initialization of an SSL context. | ||
*/ | ||
class InsecureTrustManagerConfiguration extends DataFlow::Configuration { | ||
InsecureTrustManagerConfiguration() { this = "InsecureTrustManagerConfiguration" } | ||
|
||
override predicate isSource(DataFlow::Node source) { | ||
source instanceof InsecureTrustManagerSource | ||
} | ||
|
||
override predicate isSink(DataFlow::Node sink) { sink instanceof InsecureTrustManagerSink } | ||
|
||
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::Content c) { | ||
(this.isSink(node) or this.isAdditionalFlowStep(node, _)) and | ||
node.getType() instanceof Array and | ||
c instanceof DataFlow::ArrayContent | ||
} | ||
} |
File renamed without changes.
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,21 @@ | ||
/** | ||
* @name `TrustManager` that accepts all certificates | ||
* @description Trusting all certificates allows an attacker to perform a machine-in-the-middle attack. | ||
* @kind path-problem | ||
* @problem.severity error | ||
* @security-severity 7.5 | ||
* @precision high | ||
* @id java/insecure-trustmanager | ||
* @tags security | ||
* external/cwe/cwe-295 | ||
*/ | ||
|
||
import java | ||
import semmle.code.java.dataflow.DataFlow | ||
import semmle.code.java.security.InsecureTrustManagerQuery | ||
import DataFlow::PathGraph | ||
|
||
from DataFlow::PathNode source, DataFlow::PathNode sink | ||
where any(InsecureTrustManagerConfiguration cfg).hasFlowPath(source, sink) | ||
select sink, source, sink, "This $@, which is defined $@ and trusts any certificate, is used here.", | ||
source, "TrustManager", source.getNode().asExpr().(ClassInstanceExpr).getConstructedType(), "here" |
4 changes: 4 additions & 0 deletions
4
java/ql/src/change-notes/2021-11-15-insecure-trustamanger-query.md
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,4 @@ | ||
--- | ||
category: newQuery | ||
--- | ||
* The query "`TrustManager` that accepts all certificates" (`java/insecure-trustmanager`) has been promoted from experimental to the main query pack. Its results will now appear by default. This query was originally [submitted as an experimental query by @intrigus-lgtm](https://github.com/github/codeql/pull/4879). |
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.
Commenting here, because I can not comment down there, because the code did not change.
When I coded this, there was no good place for
CertificateException
(Line 37/61), maybe there is now a better place or common library?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.
For the moment, this is something that is only used here, and it doesn't seem to fit in any of the currently existing libraries. Nonetheless, this is definitely something to keep in mind if, in the future,
CertificateException
needs to be reused, or more classes fromjava.security.cert
are modeled. Thanks!