Skip to content

Commit 22d285f

Browse files
committed
add model for the gray-matter libary to js/code-injection
1 parent 7ee1105 commit 22d285f

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `gray-matter` library is now modeled as a sink for the `js/code-injection` query.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ module CodeInjection {
5151
}
5252
}
5353

54+
/** An expression parsed by the `gray-matter` library. */
55+
class GrayMatterSink extends Sink {
56+
GrayMatterSink() { this = DataFlow::moduleImport("gray-matter").getACall().getArgument(0) }
57+
}
58+
5459
/**
5560
* A template tag occurring in JS code, viewed as a code injection sink.
5661
*/

javascript/ql/test/query-tests/Security/CWE-094/CodeInjection/UnsafeCodeConstruction.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ nodes
1111
| lib/index.js:13:38:13:41 | data |
1212
| lib/index.js:14:21:14:24 | data |
1313
| lib/index.js:14:21:14:24 | data |
14+
| lib/index.js:19:26:19:29 | data |
15+
| lib/index.js:19:26:19:29 | data |
16+
| lib/index.js:22:7:22:10 | data |
17+
| lib/index.js:22:7:22:10 | data |
1418
edges
1519
| lib/index.js:1:35:1:38 | data | lib/index.js:2:21:2:24 | data |
1620
| lib/index.js:1:35:1:38 | data | lib/index.js:2:21:2:24 | data |
@@ -24,7 +28,12 @@ edges
2428
| lib/index.js:13:38:13:41 | data | lib/index.js:14:21:14:24 | data |
2529
| lib/index.js:13:38:13:41 | data | lib/index.js:14:21:14:24 | data |
2630
| lib/index.js:13:38:13:41 | data | lib/index.js:14:21:14:24 | data |
31+
| lib/index.js:19:26:19:29 | data | lib/index.js:22:7:22:10 | data |
32+
| lib/index.js:19:26:19:29 | data | lib/index.js:22:7:22:10 | data |
33+
| lib/index.js:19:26:19:29 | data | lib/index.js:22:7:22:10 | data |
34+
| lib/index.js:19:26:19:29 | data | lib/index.js:22:7:22:10 | data |
2735
#select
2836
| lib/index.js:2:21:2:24 | data | lib/index.js:1:35:1:38 | data | lib/index.js:2:21:2:24 | data | $@ flows to here and is later $@. | lib/index.js:1:35:1:38 | data | Library input | lib/index.js:2:15:2:30 | "(" + data + ")" | interpreted as code |
2937
| lib/index.js:6:26:6:29 | name | lib/index.js:5:35:5:38 | name | lib/index.js:6:26:6:29 | name | $@ flows to here and is later $@. | lib/index.js:5:35:5:38 | name | Library input | lib/index.js:6:17:6:29 | "obj." + name | interpreted as code |
3038
| lib/index.js:14:21:14:24 | data | lib/index.js:13:38:13:41 | data | lib/index.js:14:21:14:24 | data | $@ flows to here and is later $@. | lib/index.js:13:38:13:41 | data | Library input | lib/index.js:14:15:14:30 | "(" + data + ")" | interpreted as code |
39+
| lib/index.js:22:7:22:10 | data | lib/index.js:19:26:19:29 | data | lib/index.js:22:7:22:10 | data | $@ flows to here and is later $@. | lib/index.js:19:26:19:29 | data | Library input | lib/index.js:25:32:25:34 | str | interpreted as code |

javascript/ql/test/query-tests/Security/CWE-094/CodeInjection/lib/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,16 @@ export function safeAssignment(obj, value) {
1212

1313
global.unsafeDeserialize = function (data) {
1414
return eval("(" + data + ")"); // NOT OK
15-
}
15+
}
16+
17+
const matter = require("gray-matter");
18+
19+
export function greySink(data) {
20+
const str = `
21+
---js
22+
${data}
23+
---
24+
`
25+
const { content } = matter(str);
26+
console.log(content);
27+
}

0 commit comments

Comments
 (0)