Skip to content

Commit dddc4db

Browse files
committed
unified: Add dumb version of CleartextLogging
1 parent 3d0c97c commit dddc4db

6 files changed

Lines changed: 67 additions & 0 deletions

File tree

unified/ql/lib/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extractor: unified
66
library: true
77
upgrades: upgrades
88
dependencies:
9+
codeql/concepts: ${workspace}
910
codeql/controlflow: ${workspace}
1011
codeql/ssa: ${workspace}
1112
codeql/dataflow: ${workspace}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @name Cleartext logging of sensitive information
3+
* @description Logging sensitive information in plaintext can
4+
* expose it to an attacker.
5+
* @kind path-problem
6+
* @problem.severity error
7+
* @security-severity 7.5
8+
* @precision high
9+
* @id swift/cleartext-logging
10+
* @tags security
11+
* external/cwe/cwe-312
12+
* external/cwe/cwe-359
13+
* external/cwe/cwe-532
14+
*/
15+
16+
//
17+
// FIXME: This is a deliberately dumb and noisy version of the query used to exercise data flow early on.
18+
//
19+
import unified
20+
import codeql.concepts.internal.SensitiveDataHeuristics
21+
22+
private string getNameFromExpr(Expr e) {
23+
result = e.(IdentifierExpr).getValue()
24+
or
25+
result = e.(MemberAccessExpr).getMemberName()
26+
}
27+
28+
module DummyConfig implements DataFlow::ConfigSig {
29+
predicate isSource(DataFlow::Node node) {
30+
exists(string name |
31+
name = getNameFromExpr(node.asExpr()) and
32+
HeuristicNames::nameIndicatesSensitiveData(name)
33+
)
34+
}
35+
36+
predicate isSink(DataFlow::Node node) {
37+
exists(CallExpr call |
38+
getNameFromExpr(call.getCallee()).regexpMatch("(?i)(ns)?(log|warn(ing)?|error|print).*") and
39+
node.asExpr() = call.getAnArgument().getValue()
40+
)
41+
}
42+
43+
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
44+
}
45+
46+
module DummyFlow = TaintTracking::Global<DummyConfig>;
47+
48+
import DummyFlow::PathGraph
49+
50+
from DummyFlow::PathNode source, DummyFlow::PathNode sink
51+
where DummyFlow::flowPath(source, sink)
52+
select sink.getNode(), source, sink, "Logging of $@", source.getNode(), "sensitive data"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#select
2+
| CleartextLoggingBad.swift:2:7:2:44 | StringInterpolationExpr | CleartextLoggingBad.swift:2:35:2:42 | password : unit | CleartextLoggingBad.swift:2:7:2:44 | StringInterpolationExpr | Logging of $@ | CleartextLoggingBad.swift:2:35:2:42 | password | sensitive data |
3+
edges
4+
| CleartextLoggingBad.swift:2:35:2:42 | password : unit | CleartextLoggingBad.swift:2:7:2:44 | StringInterpolationExpr | provenance | |
5+
nodes
6+
| CleartextLoggingBad.swift:2:7:2:44 | StringInterpolationExpr | semmle.label | StringInterpolationExpr |
7+
| CleartextLoggingBad.swift:2:35:2:42 | password : unit | semmle.label | password : unit |
8+
subpaths
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: queries/security/CWE-312/CleartextLogging.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let password = "P@ssw0rd"
2+
NSLog("User password changed to \(password)") // $ Alert
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let password = "P@ssw0rd"
2+
NSLog("User password changed")

0 commit comments

Comments
 (0)