Skip to content

Commit b4968eb

Browse files
committed
refactor the SensitiveExpr to be a dataflow node
1 parent 0c4f08c commit b4968eb

File tree

9 files changed

+40
-34
lines changed

9 files changed

+40
-34
lines changed

javascript/ql/lib/semmle/javascript/frameworks/CookieLibraries.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private predicate canHaveSensitiveCookie(DataFlow::Node node) {
7676
HeuristicNames::nameIndicatesSensitiveData([s, getCookieName(s)], _)
7777
)
7878
or
79-
node.asExpr() instanceof SensitiveExpr
79+
node instanceof SensitiveNode
8080
}
8181

8282
/**

javascript/ql/lib/semmle/javascript/security/SensitiveActions.qll

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,25 @@ import javascript
1313
import semmle.javascript.security.internal.SensitiveDataHeuristics
1414
private import HeuristicNames
1515

16+
/**
17+
* DEPRECATED: Use `SensitiveNode` instead.
18+
* An expression that might contain sensitive data.
19+
*/
20+
deprecated class SensitiveExpr extends Expr {
21+
SensitiveNode node;
22+
23+
SensitiveExpr() { node.asExpr() = this }
24+
25+
/** Gets a human-readable description of this expression for use in alert messages. */
26+
deprecated string describe() { result = node.describe() }
27+
28+
/** Gets a classification of the kind of sensitive data this expression might contain. */
29+
deprecated SensitiveDataClassification getClassification() { result = node.getClassification() }
30+
}
31+
1632
/** An expression that might contain sensitive data. */
1733
cached
18-
abstract class SensitiveExpr extends Expr {
34+
abstract class SensitiveNode extends DataFlow::Node {
1935
/** Gets a human-readable description of this expression for use in alert messages. */
2036
cached
2137
abstract string describe();
@@ -26,33 +42,33 @@ abstract class SensitiveExpr extends Expr {
2642
}
2743

2844
/** A function call that might produce sensitive data. */
29-
class SensitiveCall extends SensitiveExpr, InvokeExpr {
45+
class SensitiveCall extends SensitiveNode instanceof DataFlow::InvokeNode {
3046
SensitiveDataClassification classification;
3147

3248
SensitiveCall() {
33-
classification = this.getCalleeName().(SensitiveDataFunctionName).getClassification()
49+
classification = super.getCalleeName().(SensitiveDataFunctionName).getClassification()
3450
or
3551
// This is particularly to pick up methods with an argument like "password", which
3652
// may indicate a lookup.
37-
exists(string s | this.getAnArgument().mayHaveStringValue(s) |
53+
exists(string s | super.getAnArgument().mayHaveStringValue(s) |
3854
nameIndicatesSensitiveData(s, classification)
3955
)
4056
}
4157

42-
override string describe() { result = "a call to " + this.getCalleeName() }
58+
override string describe() { result = "a call to " + super.getCalleeName() }
4359

4460
override SensitiveDataClassification getClassification() { result = classification }
4561
}
4662

4763
/** An access to a variable or property that might contain sensitive data. */
48-
abstract class SensitiveVariableAccess extends SensitiveExpr {
64+
abstract class SensitiveVariableAccess extends SensitiveNode {
4965
string name;
5066

5167
SensitiveVariableAccess() {
52-
this.(VarAccess).getName() = name
68+
this.asExpr().(VarAccess).getName() = name
5369
or
5470
exists(DataFlow::PropRead pr |
55-
this = pr.asExpr() and
71+
this = pr and
5672
pr.getPropertyName() = name
5773
)
5874
}
@@ -173,10 +189,8 @@ class ProtectCall extends DataFlow::CallNode {
173189
}
174190

175191
/** An expression that might contain a clear-text password. */
176-
class CleartextPasswordExpr extends SensitiveExpr {
177-
CleartextPasswordExpr() {
178-
this.(SensitiveExpr).getClassification() = SensitiveDataClassification::password()
179-
}
192+
class CleartextPasswordExpr extends SensitiveNode {
193+
CleartextPasswordExpr() { this.getClassification() = SensitiveDataClassification::password() }
180194

181195
override string describe() { none() }
182196

javascript/ql/lib/semmle/javascript/security/dataflow/BrokenCryptoAlgorithmCustomizations.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ module BrokenCryptoAlgorithm {
3030
* A sensitive expression, viewed as a data flow source for sensitive information
3131
* in broken or weak cryptographic algorithms.
3232
*/
33-
class SensitiveExprSource extends Source, DataFlow::ValueNode {
34-
override SensitiveExpr astNode;
35-
36-
override string describe() { result = astNode.describe() }
33+
class SensitiveExprSource extends Source instanceof SensitiveNode {
34+
override string describe() { result = SensitiveNode.super.describe() }
3735
}
3836

3937
/**

javascript/ql/lib/semmle/javascript/security/dataflow/CleartextStorageCustomizations.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@ module CleartextStorage {
3030
* A sensitive expression, viewed as a data flow source for cleartext storage
3131
* of sensitive information.
3232
*/
33-
class SensitiveExprSource extends Source, DataFlow::ValueNode {
34-
override SensitiveExpr astNode;
35-
33+
class SensitiveExprSource extends Source instanceof SensitiveNode {
3634
SensitiveExprSource() {
3735
// storing user names or account names in plaintext isn't usually a problem
38-
astNode.getClassification() != SensitiveDataClassification::id()
36+
super.getClassification() != SensitiveDataClassification::id()
3937
}
4038

41-
override string describe() { result = astNode.describe() }
39+
override string describe() { result = SensitiveNode.super.describe() }
4240
}
4341

4442
/** A call to any function whose name suggests that it encodes or encrypts its arguments. */

javascript/ql/lib/semmle/javascript/security/dataflow/InsufficientPasswordHashCustomizations.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ module InsufficientPasswordHash {
3030
* A potential clear-text password, considered as a source for password hashing
3131
* with insufficient computational effort.
3232
*/
33-
class CleartextPasswordSource extends Source, DataFlow::ValueNode {
34-
override SensitiveExpr astNode;
35-
33+
class CleartextPasswordSource extends Source instanceof SensitiveNode {
3634
CleartextPasswordSource() {
37-
astNode.getClassification() = SensitiveDataClassification::password()
35+
super.getClassification() = SensitiveDataClassification::password()
3836
}
3937

40-
override string describe() { result = astNode.describe() }
38+
override string describe() { result = SensitiveNode.super.describe() }
4139
}
4240

4341
/**

javascript/ql/lib/semmle/javascript/security/dataflow/PostMessageStarCustomizations.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ module PostMessageStar {
4141
* A sensitive expression, viewed as a data flow source for cross-window communication
4242
* with unrestricted origin.
4343
*/
44-
class SensitiveExprSource extends Source, DataFlow::ValueNode {
45-
override SensitiveExpr astNode;
46-
}
44+
class SensitiveExprSource extends Source instanceof SensitiveNode { }
4745

4846
/** A call to any function whose name suggests that it encodes or encrypts its arguments. */
4947
class ProtectSanitizer extends Sanitizer {

javascript/ql/src/Security/CWE-327/BrokenCryptoAlgorithm.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import DataFlow::PathGraph
1919
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
2020
where
2121
cfg.hasFlowPath(source, sink) and
22-
not source.getNode().asExpr() instanceof CleartextPasswordExpr // flagged by js/insufficient-password-hash
22+
not source.getNode() instanceof CleartextPasswordExpr // flagged by js/insufficient-password-hash
2323
select sink.getNode(), source, sink,
2424
"Sensitive data from $@ is used in a broken or weak cryptographic algorithm.", source.getNode(),
2525
source.getNode().(Source).describe()

javascript/ql/src/Security/CWE-598/SensitiveGetQuery.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import javascript
1515

1616
from
1717
Routing::RouteSetup setup, Routing::RouteHandler handler, HTTP::RequestInputAccess input,
18-
SensitiveExpr sensitive
18+
SensitiveNode sensitive
1919
where
2020
setup.getOwnHttpMethod() = "GET" and
2121
setup.getAChild+() = handler and
2222
input.getRouteHandler() = handler.getFunction() and
2323
input.getKind() = "parameter" and
24-
input.(DataFlow::SourceNode).flowsToExpr(sensitive) and
24+
input.(DataFlow::SourceNode).flowsTo(sensitive) and
2525
not sensitive.getClassification() = SensitiveDataClassification::id()
2626
select input, "$@ for GET requests uses query parameter as sensitive data.", handler,
2727
"Route handler"

javascript/ql/test/library-tests/SensitiveActions/tests.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ query predicate processTermination(NodeJSLib::ProcessTermination term) { any() }
2020

2121
query predicate sensitiveAction(SensitiveAction ac) { any() }
2222

23-
query predicate sensitiveExpr(SensitiveExpr e) { any() }
23+
query predicate sensitiveExpr(SensitiveNode e) { any() }

0 commit comments

Comments
 (0)