Skip to content

Commit 4fdbda3

Browse files
authored
Merge pull request github#5056 from erik-krogh/react
Approved by asgerf
2 parents 8abc37f + aae69c6 commit 4fdbda3

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ module CodeInjection {
112112
}
113113
}
114114

115+
/**
116+
* A body element from a script tag inside React code.
117+
*/
118+
class ReactScriptTag extends Sink {
119+
ReactScriptTag() {
120+
exists(JSXElement element | element.getName() = "script" |
121+
this = element.getBodyElement(_).flow()
122+
)
123+
}
124+
}
125+
115126
/**
116127
* An event handler attribute as a code injection sink.
117128
*/

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ nodes
118118
| react-native.js:8:32:8:38 | tainted |
119119
| react-native.js:10:23:10:29 | tainted |
120120
| react-native.js:10:23:10:29 | tainted |
121+
| react.js:10:56:10:72 | document.location |
122+
| react.js:10:56:10:72 | document.location |
123+
| react.js:10:56:10:77 | documen ... on.hash |
124+
| react.js:10:56:10:77 | documen ... on.hash |
121125
| template-sinks.js:12:9:12:31 | tainted |
122126
| template-sinks.js:12:19:12:31 | req.query.foo |
123127
| template-sinks.js:12:19:12:31 | req.query.foo |
@@ -275,6 +279,10 @@ edges
275279
| react-native.js:7:7:7:33 | tainted | react-native.js:10:23:10:29 | tainted |
276280
| react-native.js:7:17:7:33 | req.param("code") | react-native.js:7:7:7:33 | tainted |
277281
| react-native.js:7:17:7:33 | req.param("code") | react-native.js:7:7:7:33 | tainted |
282+
| react.js:10:56:10:72 | document.location | react.js:10:56:10:77 | documen ... on.hash |
283+
| react.js:10:56:10:72 | document.location | react.js:10:56:10:77 | documen ... on.hash |
284+
| react.js:10:56:10:72 | document.location | react.js:10:56:10:77 | documen ... on.hash |
285+
| react.js:10:56:10:72 | document.location | react.js:10:56:10:77 | documen ... on.hash |
278286
| template-sinks.js:12:9:12:31 | tainted | template-sinks.js:14:17:14:23 | tainted |
279287
| template-sinks.js:12:9:12:31 | tainted | template-sinks.js:14:17:14:23 | tainted |
280288
| template-sinks.js:12:9:12:31 | tainted | template-sinks.js:15:16:15:22 | tainted |
@@ -352,6 +360,7 @@ edges
352360
| module.js:9:16:9:29 | req.query.code | module.js:9:16:9:29 | req.query.code | module.js:9:16:9:29 | req.query.code | $@ flows to here and is interpreted as code. | module.js:9:16:9:29 | req.query.code | User-provided value |
353361
| react-native.js:8:32:8:38 | tainted | react-native.js:7:17:7:33 | req.param("code") | react-native.js:8:32:8:38 | tainted | $@ flows to here and is interpreted as code. | react-native.js:7:17:7:33 | req.param("code") | User-provided value |
354362
| react-native.js:10:23:10:29 | tainted | react-native.js:7:17:7:33 | req.param("code") | react-native.js:10:23:10:29 | tainted | $@ flows to here and is interpreted as code. | react-native.js:7:17:7:33 | req.param("code") | User-provided value |
363+
| react.js:10:56:10:77 | documen ... on.hash | react.js:10:56:10:72 | document.location | react.js:10:56:10:77 | documen ... on.hash | $@ flows to here and is interpreted as code. | react.js:10:56:10:72 | document.location | User-provided value |
355364
| template-sinks.js:14:17:14:23 | tainted | template-sinks.js:12:19:12:31 | req.query.foo | template-sinks.js:14:17:14:23 | tainted | $@ flows to here and is interpreted as a template, which may contain code. | template-sinks.js:12:19:12:31 | req.query.foo | User-provided value |
356365
| template-sinks.js:15:16:15:22 | tainted | template-sinks.js:12:19:12:31 | req.query.foo | template-sinks.js:15:16:15:22 | tainted | $@ flows to here and is interpreted as a template, which may contain code. | template-sinks.js:12:19:12:31 | req.query.foo | User-provided value |
357366
| template-sinks.js:16:18:16:24 | tainted | template-sinks.js:12:19:12:31 | req.query.foo | template-sinks.js:16:18:16:24 | tainted | $@ flows to here and is interpreted as a template, which may contain code. | template-sinks.js:12:19:12:31 | req.query.foo | User-provided value |

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ nodes
122122
| react-native.js:8:32:8:38 | tainted |
123123
| react-native.js:10:23:10:29 | tainted |
124124
| react-native.js:10:23:10:29 | tainted |
125+
| react.js:10:56:10:72 | document.location |
126+
| react.js:10:56:10:72 | document.location |
127+
| react.js:10:56:10:77 | documen ... on.hash |
128+
| react.js:10:56:10:77 | documen ... on.hash |
125129
| template-sinks.js:12:9:12:31 | tainted |
126130
| template-sinks.js:12:19:12:31 | req.query.foo |
127131
| template-sinks.js:12:19:12:31 | req.query.foo |
@@ -283,6 +287,10 @@ edges
283287
| react-native.js:7:7:7:33 | tainted | react-native.js:10:23:10:29 | tainted |
284288
| react-native.js:7:17:7:33 | req.param("code") | react-native.js:7:7:7:33 | tainted |
285289
| react-native.js:7:17:7:33 | req.param("code") | react-native.js:7:7:7:33 | tainted |
290+
| react.js:10:56:10:72 | document.location | react.js:10:56:10:77 | documen ... on.hash |
291+
| react.js:10:56:10:72 | document.location | react.js:10:56:10:77 | documen ... on.hash |
292+
| react.js:10:56:10:72 | document.location | react.js:10:56:10:77 | documen ... on.hash |
293+
| react.js:10:56:10:72 | document.location | react.js:10:56:10:77 | documen ... on.hash |
286294
| template-sinks.js:12:9:12:31 | tainted | template-sinks.js:14:17:14:23 | tainted |
287295
| template-sinks.js:12:9:12:31 | tainted | template-sinks.js:14:17:14:23 | tainted |
288296
| template-sinks.js:12:9:12:31 | tainted | template-sinks.js:15:16:15:22 | tainted |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
import {Helmet} from "react-helmet";
3+
4+
class Application extends React.Component {
5+
render () {
6+
return (
7+
<div className="application">
8+
<Helmet>
9+
<title>My unsafe</title>
10+
<script type="application/javascript">{document.location.hash}</script>
11+
</Helmet>
12+
</div>
13+
);
14+
}
15+
};
16+
17+
export default Application

