-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Swift: Add Command Injection query (CWE-078) #13726
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
geoffw0
merged 9 commits into
github:main
from
maikypedia:maikypedia/swift-command-injection
Jul 31, 2023
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e45a317
Initial commit
maikypedia cea3477
Qhelp and examples
maikypedia d7d9ffc
Doc error
maikypedia c9fadd9
Support `CommandInjectionAdditionalFlowStep` and fix doc errors
maikypedia 3783133
Fix sink
maikypedia d0a912f
Update swift/ql/src/queries/Security/CWE-078/CommandInjection.ql
maikypedia d9800c7
Update CommandInjection.ql
maikypedia 2a49219
Move query to experimental
maikypedia 90ac5b9
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
Next
Next commit
Initial commit
- Loading branch information
commit e45a31744f31acf3dc27c2602ab23210c1b48bf5
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
swift/ql/lib/codeql/swift/security/CommandInjectionExtensions.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,50 @@ | ||
/** | ||
* Provides classes and predicates for reasoning about system | ||
* commands built from user-controlled sources (that is, command injection | ||
* vulnerabilities). | ||
*/ | ||
|
||
import swift | ||
import codeql.swift.dataflow.DataFlow | ||
import codeql.swift.dataflow.ExternalFlow | ||
|
||
/** | ||
* A dataflow sink for command injection vulnerabilities. | ||
*/ | ||
abstract class CommandInjectionSink extends DataFlow::Node { } | ||
|
||
/** | ||
* A barrier for command injection vulnerabilities. | 8000 tr>||
*/ | ||
abstract class CommandInjectionBarrier extends DataFlow::Node { } | ||
|
||
/** | ||
* A unit class for adding additional flow steps. | ||
*/ | ||
class CommandInjectionAdditionalFlowStep extends Unit { | ||
/** | ||
* Holds if the step from `node1` to `node2` should be considered a flow | ||
* step for paths related to command injection vulnerabilities. | ||
*/ | ||
abstract predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo); | ||
} | ||
|
||
/** An expression of type `Process`. */ | ||
private class ProcessRef extends Expr { | ||
ProcessRef() { | ||
this.getType() instanceof ProcessType or | ||
this.getType() = any(OptionalType t | t.getBaseType() instanceof ProcessType) | ||
} | ||
} | ||
|
||
/** The type `Process`. */ | ||
private class ProcessType extends NominalType { | ||
ProcessType() { this.getFullName() = "Process" } | ||
} | ||
|
||
/** | ||
* A sink defined in a CSV model. | ||
*/ | ||
private class DefaultCommandInjectionSink extends CommandInjectionSink { | ||
DefaultCommandInjectionSink() { sinkNode(this, "command-injection") } | ||
} |
27 changes: 27 additions & 0 deletions
27
swift/ql/lib/codeql/swift/security/CommandInjectionQuery.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,27 @@ | ||
/** | ||
* Provides a taint-tracking configuration for reasoning about system | ||
* commands built from user-controlled sources (that is, Command injection | ||
* vulnerabilities). | ||
*/ | ||
|
||
import swift | ||
import codeql.swift.dataflow.DataFlow | ||
import codeql.swift.dataflow.TaintTracking | ||
import codeql.swift.dataflow.FlowSources | ||
import codeql.swift.security.CommandInjectionExtensions | ||
|
||
/** | ||
* A taint configuration for tainted data that reaches a Command Injection sink. | ||
*/ | ||
module CommandInjectionConfig implements DataFlow::ConfigSig { | ||
predicate isSource(DataFlow::Node node) { node instanceof FlowSource } | ||
|
||
predicate isSink(DataFlow::Node node) { node instanceof CommandInjectionSink } | ||
|
||
predicate isBarrier(DataFlow::Node barrier) { barrier instanceof CommandInjectionBarrier } | ||
} | ||
|
||
/** | ||
* Detect taint flow of tainted data that reaches a Command Injection sink. | ||
*/ | ||
module CommandInjectionFlow = TaintTracking::Global<CommandInjectionConfig>; |
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.