Skip to content

Commit dafca8f

Browse files
committed
introduce flow-labels to js/insecure-download
1 parent 9bdedb3 commit dafca8f

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

javascript/ql/src/semmle/javascript/security/dataflow/InsecureDownload.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ module InsecureDownload {
2020
class Configuration extends DataFlow::Configuration {
2121
Configuration() { this = "InsecureDownload" }
2222

23-
override predicate isSource(DataFlow::Node source) { source instanceof Source }
23+
override predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) {
24+
source.(Source).getALabel() = label
25+
}
2426

25-
override predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
27+
override predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel label) {
28+
sink.(Sink).getALabel() = label
29+
}
2630
}
2731
}

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

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ module InsecureDownload {
1313
/**
1414
* A data flow source for download of sensitive file through insecure connection.
1515
*/
16-
abstract class Source extends DataFlow::Node { }
16+
abstract class Source extends DataFlow::Node {
17+
/**
18+
* Gets a flow-label for this source
19+
*/
20+
abstract DataFlow::FlowLabel getALabel();
21+
}
1722

1823
/**
1924
* A data flow sink for download of sensitive file through insecure connection.
@@ -23,25 +28,50 @@ module InsecureDownload {
2328
* Gets the call that downloads the sensitive file.
2429
*/
2530
abstract DataFlow::Node getDownloadCall();
31+
32+
/**
33+
* Gets a flow-label where this sink is vulnerable.
34+
*/
35+
abstract DataFlow::FlowLabel getALabel();
2636
}
2737

2838
/**
2939
* A sanitizer for download of sensitive file through insecure connection.
3040
*/
3141
abstract class Sanitizer extends DataFlow::Node { }
3242

43+
module Label {
44+
/**
45+
* A flow-label for file URLs that are both sensitive and downloaded over an insecure connection.
46+
*/
47+
class SensitiveInsecureURL extends DataFlow::FlowLabel {
48+
SensitiveInsecureURL() { this = "sensitiveInsecure" }
49+
}
50+
51+
class InsecureURL extends DataFlow::FlowLabel {
52+
InsecureURL() { this = "insecure" }
53+
}
54+
}
55+
3356
/**
3457
* A HTTP or FTP URL that refers to a file with a sensitive file extension,
3558
* seen as a source for download of sensitive file through insecure connection.
3659
*/
3760
class SensitiveFileUrl extends Source {
61+
string str;
62+
3863
SensitiveFileUrl() {
39-
exists(string str | str = this.getStringValue() |
40-
str.regexpMatch("http://.*|ftp://.*") and
41-
exists(string suffix | suffix = unsafeExtension() |
42-
str.suffix(str.length() - suffix.length() - 1).toLowerCase() = "." + suffix
43-
)
44-
)
64+
str = this.getStringValue() and
65+
str.regexpMatch("http://.*|ftp://.*")
66+
}
67+
68+
override DataFlow::FlowLabel getALabel() {
69+
result instanceof Label::InsecureURL
70+
or
71+
exists(string suffix | suffix = unsafeExtension() |
72+
str.suffix(str.length() - suffix.length() - 1).toLowerCase() = "." + suffix
73+
) and
74+
result instanceof Label::SensitiveInsecureURL
4575
}
4676
}
4777

@@ -58,13 +88,17 @@ module InsecureDownload {
5888

5989
/**
6090
* A url downloaded by a client-request, seen as a sink for download of
61-
* sensitive file through insecure connection.a
91+
* sensitive file through insecure connection.
6292
*/
6393
class ClientRequestURL extends Sink {
6494
ClientRequest request;
6595

6696
ClientRequestURL() { this = request.getUrl() }
6797

6898
override DataFlow::Node getDownloadCall() { result = request }
99+
100+
override DataFlow::FlowLabel getALabel() {
101+
result instanceof Label::SensitiveInsecureURL // TODO: Also non-sensitive.
102+
}
69103
}
70104
}

javascript/ql/test/query-tests/Security/CWE-829/insecure-download.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ function baz() {
4040

4141
nugget("ftp://example.org/unsafe.APK") // NOT OK
4242
}
43+
44+
const fs = require("fs");
45+
var writeFileAtomic = require("write-file-atomic");
46+
47+
function test() {
48+
nugget("http://example.org/unsafe", {target: "foo.exe"}, () => { }) // NOT OK
49+
}

0 commit comments

Comments
 (0)