Skip to content

Commit a4449b4

Browse files
committed
Java: Diff-informed CleartextStorageCookie.ql
This query shares implementation with several other queries about cleartext storage, but it's the only one of them that's in the code-scanning suite. The sharing mechanism remains the same as before, but now each query has to override `getASelectedLocation` to become diff-informed. Two other data-flow configurations are used in this query, but they can't easily be made diff-informed.
1 parent 29b37a4 commit a4449b4

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

java/ql/lib/semmle/code/java/security/CleartextStorageCookieQuery.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ private import semmle.code.java.dataflow.FlowSinks
77
private import semmle.code.java.dataflow.FlowSources
88

99
private class CookieCleartextStorageSink extends CleartextStorageSink {
10-
CookieCleartextStorageSink() { this.asExpr() = cookieInput(_) }
10+
Cookie cookie;
11+
12+
CookieCleartextStorageSink() { this.asExpr() = cookieInput(cookie) }
13+
14+
override Location getASelectedLocation() {
15+
result = this.getLocation()
16+
or
17+
result = cookie.getLocation()
18+
or
19+
result = cookie.getAStore().getLocation()
20+
}
1121
}
1222

1323
/** The instantiation of a cookie, which can act as storage. */

java/ql/lib/semmle/code/java/security/CleartextStorageQuery.qll

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ private import semmle.code.java.dataflow.TaintTracking
55
private import semmle.code.java.security.SensitiveActions
66

77
/** A sink representing persistent storage that saves data in clear text. */
8-
abstract class CleartextStorageSink extends DataFlow::Node { }
8+
abstract class CleartextStorageSink extends DataFlow::Node {
9+
/**
10+
* Gets a location that will be selected in the diff-informed query where
11+
* this sink is found. If this has no results for any sink, that's taken to
12+
* mean the query is not diff-informed.
13+
*/
14+
Location getASelectedLocation() { none() }
15+
}
916

1017
/** A sanitizer for flows tracking sensitive data being stored in persistent storage. */
1118
abstract class CleartextStorageSanitizer extends DataFlow::Node { }
@@ -46,6 +53,17 @@ private module SensitiveSourceFlowConfig implements DataFlow::ConfigSig {
4653
predicate isAdditionalFlowStep(DataFlow::Node n1, DataFlow::Node n2) {
4754
any(CleartextStorageAdditionalTaintStep c).step(n1, n2)
4855
}
56+
57+
predicate observeDiffInformedIncrementalMode() {
58+
// This configuration is used by several queries. A query can opt in to
59+
// diff-informed mode by implementing `getASelectedLocation` on its sinks,
60+
// indicating that it has considered which sinks are selected.
61+
exists(CleartextStorageSink sink | exists(sink.getASelectedLocation()))
62+
}
63+
64+
Location getASelectedSinkLocation(DataFlow::Node sink) {
65+
result = sink.(CleartextStorageSink).getASelectedLocation()
66+
}
4967
}
5068

5169
private module SensitiveSourceFlow = TaintTracking::Global<SensitiveSourceFlowConfig>;

0 commit comments

Comments
 (0)