Skip to content

Commit a21ebbb

Browse files
committed
add taint step through the ansi-colors library
1 parent d719a1e commit a21ebbb

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lgtm,codescanning
2+
* The dataflow libraries now model dataflow through console styling libraries.
3+
Affected packages are
4+
[ansi-colors](https://npmjs.com/package/ansi-colors)

javascript/ql/src/semmle/javascript/frameworks/Logging.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,15 @@ private class DebugLoggerCall extends LoggerCall, API::CallNode {
201201

202202
override DataFlow::Node getAMessageComponent() { result = getAnArgument() }
203203
}
204+
205+
/**
206+
* A step through the [`ansi-colors`](https://https://npmjs.org/package/ansi-colors) library.
207+
*/
208+
class AnsiColorsStep extends TaintTracking::SharedTaintStep {
209+
override predicate stringManipulationStep(DataFlow::Node pred, DataFlow::Node succ) {
210+
exists(API::CallNode call | call = API::moduleImport("ansi-colors").getAMember*().getACall() |
211+
pred = call.getArgument(0) and
212+
succ = call
213+
)
214+
}
215+
}

javascript/ql/test/query-tests/Security/CWE-117/LogInjection.expected

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ nodes
2222
| logInjectionBad.js:30:23:30:49 | `[ERROR ... rror}"` |
2323
| logInjectionBad.js:30:23:30:49 | `[ERROR ... rror}"` |
2424
| logInjectionBad.js:30:42:30:46 | error |
25+
| logInjectionBad.js:37:9:37:36 | q |
26+
| logInjectionBad.js:37:13:37:36 | url.par ... , true) |
27+
| logInjectionBad.js:37:23:37:29 | req.url |
28+
| logInjectionBad.js:37:23:37:29 | req.url |
29+
| logInjectionBad.js:38:9:38:35 | username |
30+
| logInjectionBad.js:38:20:38:20 | q |
31+
| logInjectionBad.js:38:20:38:26 | q.query |
32+
| logInjectionBad.js:38:20:38:35 | q.query.username |
33+
| logInjectionBad.js:40:18:40:54 | ansiCol ... ername) |
34+
| logInjectionBad.js:40:18:40:54 | ansiCol ... ername) |
35+
| logInjectionBad.js:40:46:40:53 | username |
2536
edges
2637
| logInjectionBad.js:19:9:19:36 | q | logInjectionBad.js:20:20:20:20 | q |
2738
| logInjectionBad.js:19:13:19:36 | url.par ... , true) | logInjectionBad.js:19:9:19:36 | q |
@@ -45,9 +56,20 @@ edges
4556
| logInjectionBad.js:29:14:29:18 | error | logInjectionBad.js:30:42:30:46 | error |
4657
| logInjectionBad.js:30:42:30:46 | error | logInjectionBad.js:30:23:30:49 | `[ERROR ... rror}"` |
4758
| logInjectionBad.js:30:42:30:46 | error | logInjectionBad.js:30:23:30:49 | `[ERROR ... rror}"` |
59+
| logInjectionBad.js:37:9:37:36 | q | logInjectionBad.js:38:20:38:20 | q |
60+
| logInjectionBad.js:37:13:37:36 | url.par ... , true) | logInjectionBad.js:37:9:37:36 | q |
61+
| logInjectionBad.js:37:23:37:29 | req.url | logInjectionBad.js:37:13:37:36 | url.par ... , true) |
62+
| logInjectionBad.js:37:23:37:29 | req.url | logInjectionBad.js:37:13:37:36 | url.par ... , true) |
63+
| logInjectionBad.js:38:9:38:35 | username | logInjectionBad.js:40:46:40:53 | username |
64+
| logInjectionBad.js:38:20:38:20 | q | logInjectionBad.js:38:20:38:26 | q.query |
65+
| logInjectionBad.js:38:20:38:26 | q.query | logInjectionBad.js:38:20:38:35 | q.query.username |
66+
| logInjectionBad.js:38:20:38:35 | q.query.username | logInjectionBad.js:38:9:38:35 | username |
67+
| logInjectionBad.js:40:46:40:53 | username | logInjectionBad.js:40:18:40:54 | ansiCol ... ername) |
68+
| logInjectionBad.js:40:46:40:53 | username | logInjectionBad.js:40:18:40:54 | ansiCol ... ername) |
4869
#select
4970
| logInjectionBad.js:22:18:22:43 | `[INFO] ... rname}` | logInjectionBad.js:19:23:19:29 | req.url | logInjectionBad.js:22:18:22:43 | `[INFO] ... rname}` | $@ flows to log entry. | logInjectionBad.js:19:23:19:29 | req.url | User-provided value |
5071
| logInjectionBad.js:23:37:23:44 | username | logInjectionBad.js:19:23:19:29 | req.url | logInjectionBad.js:23:37:23:44 | username | $@ flows to log entry. | logInjectionBad.js:19:23:19:29 | req.url | User-provided value |
5172
| logInjectionBad.js:24:35:24:42 | username | logInjectionBad.js:19:23:19:29 | req.url | logInjectionBad.js:24:35:24:42 | username | $@ flows to log entry. | logInjectionBad.js:19:23:19:29 | req.url | User-provided value |
5273
| logInjectionBad.js:25:36:25:43 | username | logInjectionBad.js:19:23:19:29 | req.url | logInjectionBad.js:25:36:25:43 | username | $@ flows to log entry. | logInjectionBad.js:19:23:19:29 | req.url | User-provided value |
5374
| logInjectionBad.js:30:23:30:49 | `[ERROR ... rror}"` | logInjectionBad.js:19:23:19:29 | req.url | logInjectionBad.js:30:23:30:49 | `[ERROR ... rror}"` | $@ flows to log entry. | logInjectionBad.js:19:23:19:29 | req.url | User-provided value |
75+
| logInjectionBad.js:40:18:40:54 | ansiCol ... ername) | logInjectionBad.js:37:23:37:29 | req.url | logInjectionBad.js:40:18:40:54 | ansiCol ... ername) | $@ flows to log entry. | logInjectionBad.js:37:23:37:29 | req.url | User-provided value |

javascript/ql/test/query-tests/Security/CWE-117/logInjectionBad.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ const server = http.createServer((req, res) => {
2929
} catch (error) {
3030
console.error(`[ERROR] Error: "${error}"`); // NOT OK
3131
}
32+
});
33+
34+
const ansiColors = require('ansi-colors');
35+
36+
const server2 = http.createServer((req, res) => {
37+
let q = url.parse(req.url, true);
38+
let username = q.query.username;
39+
40+
console.info(ansiColors.yellow.underline(username)); // NOT OK
3241
});

0 commit comments

Comments
 (0)