Skip to content

Commit e23ff9c

Browse files
committed
Add TypedArrays flow summaries for Uint8Array and buffer property
1 parent 9388226 commit e23ff9c

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

javascript/ql/lib/semmle/javascript/internal/flow_summaries/AllFlowSummaries.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ private import Sets
1212
private import Strings
1313
private import DynamicImportStep
1414
private import UrlSearchParams
15+
private import TypedArrays
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
private import javascript
2+
private import semmle.javascript.dataflow.FlowSummary
3+
private import semmle.javascript.dataflow.InferredTypes
4+
private import semmle.javascript.dataflow.internal.DataFlowPrivate as Private
5+
private import FlowSummaryUtil
6+
7+
private class TypedArrayEntryPoint extends API::EntryPoint {
8+
TypedArrayEntryPoint() { this = "global.Uint8Array" }
9+
10+
override DataFlow::SourceNode getASource() { result = DataFlow::globalVarRef("Uint8Array") }
11+
}
12+
13+
pragma[nomagic]
14+
API::Node typedArrayConstructorRef() { result = any(TypedArrayEntryPoint e).getANode() }
15+
16+
class TypedArrayConstructorSummary extends SummarizedCallable {
17+
TypedArrayConstructorSummary() { this = "TypedArray constructor" }
18+
19+
override DataFlow::InvokeNode getACall() {
20+
result = typedArrayConstructorRef().getAnInstantiation()
21+
}
22+
23+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
24+
preservesValue = true and
25+
input = "Argument[0].ArrayElement" and
26+
output = "ReturnValue.ArrayElement"
27+
}
28+
}
29+
30+
class BufferTypedArray extends DataFlow::AdditionalFlowStep {
31+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
32+
exists(DataFlow::PropRead p |
33+
p = typedArrayConstructorRef().getInstance().getMember("buffer").asSource() and
34+
pred = p.getBase() and
35+
succ = p
36+
)
37+
}
38+
}

javascript/ql/test/library-tests/TaintTracking/BasicTaintTracking.expected

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ legacyDataFlowDifference
3535
| spread.js:4:15:4:22 | source() | spread.js:18:8:18:8 | y | only flow with NEW data flow library |
3636
| spread.js:4:15:4:22 | source() | spread.js:24:8:24:8 | y | only flow with NEW data flow library |
3737
| tst.js:2:13:2:20 | source() | tst.js:17:10:17:10 | a | only flow with OLD data flow library |
38+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:5:10:5:10 | y | only flow with NEW data flow library |
39+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:7:10:7:17 | y.buffer | only flow with NEW data flow library |
40+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:11:10:11:12 | arr | only flow with NEW data flow library |
3841
| use-use-after-implicit-read.js:7:17:7:24 | source() | use-use-after-implicit-read.js:15:10:15:10 | x | only flow with NEW data flow library |
3942
consistencyIssue
4043
| nested-props.js:20 | expected an alert, but found none | NOT OK - but not found | Consistency |
4144
| stringification-read-steps.js:17 | expected an alert, but found none | NOT OK | Consistency |
4245
| stringification-read-steps.js:25 | expected an alert, but found none | NOT OK | Consistency |
43-
| typed-arrays.js:5 | expected an alert, but found none | NOT OK | Consistency |
44-
| typed-arrays.js:7 | expected an alert, but found none | NOT OK | Consistency |
45-
| typed-arrays.js:11 | expected an alert, but found none | NOT OK | Consistency |
4646
flow
4747
| access-path-sanitizer.js:2:18:2:25 | source() | access-path-sanitizer.js:4:8:4:12 | obj.x |
4848
| addexpr.js:4:10:4:17 | source() | addexpr.js:7:8:7:8 | x |
@@ -328,6 +328,9 @@ flow
328328
| tst.js:87:22:87:29 | source() | tst.js:90:14:90:25 | taintedValue |
329329
| tst.js:93:22:93:29 | source() | tst.js:96:14:96:25 | taintedValue |
330330
| tst.js:93:22:93:29 | source() | tst.js:97:14:97:26 | map.get(true) |
331+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:5:10:5:10 | y |
332+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:7:10:7:17 | y.buffer |
333+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:11:10:11:12 | arr |
331334
| use-use-after-implicit-read.js:7:17:7:24 | source() | use-use-after-implicit-read.js:8:10:8:17 | captured |
332335
| use-use-after-implicit-read.js:7:17:7:24 | source() | use-use-after-implicit-read.js:15:10:15:10 | x |
333336
| xml.js:5:18:5:25 | source() | xml.js:8:14:8:17 | text |

javascript/ql/test/query-tests/Security/CWE-522-DecompressionBombs/DecompressionBombs.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ edges
8181
| pako.js:18:48:18:66 | zipFile.data.buffer | pako.js:18:33:18:67 | new Uin ... buffer) | provenance | Config |
8282
| pako.js:28:19:28:25 | zipFile | pako.js:29:36:29:42 | zipFile | provenance | |
8383
| pako.js:29:11:29:62 | myArray | pako.js:32:31:32:37 | myArray | provenance | |
84+
| pako.js:29:11:29:62 | myArray [ArrayElement] | pako.js:32:31:32:37 | myArray | provenance | |
8485
| pako.js:29:21:29:55 | new Uin ... buffer) | pako.js:29:11:29:62 | myArray | provenance | |
86+
| pako.js:29:21:29:55 | new Uin ... buffer) [ArrayElement] | pako.js:29:11:29:62 | myArray [ArrayElement] | provenance | |
8587
| pako.js:29:36:29:42 | zipFile | pako.js:29:36:29:54 | zipFile.data.buffer | provenance | |
8688
| pako.js:29:36:29:54 | zipFile.data.buffer | pako.js:29:21:29:55 | new Uin ... buffer) | provenance | Config |
89+
| pako.js:29:36:29:54 | zipFile.data.buffer | pako.js:29:21:29:55 | new Uin ... buffer) [ArrayElement] | provenance | |
8790
| unbzip2.js:12:5:12:43 | fs.crea ... lePath) | unbzip2.js:12:50:12:54 | bz2() | provenance | Config |
8891
| unbzip2.js:12:25:12:42 | req.query.FilePath | unbzip2.js:12:5:12:43 | fs.crea ... lePath) | provenance | Config |
8992
| unzipper.js:13:26:13:62 | Readabl ... e.data) | unzipper.js:16:23:16:63 | unzippe ... ath' }) | provenance | Config |
@@ -183,7 +186,9 @@ nodes
183186
| pako.js:21:31:21:37 | myArray | semmle.label | myArray |
184187
| pako.js:28:19:28:25 | zipFile | semmle.label | zipFile |
185188
| pako.js:29:11:29:62 | myArray | semmle.label | myArray |
189+
| pako.js:29:11:29:62 | myArray [ArrayElement] | semmle.label | myArray [ArrayElement] |
186190
| pako.js:29:21:29:55 | new Uin ... buffer) | semmle.label | new Uin ... buffer) |
191+
| pako.js:29:21:29:55 | new Uin ... buffer) [ArrayElement] | semmle.label | new Uin ... buffer) [ArrayElement] |
187192
| pako.js:29:36:29:42 | zipFile | semmle.label | zipFile |
188193
| pako.js:29:36:29:54 | zipFile.data.buffer | semmle.label | zipFile.data.buffer |
189194
| pako.js:32:31:32:37 | myArray | semmle.label | myArray |

0 commit comments

Comments
 (0)