Skip to content

Commit d86b7f6

Browse files
committed
recognize an access to the arguments object as library-input
1 parent 7b1ef74 commit d86b7f6

File tree

9 files changed

+44
-7
lines changed

9 files changed

+44
-7
lines changed

javascript/ql/lib/semmle/javascript/PackageExports.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ private import semmle.javascript.internal.CachedStages
1111
* Gets a parameter that is a library input to a top-level package.
1212
*/
1313
cached
14-
DataFlow::SourceNode getALibraryInputParameter() {
14+
DataFlow::Node getALibraryInputParameter() {
1515
Stages::Taint::ref() and
1616
exists(int bound, DataFlow::FunctionNode func |
1717
func = getAValueExportedByPackage().getABoundFunctionValue(bound)
1818
|
1919
result = func.getParameter(any(int arg | arg >= bound))
2020
or
2121
result = getAnArgumentsRead(func.getFunction())
22+
or
23+
result = func.getFunction().getArgumentsVariable().getAnAccess().flow()
2224
)
2325
}
2426

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module PrototypePollutingAssignment {
6868
/**
6969
* A parameter of an exported function, seen as a source prototype-polluting assignment.
7070
*/
71-
class ExternalInputSource extends Source, DataFlow::SourceNode {
71+
class ExternalInputSource extends Source {
7272
ExternalInputSource() { this = Exports::getALibraryInputParameter() }
7373

7474
override string describe() { result = "library input" }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ module UnsafeCodeConstruction {
2121
/**
2222
* A parameter of an exported function, seen as a source.
2323
*/
24-
class ExternalInputSource extends Source, DataFlow::ParameterNode {
24+
class ExternalInputSource extends Source {
2525
ExternalInputSource() {
2626
this = Exports::getALibraryInputParameter() and
2727
// permit parameters that clearly are intended to contain executable code.
28-
not this.getName() = "code"
28+
not this.(DataFlow::ParameterNode).getName() = "code"
2929
}
3030
}
3131

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module UnsafeHtmlConstruction {
2222
/**
2323
* A parameter of an exported function, seen as a source for usnafe HTML constructed from input.
2424
*/
25-
class ExternalInputSource extends Source, DataFlow::ParameterNode {
25+
class ExternalInputSource extends Source {
2626
ExternalInputSource() {
2727
this = Exports::getALibraryInputParameter() and
2828
// An AMD-style module sometimes loads the jQuery library in a way which looks like library input.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module UnsafeShellCommandConstruction {
4949
/**
5050
* A parameter of an exported function, seen as a source for shell command constructed from library input.
5151
*/
52-
class ExternalInputSource extends Source, DataFlow::SourceNode {
52+
class ExternalInputSource extends Source {
5353
ExternalInputSource() {
5454
this = Exports::getALibraryInputParameter() and
5555
not (

javascript/ql/lib/semmle/javascript/security/regexp/PolynomialReDoSCustomizations.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ module PolynomialReDoS {
138138
/**
139139
* A parameter of an exported function, seen as a source for polynomial-redos.
140140
*/
141-
class ExternalInputSource extends Source, DataFlow::SourceNode {
141+
class ExternalInputSource extends Source {
142142
ExternalInputSource() { this = Exports::getALibraryInputParameter() }
143143

144144
override string getKind() { result = "library" }

javascript/ql/test/query-tests/Security/CWE-400/ReDoS/PolynomialBackTracking.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
| lib/lib.js:1:15:1:16 | a* | Strings with many repetitions of 'a' can start matching anywhere after the start of the preceeding a*b |
3333
| lib/lib.js:8:3:8:4 | f* | Strings with many repetitions of 'f' can start matching anywhere after the start of the preceeding f*g |
3434
| lib/lib.js:28:3:28:4 | f* | Strings with many repetitions of 'f' can start matching anywhere after the start of the preceeding f*g |
35+
| lib/lib.js:36:3:36:4 | f* | Strings with many repetitions of 'f' can start matching anywhere after the start of the preceeding f*g |
3536
| lib/moduleLib/moduleLib.js:2:3:2:4 | a* | Strings with many repetitions of 'a' can start matching anywhere after the start of the preceeding a*b |
3637
| lib/otherLib/js/src/index.js:2:3:2:4 | a* | Strings with many repetitions of 'a' can start matching anywhere after the start of the preceeding a*b |
3738
| lib/snapdragon.js:7:28:7:29 | a* | Strings starting with 'a' and with many repetitions of 'a' can start matching anywhere after the start of the preceeding aa*$ |

javascript/ql/test/query-tests/Security/CWE-400/ReDoS/lib/lib.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ module.exports.safe = function (x) {
2828
/f*g/.test(y); // OK
2929
}
3030

31+
module.exports.useArguments = function () {
32+
usedWithArguments.apply(this, arguments);
33+
}
34+
35+
function usedWithArguments(name) {
36+
/f*g/.test(name); // NOT OK - bit not yet recognized [INCONSITENCY]
37+
}
38+
3139
module.exports.snapdragon = require("./snapdragon")

javascript/ql/test/query-tests/Security/CWE-915/PrototypePollutingAssignment/PrototypePollutingAssignment.expected

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ nodes
2626
| lib.js:15:7:15:10 | path |
2727
| lib.js:15:7:15:13 | path[0] |
2828
| lib.js:20:7:20:25 | path |
29+
| lib.js:20:14:20:22 | arguments |
30+
| lib.js:20:14:20:22 | arguments |
2931
| lib.js:20:14:20:25 | arguments[1] |
3032
| lib.js:20:14:20:25 | arguments[1] |
3133
| lib.js:22:3:22:14 | obj[path[0]] |
@@ -45,7 +47,12 @@ nodes
4547
| lib.js:34:3:34:14 | obj[path[0]] |
4648
| lib.js:34:7:34:10 | path |
4749
| lib.js:34:7:34:13 | path[0] |
50+
| lib.js:38:9:38:36 | args |
51+
| lib.js:38:16:38:36 | Array.f ... uments) |
52+
| lib.js:38:27:38:35 | arguments |
53+
| lib.js:38:27:38:35 | arguments |
4854
| lib.js:40:7:40:20 | path |
55+
| lib.js:40:14:40:17 | args |
4956
| lib.js:40:14:40:20 | args[1] |
5057
| lib.js:40:14:40:20 | args[1] |
5158
| lib.js:42:3:42:14 | obj[path[0]] |
@@ -71,6 +78,8 @@ nodes
7178
| lib.js:70:17:70:20 | path |
7279
| lib.js:70:17:70:23 | path[0] |
7380
| lib.js:83:7:83:25 | path |
81+
| lib.js:83:14:83:22 | arguments |
82+
| lib.js:83:14:83:22 | arguments |
7483
| lib.js:83:14:83:25 | arguments[1] |
7584
| lib.js:83:14:83:25 | arguments[1] |
7685
| lib.js:86:7:86:26 | proto |
@@ -89,6 +98,8 @@ nodes
8998
| lib.js:95:3:95:12 | maybeProto |
9099
| lib.js:95:3:95:12 | maybeProto |
91100
| lib.js:104:7:104:24 | one |
101+
| lib.js:104:13:104:21 | arguments |
102+
| lib.js:104:13:104:21 | arguments |
92103
| lib.js:104:13:104:24 | arguments[1] |
93104
| lib.js:104:13:104:24 | arguments[1] |
94105
| lib.js:108:3:108:10 | obj[one] |
@@ -183,6 +194,8 @@ edges
183194
| lib.js:15:7:15:13 | path[0] | lib.js:15:3:15:14 | obj[path[0]] |
184195
| lib.js:15:7:15:13 | path[0] | lib.js:15:3:15:14 | obj[path[0]] |
185196
| lib.js:20:7:20:25 | path | lib.js:22:7:22:10 | path |
197+
| lib.js:20:14:20:22 | arguments | lib.js:20:14:20:25 | arguments[1] |
198+
| lib.js:20:14:20:22 | arguments | lib.js:20:14:20:25 | arguments[1] |
186199
| lib.js:20:14:20:25 | arguments[1] | lib.js:20:7:20:25 | path |
187200
| lib.js:20:14:20:25 | arguments[1] | lib.js:20:7:20:25 | path |
188201
| lib.js:22:7:22:10 | path | lib.js:22:7:22:13 | path[0] |
@@ -199,7 +212,12 @@ edges
199212
| lib.js:34:7:34:10 | path | lib.js:34:7:34:13 | path[0] |
200213
| lib.js:34:7:34:13 | path[0] | lib.js:34:3:34:14 | obj[path[0]] |
201214
| lib.js:34:7:34:13 | path[0] | lib.js:34:3:34:14 | obj[path[0]] |
215+
| lib.js:38:9:38:36 | args | lib.js:40:14:40:17 | args |
216+
| lib.js:38:16:38:36 | Array.f ... uments) | lib.js:38:9:38:36 | args |
217+
| lib.js:38:27:38:35 | arguments | lib.js:38:16:38:36 | Array.f ... uments) |
218+
| lib.js:38:27:38:35 | arguments | lib.js:38:16:38:36 | Array.f ... uments) |
202219
| lib.js:40:7:40:20 | path | lib.js:42:7:42:10 | path |
220+
| lib.js:40:14:40:17 | args | lib.js:40:14:40:20 | args[1] |
203221
| lib.js:40:14:40:20 | args[1] | lib.js:40:7:40:20 | path |
204222
| lib.js:40:14:40:20 | args[1] | lib.js:40:7:40:20 | path |
205223
| lib.js:42:7:42:10 | path | lib.js:42:7:42:13 | path[0] |
@@ -222,6 +240,8 @@ edges
222240
| lib.js:70:17:70:23 | path[0] | lib.js:70:13:70:24 | obj[path[0]] |
223241
| lib.js:70:17:70:23 | path[0] | lib.js:70:13:70:24 | obj[path[0]] |
224242
| lib.js:83:7:83:25 | path | lib.js:86:19:86:22 | path |
243+
| lib.js:83:14:83:22 | arguments | lib.js:83:14:83:25 | arguments[1] |
244+
| lib.js:83:14:83:22 | arguments | lib.js:83:14:83:25 | arguments[1] |
225245
| lib.js:83:14:83:25 | arguments[1] | lib.js:83:7:83:25 | path |
226246
| lib.js:83:14:83:25 | arguments[1] | lib.js:83:7:83:25 | path |
227247
| lib.js:86:7:86:26 | proto | lib.js:87:10:87:14 | proto |
@@ -238,6 +258,8 @@ edges
238258
| lib.js:91:20:91:28 | obj[path] | lib.js:91:7:91:28 | maybeProto |
239259
| lib.js:91:24:91:27 | path | lib.js:91:20:91:28 | obj[path] |
240260
| lib.js:104:7:104:24 | one | lib.js:108:7:108:9 | one |
261+
| lib.js:104:13:104:21 | arguments | lib.js:104:13:104:24 | arguments[1] |
262+
| lib.js:104:13:104:21 | arguments | lib.js:104:13:104:24 | arguments[1] |
241263
| lib.js:104:13:104:24 | arguments[1] | lib.js:104:7:104:24 | one |
242264
| lib.js:104:13:104:24 | arguments[1] | lib.js:104:7:104:24 | one |
243265
| lib.js:108:7:108:9 | one | lib.js:108:3:108:10 | obj[one] |
@@ -299,12 +321,16 @@ edges
299321
#select
300322
| lib.js:6:7:6:9 | obj | lib.js:1:43:1:46 | path | lib.js:6:7:6:9 | obj | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:1:43:1:46 | path | library input |
301323
| lib.js:15:3:15:14 | obj[path[0]] | lib.js:14:38:14:41 | path | lib.js:15:3:15:14 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:14:38:14:41 | path | library input |
324+
| lib.js:22:3:22:14 | obj[path[0]] | lib.js:20:14:20:22 | arguments | lib.js:22:3:22:14 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:20:14:20:22 | arguments | library input |
302325
| lib.js:22:3:22:14 | obj[path[0]] | lib.js:20:14:20:25 | arguments[1] | lib.js:22:3:22:14 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:20:14:20:25 | arguments[1] | library input |
303326
| lib.js:26:10:26:21 | obj[path[0]] | lib.js:25:44:25:47 | path | lib.js:26:10:26:21 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:25:44:25:47 | path | library input |
304327
| lib.js:34:3:34:14 | obj[path[0]] | lib.js:32:14:32:20 | args[1] | lib.js:34:3:34:14 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:32:14:32:20 | args[1] | library input |
328+
| lib.js:42:3:42:14 | obj[path[0]] | lib.js:38:27:38:35 | arguments | lib.js:42:3:42:14 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:38:27:38:35 | arguments | library input |
305329
| lib.js:42:3:42:14 | obj[path[0]] | lib.js:40:14:40:20 | args[1] | lib.js:42:3:42:14 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:40:14:40:20 | args[1] | library input |
306330
| lib.js:70:13:70:24 | obj[path[0]] | lib.js:59:18:59:18 | s | lib.js:70:13:70:24 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:59:18:59:18 | s | library input |
331+
| lib.js:87:10:87:14 | proto | lib.js:83:14:83:22 | arguments | lib.js:87:10:87:14 | proto | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:83:14:83:22 | arguments | library input |
307332
| lib.js:87:10:87:14 | proto | lib.js:83:14:83:25 | arguments[1] | lib.js:87:10:87:14 | proto | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:83:14:83:25 | arguments[1] | library input |
333+
| lib.js:108:3:108:10 | obj[one] | lib.js:104:13:104:21 | arguments | lib.js:108:3:108:10 | obj[one] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:104:13:104:21 | arguments | library input |
308334
| lib.js:108:3:108:10 | obj[one] | lib.js:104:13:104:24 | arguments[1] | lib.js:108:3:108:10 | obj[one] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:104:13:104:24 | arguments[1] | library input |
309335
| lib.js:119:13:119:24 | obj[path[0]] | lib.js:118:29:118:32 | path | lib.js:119:13:119:24 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:118:29:118:32 | path | library input |
310336
| sublib/sub.js:2:3:2:14 | obj[path[0]] | sublib/sub.js:1:37:1:40 | path | sublib/sub.js:2:3:2:14 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | sublib/sub.js:1:37:1:40 | path | library input |

0 commit comments

Comments
 (0)