Skip to content

Commit bcc1669

Browse files
committed
JS: Migrate InsecureDownload
1 parent 4e25036 commit bcc1669

File tree

2 files changed

+61
-19
lines changed

2 files changed

+61
-19
lines changed

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

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,52 @@ import javascript
1010
* Classes and predicates for reasoning about download of sensitive file through insecure connection vulnerabilities.
1111
*/
1212
module InsecureDownload {
13+
private newtype TFlowState =
14+
TSensitiveInsecureUrl() or
15+
TInsecureUrl()
16+
17+
/** A flow state to associate with a tracked value. */
18+
class FlowState extends TFlowState {
19+
/** Gets a string representation fo this flow state */
20+
string toString() {
21+
this = TSensitiveInsecureUrl() and result = "sensitive-insecure-url"
22+
or
23+
this = TInsecureUrl() and result = "insecure-url"
24+
}
25+
26+
deprecated DataFlow::FlowLabel toFlowLabel() {
27+
this = TSensitiveInsecureUrl() and result instanceof Label::SensitiveInsecureUrl
28+
or
29+
this = TInsecureUrl() and result instanceof Label::InsecureUrl
30+
}
31+
}
32+
33+
/** Predicates for working with flow states. */
34+
module FlowState {
35+
deprecated FlowState fromFlowLabel(DataFlow::FlowLabel label) { result.toFlowLabel() = label }
36+
37+
/**
38+
* A file URL that is both sensitive and downloaded over an insecure connection.
39+
*/
40+
FlowState sensitiveInsecureUrl() { result = TSensitiveInsecureUrl() }
41+
42+
/**
43+
* A URL that is downloaded over an insecure connection.
44+
*/
45+
FlowState insecureUrl() { result = TInsecureUrl() }
46+
}
47+
1348
/**
1449
* A data flow source for download of sensitive file through insecure connection.
1550
*/
1651
abstract class Source extends DataFlow::Node {
1752
/**
18-
* Gets a flow-label for this source.
53+
* Gets a flow state for this source.
1954
*/
20-
abstract DataFlow::FlowLabel getALabel();
55+
FlowState getAFlowState() { result = FlowState::insecureUrl() }
56+
57+
/** DEPRECATED. Use `getAFlowState()` instead. */
58+
deprecated DataFlow::FlowLabel getALabel() { result = this.getAFlowState().toFlowLabel() }
2159
}
2260

2361
/**
@@ -30,9 +68,14 @@ module InsecureDownload {
3068
abstract DataFlow::Node getDownloadCall();
3169

3270
/**
33-
* Gets a flow-label where this sink is vulnerable.
71+
* Gets a flow state where this sink is vulnerable.
3472
*/
35-
abstract DataFlow::FlowLabel getALabel();
73+
FlowState getAFlowState() {
74+
result = [FlowState::insecureUrl(), FlowState::sensitiveInsecureUrl()]
75+
}
76+
77+
/** DEPRECATED. Use `getAFlowState()` instead. */
78+
deprecated DataFlow::FlowLabel getALabel() { result = this.getAFlowState().toFlowLabel() }
3679
}
3780

3881
/**
@@ -71,11 +114,11 @@ module InsecureDownload {
71114
str.regexpMatch("http://.*|ftp://.*")
72115
}
73116

74-
override DataFlow::FlowLabel getALabel() {
75-
result instanceof Label::InsecureUrl
117+
override FlowState getAFlowState() {
118+
result = FlowState::insecureUrl()
76119
or
77120
hasUnsafeExtension(str) and
78-
result instanceof Label::SensitiveInsecureUrl
121+
result = FlowState::sensitiveInsecureUrl()
79122
}
80123
}
81124

@@ -113,11 +156,11 @@ module InsecureDownload {
113156

114157
override DataFlow::Node getDownloadCall() { result = request }
115158

116-
override DataFlow::FlowLabel getALabel() {
117-
result instanceof Label::SensitiveInsecureUrl
159+
override FlowState getAFlowState() {
160+
result = FlowState::sensitiveInsecureUrl()
118161
or
119162
hasUnsafeExtension(request.getASavePath().getStringValue()) and
120-
result instanceof Label::InsecureUrl
163+
result = FlowState::insecureUrl()
121164
}
122165
}
123166

@@ -145,7 +188,7 @@ module InsecureDownload {
145188
)
146189
}
147190

148-
override DataFlow::FlowLabel getALabel() { result instanceof Label::InsecureUrl }
191+
override FlowState getAFlowState() { result = FlowState::insecureUrl() }
149192

150193
override DataFlow::Node getDownloadCall() { result = request }
151194
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@
88

99
import javascript
1010
import InsecureDownloadCustomizations::InsecureDownload
11+
private import InsecureDownloadCustomizations::InsecureDownload as InsecureDownload
1112

1213
/**
1314
* A taint tracking configuration for download of sensitive file through insecure connection.
1415
*/
1516
module InsecureDownloadConfig implements DataFlow::StateConfigSig {
16-
class FlowState = DataFlow::FlowLabel;
17+
class FlowState = InsecureDownload::FlowState;
1718

18-
predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) {
19-
source.(Source).getALabel() = label
19+
predicate isSource(DataFlow::Node source, FlowState state) {
20+
source.(Source).getAFlowState() = state
2021
}
2122

22-
predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel label) {
23-
sink.(Sink).getALabel() = label
24-
}
23+
predicate isSink(DataFlow::Node sink, FlowState state) { sink.(Sink).getAFlowState() = state }
2524

2625
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
2726
}
@@ -38,11 +37,11 @@ deprecated class Configuration extends DataFlow::Configuration {
3837
Configuration() { this = "InsecureDownload" }
3938

4039
override predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) {
41-
InsecureDownloadConfig::isSource(source, label)
40+
InsecureDownloadConfig::isSource(source, FlowState::fromFlowLabel(label))
4241
}
4342

4443
override predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel label) {
45-
InsecureDownloadConfig::isSink(sink, label)
44+
InsecureDownloadConfig::isSink(sink, FlowState::fromFlowLabel(label))
4645
}
4746

4847
override predicate isBarrier(DataFlow::Node node) {

0 commit comments

Comments
 (0)