javascript/ql/test/query-tests/Security/CWE-601/ClientSideUrlRedirect/ClientSideUrlRedirect.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ nodes
33
| electron.js:4:12:4:22 | window.name |
44
| electron.js:7:20:7:29 | getTaint() |
55
| electron.js:7:20:7:29 | getTaint() |
6+
| react.js:10:60:10:76 | document.location |
7+
| react.js:10:60:10:76 | document.location |
8+
| react.js:10:60:10:81 | documen ... on.hash |
9+
| react.js:10:60:10:81 | documen ... on.hash |
610
| sanitizer.js:2:9:2:25 | url |
711
| sanitizer.js:2:15:2:25 | window.name |
812
| sanitizer.js:2:15:2:25 | window.name |
@@ -189,6 +193,10 @@ edges
189193
| electron.js:4:12:4:22 | window.name | electron.js:7:20:7:29 | getTaint() |
190194
| electron.js:4:12:4:22 | window.name | electron.js:7:20:7:29 | getTaint() |
191195
| electron.js:4:12:4:22 | window.name | electron.js:7:20:7:29 | getTaint() |
196+
| react.js:10:60:10:76 | document.location | react.js:10:60:10:81 | documen ... on.hash |
197+
| react.js:10:60:10:76 | document.location | react.js:10:60:10:81 | documen ... on.hash |
198+
| react.js:10:60:10:76 | document.location | react.js:10:60:10:81 | documen ... on.hash |
199+
| react.js:10:60:10:76 | document.location | react.js:10:60:10:81 | documen ... on.hash |
192200
| sanitizer.js:2:9:2:25 | url | sanitizer.js:4:27:4:29 | url |
193201
| sanitizer.js:2:9:2:25 | url | sanitizer.js:4:27:4:29 | url |
194202
| sanitizer.js:2:9:2:25 | url | sanitizer.js:16:27:16:29 | url |
@@ -358,6 +366,7 @@ edges
358366
| typed.ts:28:24:28:34 | redirectUri | typed.ts:29:33:29:43 | redirectUri |
359367
#select
360368
| electron.js:7:20:7:29 | getTaint() | electron.js:4:12:4:22 | window.name | electron.js:7:20:7:29 | getTaint() | Untrusted URL redirection due to $@. | electron.js:4:12:4:22 | window.name | user-provided value |
369+
| react.js:10:60:10:81 | documen ... on.hash | react.js:10:60:10:76 | document.location | react.js:10:60:10:81 | documen ... on.hash | Untrusted URL redirection due to $@. | react.js:10:60:10:76 | document.location | user-provided value |
361370
| sanitizer.js:4:27:4:29 | url | sanitizer.js:2:15:2:25 | window.name | sanitizer.js:4:27:4:29 | url | Untrusted URL redirection due to $@. | sanitizer.js:2:15:2:25 | window.name | user-provided value |
362371
| sanitizer.js:16:27:16:29 | url | sanitizer.js:2:15:2:25 | window.name | sanitizer.js:16:27:16:29 | url | Untrusted URL redirection due to $@. | sanitizer.js:2:15:2:25 | window.name | user-provided value |
363372
| sanitizer.js:19:27:19:29 | url | sanitizer.js:2:15:2:25 | window.name | sanitizer.js:19:27:19:29 | url | Untrusted URL redirection due to $@. | sanitizer.js:2:15:2:25 | window.name | user-provided value |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
import {Helmet} from "react-helmet";
3+
4+
class Application extends React.Component {
5+
render () {
6+
return (
7+
<div className="application">
8+
<Helmet>
9+
<title>My unsafe app</title>
10+
<script type="application/javascript" src={document.location.hash}/>
11+
</Helmet>
12+
</div>
13+
);
14+
}
15+
};
16+
17+
export default Application

0 commit comments

Comments
 (0)