Repository navigation
Unified: Improve unified/swift/cleartext-logging #23185
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
Open
geoffw0
wants to merge
8
commits into
github:main
Choose a base branch
from
geoffw0:unifiedlogging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5ac3343
Unified: Add TODO comments in the query for the parts we're still mis…
geoffw0 0293b08
Unified: Add a few more test cases.
geoffw0 206b42a
Unified: Replace memberAccessParent logic with additional taint steps…
geoffw0 25f82eb
Unified: SensitiveDataCall is redundant now.
geoffw0 ffe581a
Unified: Add models-as-data sinks.
geoffw0 4210d86
Unified: Add heuristic sinks (ported from original Swift).
geoffw0 cad278e
Unified: Add Copilot suggested test case.
geoffw0 a58449f
Unified: Replace SensitiveDataCall.
geoffw0 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -13,32 +13,73 @@ | |
| * external/cwe/cwe-532 | ||
| */ | ||
|
|
||
| // | ||
| // FIXME: This is a deliberately dumb and noisy version of the query used to exercise data flow early on. | ||
| // | ||
| import unified | ||
| import codeql.unified.security.SensitiveData | ||
| import codeql.unified.internal.typeinference.TypeInference as TypeInference | ||
|
|
||
| private string getNameFromExpr(Expr e) { | ||
| result = e.(IdentifierExpr).getValue() | ||
| or | ||
| result = e.(MemberAccessExpr).getMemberName() | ||
| } | ||
|
|
||
| /** | ||
| * Holds if `label` looks like the name of a logging function. | ||
| */ | ||
| bindingset[label] | ||
| private predicate logLikeHeuristic(string label) { | ||
| label.regexpMatch("(l|.*L)og([A-Z0-9].*)?") // e.g. "logMessage", "debugLog" | ||
| } | ||
|
|
||
| predicate heuristicSink(DataFlow::Node node) { | ||
| exists(CallExpr call, FunctionDeclaration f, Expr e | | ||
| f = TypeInference::resolveCallTarget(call) and | ||
| ( | ||
| logLikeHeuristic(f.getName()) | ||
| or | ||
| exists(ClassLikeDeclaration type | | ||
| f = type.getAMemberIncludingExtensions() and | ||
| logLikeHeuristic(type.getName()) | ||
| ) | ||
| ) and | ||
| e = call.getAnArgument().getValue() and | ||
| TypeInference::inferType(e).asClass().getName() = ["String", "NSString"] and | ||
| node.asExpr() = e | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * A taint-tracking configuration for cleartext logging vulnerabilities. | ||
| */ | ||
| module CleartextLoggingConfig implements DataFlow::ConfigSig { | ||
| predicate isSource(DataFlow::Node node) { node instanceof SensitiveData } | ||
|
|
||
| predicate isSink(DataFlow::Node node) { | ||
| Models::isSink(node, "log-injection") | ||
|
geoffw0 marked this conversation as resolved.
Resolved
|
||
| or | ||
| heuristicSink(node) | ||
| or | ||
| // TODO: port StringFormat.qll and use it, as in `PrintfCleartextLoggingSink` in the original Swift query | ||
| // TODO: then we shouldn't need this: | ||
| exists(CallExpr call | | ||
| getNameFromExpr(call.getCallee()).regexpMatch("(?i)(ns)?(log|warn(ing)?|error|print).*") and | ||
| node.asExpr() = call.getAnArgument().getValue() | ||
| ) | ||
| } | ||
|
|
||
| predicate isBarrier(DataFlow::Node node) { | ||
| none() // TODO: barriers for booleans, encrypted data, and MaD defined barriers as in original Swift | ||
| } | ||
|
|
||
| predicate isBarrierIn(DataFlow::Node node) { isSource(node) } | ||
|
|
||
| predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) { | ||
| // if `a` is sensitive, then `a.b` is also sensitive. | ||
| nodeTo.asExpr().(MemberAccessExpr).getBase() = nodeFrom.asExpr() | ||
| or | ||
| // if `a` is sensitive, then `a()` is also sensitive. | ||
| nodeTo.asExpr().(CallExpr).getCallee() = nodeFrom.asExpr() | ||
|
Contributor
Author
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. Added the test and restored the old |
||
| } | ||
| } | ||
|
|
||
| module CleartextLoggingFlow = TaintTracking::Global<CleartextLoggingConfig>; | ||
|
|
||
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.