Skip to content

Commit 893f4ab

Browse files
authored
Merge pull request github#9288 from asgerf/js/resource-exhaustion-no-buffer.from
JS: Remove Buffer.from sink from js/resource-exhaustion
2 parents 67572bb + 4913a7a commit 893f4ab

File tree

4 files changed

+10
-26
lines changed

4 files changed

+10
-26
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,8 @@ module ResourceExhaustion {
7878
exists(DataFlow::SourceNode clazz, DataFlow::InvokeNode invk, int index |
7979
clazz = DataFlow::globalVarRef("Buffer") and this = invk.getArgument(index)
8080
|
81-
exists(string name |
82-
invk = clazz.getAMemberCall(name) and
83-
(
84-
name = "from" and index = 2 // the length argument
85-
or
86-
name = ["alloc", "allocUnsafe", "allocUnsafeSlow"] and index = 0 // the buffer size
87-
)
88-
)
81+
invk = clazz.getAMemberCall(["alloc", "allocUnsafe", "allocUnsafeSlow"]) and
82+
index = 0 // the buffer size
8983
or
9084
invk = clazz.getAnInvocation() and
9185
(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `js/resource-exhaustion` query no longer treats the 3-argument version of `Buffer.from` as a sink,
5+
since it does not allocate a new buffer.

javascript/ql/test/query-tests/Security/CWE-770/ResourceExhaustion/ResourceExhaustion.expected

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ nodes
1717
| resource-exhaustion.js:6:7:6:21 | n |
1818
| resource-exhaustion.js:6:11:6:21 | parseInt(s) |
1919
| resource-exhaustion.js:6:20:6:20 | s |
20-
| resource-exhaustion.js:11:21:11:21 | s |
21-
| resource-exhaustion.js:11:21:11:21 | s |
22-
| resource-exhaustion.js:12:21:12:21 | n |
23-
| resource-exhaustion.js:12:21:12:21 | n |
24-
| resource-exhaustion.js:13:21:13:21 | n |
25-
| resource-exhaustion.js:13:21:13:21 | n |
2620
| resource-exhaustion.js:14:16:14:16 | n |
2721
| resource-exhaustion.js:14:16:14:16 | n |
2822
| resource-exhaustion.js:15:22:15:22 | n |
@@ -71,8 +65,6 @@ edges
7165
| documentaion-examples/ResourceExhaustion_timeout.js:5:33:5:39 | req.url | documentaion-examples/ResourceExhaustion_timeout.js:5:23:5:46 | url.par ... , true) |
7266
| documentaion-examples/ResourceExhaustion_timeout.js:5:33:5:39 | req.url | documentaion-examples/ResourceExhaustion_timeout.js:5:23:5:46 | url.par ... , true) |
7367
| resource-exhaustion.js:5:7:5:42 | s | resource-exhaustion.js:6:20:6:20 | s |
74-
| resource-exhaustion.js:5:7:5:42 | s | resource-exhaustion.js:11:21:11:21 | s |
75-
| resource-exhaustion.js:5:7:5:42 | s | resource-exhaustion.js:11:21:11:21 | s |
7668
| resource-exhaustion.js:5:7:5:42 | s | resource-exhaustion.js:35:12:35:12 | s |
7769
| resource-exhaustion.js:5:7:5:42 | s | resource-exhaustion.js:35:12:35:12 | s |
7870
| resource-exhaustion.js:5:7:5:42 | s | resource-exhaustion.js:82:17:82:17 | s |
@@ -84,10 +76,6 @@ edges
8476
| resource-exhaustion.js:5:11:5:42 | url.par ... query.s | resource-exhaustion.js:5:7:5:42 | s |
8577
| resource-exhaustion.js:5:21:5:27 | req.url | resource-exhaustion.js:5:11:5:34 | url.par ... , true) |
8678
| resource-exhaustion.js:5:21:5:27 | req.url | resource-exhaustion.js:5:11:5:34 | url.par ... , true) |
87-
| resource-exhaustion.js:6:7:6:21 | n | resource-exhaustion.js:12:21:12:21 | n |
88-
| resource-exhaustion.js:6:7:6:21 | n | resource-exhaustion.js:12:21:12:21 | n |
89-
| resource-exhaustion.js:6:7:6:21 | n | resource-exhaustion.js:13:21:13:21 | n |
90-
| resource-exhaustion.js:6:7:6:21 | n | resource-exhaustion.js:13:21:13:21 | n |
9179
| resource-exhaustion.js:6:7:6:21 | n | resource-exhaustion.js:14:16:14:16 | n |
9280
| resource-exhaustion.js:6:7:6:21 | n | resource-exhaustion.js:14:16:14:16 | n |
9381
| resource-exhaustion.js:6:7:6:21 | n | resource-exhaustion.js:15:22:15:22 | n |
@@ -124,9 +112,6 @@ edges
124112
| resource-exhaustion.js:6:20:6:20 | s | resource-exhaustion.js:6:11:6:21 | parseInt(s) |
125113
#select
126114
| documentaion-examples/ResourceExhaustion_timeout.js:7:16:7:20 | delay | documentaion-examples/ResourceExhaustion_timeout.js:5:33:5:39 | req.url | documentaion-examples/ResourceExhaustion_timeout.js:7:16:7:20 | delay | This creates a timer with a user-controlled duration from $@. | documentaion-examples/ResourceExhaustion_timeout.js:5:33:5:39 | req.url | here |
127-
| resource-exhaustion.js:11:21:11:21 | s | resource-exhaustion.js:5:21:5:27 | req.url | resource-exhaustion.js:11:21:11:21 | s | This creates a buffer with a user-controlled size from $@. | resource-exhaustion.js:5:21:5:27 | req.url | here |
128-
| resource-exhaustion.js:12:21:12:21 | n | resource-exhaustion.js:5:21:5:27 | req.url | resource-exhaustion.js:12:21:12:21 | n | This creates a buffer with a user-controlled size from $@. | resource-exhaustion.js:5:21:5:27 | req.url | here |
129-
| resource-exhaustion.js:13:21:13:21 | n | resource-exhaustion.js:5:21:5:27 | req.url | resource-exhaustion.js:13:21:13:21 | n | This creates a buffer with a user-controlled size from $@. | resource-exhaustion.js:5:21:5:27 | req.url | here |
130115
| resource-exhaustion.js:14:16:14:16 | n | resource-exhaustion.js:5:21:5:27 | req.url | resource-exhaustion.js:14:16:14:16 | n | This creates a buffer with a user-controlled size from $@. | resource-exhaustion.js:5:21:5:27 | req.url | here |
131116
| resource-exhaustion.js:15:22:15:22 | n | resource-exhaustion.js:5:21:5:27 | req.url | resource-exhaustion.js:15:22:15:22 | n | This creates a buffer with a user-controlled size from $@. | resource-exhaustion.js:5:21:5:27 | req.url | here |
132117
| resource-exhaustion.js:16:26:16:26 | n | resource-exhaustion.js:5:21:5:27 | req.url | resource-exhaustion.js:16:26:16:26 | n | This creates a buffer with a user-controlled size from $@. | resource-exhaustion.js:5:21:5:27 | req.url | here |

javascript/ql/test/query-tests/Security/CWE-770/ResourceExhaustion/resource-exhaustion.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ var server = http.createServer(function(req, res) {
88
Buffer.from(s); // OK
99
Buffer.from(n); // OK
1010
Buffer.from(x, n); // OK
11-
Buffer.from(x, y, s); // NOT OK
12-
Buffer.from(x, y, n); // NOT OK
13-
Buffer.from(x, y, n); // NOT OK
11+
Buffer.from(x, y, s); // OK - does not allocate memory
12+
Buffer.from(x, y, n); // OK - does not allocate memory
13+
Buffer.from(x, y, n); // OK - does not allocate memory
1414
Buffer.alloc(n); // NOT OK
1515
Buffer.allocUnsafe(n); // NOT OK
1616
Buffer.allocUnsafeSlow(n); // NOT OK

0 commit comments

Comments
 (0)