-
Notifications
You must be signed in to change notification settings - Fork 2k
Java: Promote Log Injection from experimental #7054
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 12 commits into
github:main
from
atorralba:atorralba/promote-log-injection
Jan 11, 2022
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7f15177
Move from experimental
atorralba 3ea1af3
Refactor into separate libraries
atorralba ebd6529
WIP: add tests
atorralba 7d88f80
Add tests for summaries
atorralba f1df542
Add stubs & tests
atorralba 474bf57
Minor corrections in QLDoc, qhelp and example code
atorralba ea7e259
Add change note
atorralba 6613a98
Fix references to logging library
atorralba 0e73862
Merge branch 'main' into atorralba/promote-log-injection
atorralba fbebf5e
Move change note to new location
atorralba b9e3220
Move change note to new location
atorralba 1030ff7
Update java/ql/src/Security/CWE/CWE-117/LogInjection.ql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| lgtm,codescanning | ||
| * The query "Log Injection" (`java/log-injection`) has been promoted from experimental to the main query pack. Its results will now appear by default. The query was originally [submitted as an experimental query by @porcupineyhairs and @dellalibera](https://github.com/github/codeql/pull/5099). |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,36 @@ | ||
| /** Provides classes and predicates related to Log Injection vulnerabilities. */ | ||
|
|
||
| import java | ||
| import semmle.code.java.dataflow.DataFlow | ||
| import semmle.code.java.dataflow.ExternalFlow | ||
|
|
||
| /** A data flow sink for unvalidated user input that is used to log messages. */ | ||
| abstract class LogInjectionSink extends DataFlow::Node { } | ||
|
|
||
| /** | ||
| * A node that sanitizes a message before logging to avoid log injection. | ||
| */ | ||
| abstract class LogInjectionSanitizer extends DataFlow::Node { } | ||
|
|
||
| /** | ||
| * A unit class for adding additional taint steps. | ||
| * | ||
| * Extend this class to add additional taint steps that should apply to the `LogInjectionConfiguration`. | ||
| */ | ||
| class LogInjectionAdditionalTaintStep extends Unit { | ||
| /** | ||
| * Holds if the step from `node1` to `node2` should be considered a taint | ||
| * step for the `LogInjectionConfiguration` configuration. | ||
| */ | ||
| abstract predicate step(DataFlow::Node node1, DataFlow::Node node2); | ||
| } | ||
|
|
||
| private class DefaultLogInjectionSink extends LogInjectionSink { | ||
| DefaultLogInjectionSink() { sinkNode(this, "logging") } | ||
| } | ||
|
|
||
| private class DefaultLogInjectionSanitizer extends LogInjectionSanitizer { | ||
| DefaultLogInjectionSanitizer() { | ||
| this.getType() instanceof BoxedType or this.getType() instanceof PrimitiveType | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
java/ql/lib/semmle/code/java/security/LogInjectionQuery.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,22 @@ | ||
| /** Provides taint tracking configurations to be used in queries related to the Log Injection vulnerability. */ | ||
|
|
||
| import java | ||
| import semmle.code.java.dataflow.FlowSources | ||
| import semmle.code.java.security.LogInjection | ||
|
|
||
| /** | ||
| * A taint-tracking configuration for tracking untrusted user input used in log entries. | ||
| */ | ||
| class LogInjectionConfiguration extends TaintTracking::Configuration { | ||
| LogInjectionConfiguration() { this = "LogInjectionConfiguration" } | ||
|
|
||
| override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource } | ||
|
|
||
| override predicate isSink(DataFlow::Node sink) { sink instanceof LogInjectionSink } | ||
|
|
||
| override predicate isSanitizer(DataFlow::Node node) { node instanceof LogInjectionSanitizer } | ||
|
|
||
| override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) { | ||
| any(LogInjectionAdditionalTaintStep c).step(node1, node2) | ||
| } | ||
| } |
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 Log Injection | ||
| * @description Building log entries from user-controlled data may allow | ||
| * insertion of forged log entries by malicious users. | ||
| * @kind path-problem | ||
| * @problem.severity error | ||
| * @security-severity 7.8 | ||
| * @precision high | ||
| * @id java/log-injection | ||
| * @tags security | ||
| * external/cwe/cwe-117 | ||
| */ | ||
|
|
||
| import java | ||
| import semmle.code.java.security.LogInjectionQuery | ||
| import DataFlow::PathGraph | ||
|
|
||
| from LogInjectionConfiguration cfg, DataFlow::PathNode source, DataFlow::PathNode sink | ||
| where cfg.hasFlowPath(source, sink) | ||
| select sink.getNode(), source, sink, "This $@ flows to a log entry.", source.getNode(), | ||
| "user-provided value" | ||
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
38 changes: 0 additions & 38 deletions
38
java/ql/src/experimental/Security/CWE/CWE-117/LogInjection.ql
This file was deleted.
Oops, something went wrong.
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.