Skip to content

Commit cce15be

Browse files
committed
add basic support for the pino library
1 parent cb1b227 commit cce15be

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-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 `js/log-injection` query now recognizes more logging frameworks.
3+
Affected packages are
4+
[pino](https://npmjs.com/package/pino)

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,28 @@ class StripAnsiStep extends TaintTracking::SharedTaintStep {
337337
)
338338
}
339339
}
340+
341+
/**
342+
* Provides classes and predicates for working with the `pino` library.
343+
*/
344+
private module Pino {
345+
/**
346+
* Gets a logger instance from the `pino` library.
347+
*/
348+
private API::Node pino() {
349+
result = API::moduleImport("pino").getReturn()
350+
or
351+
result = pino().getMember("child").getReturn()
352+
}
353+
354+
/**
355+
* A logging call to the `pino` library.
356+
*/
357+
private class PinoCall extends LoggerCall {
358+
PinoCall() {
359+
this = pino().getMember(["trace", "debug", "info", "warn", "error", "fatal"]).getACall()
360+
}
361+
362+
override DataFlow::Node getAMessageComponent() { result = getArgument(0) }
363+
}
364+
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ nodes
6565
| logInjectionBad.js:58:17:58:59 | stripAn ... rname)) |
6666
| logInjectionBad.js:58:27:58:58 | chalk.u ... ername) |
6767
| logInjectionBad.js:58:50:58:57 | username |
68+
| logInjectionBad.js:64:9:64:36 | q |
69+
| logInjectionBad.js:64:13:64:36 | url.par ... , true) |
70+
| logInjectionBad.js:64:23:64:29 | req.url |
71+
| logInjectionBad.js:64:23:64:29 | req.url |
72+
| logInjectionBad.js:65:9:65:35 | username |
73+
| logInjectionBad.js:65:20:65:20 | q |
74+
| logInjectionBad.js:65:20:65:26 | q.query |
75+
| logInjectionBad.js:65:20:65:35 | q.query.username |
76+
| logInjectionBad.js:67:15:67:22 | username |
77+
| logInjectionBad.js:67:15:67:22 | username |
6878
edges
6979
| logInjectionBad.js:19:9:19:36 | q | logInjectionBad.js:20:20:20:20 | q |
7080
| logInjectionBad.js:19:13:19:36 | url.par ... , true) | logInjectionBad.js:19:9:19:36 | q |
@@ -130,6 +140,15 @@ edges
130140
| logInjectionBad.js:58:27:58:58 | chalk.u ... ername) | logInjectionBad.js:58:17:58:59 | stripAn ... rname)) |
131141
| logInjectionBad.js:58:27:58:58 | chalk.u ... ername) | logInjectionBad.js:58:17:58:59 | stripAn ... rname)) |
132142
| logInjectionBad.js:58:50:58:57 | username | logInjectionBad.js:58:27:58:58 | chalk.u ... ername) |
143+
| logInjectionBad.js:64:9:64:36 | q | logInjectionBad.js:65:20:65:20 | q |
144+
| logInjectionBad.js:64:13:64:36 | url.par ... , true) | logInjectionBad.js:64:9:64:36 | q |
145+
| logInjectionBad.js:64:23:64:29 | req.url | logInjectionBad.js:64:13:64:36 | url.par ... , true) |
146+
| logInjectionBad.js:64:23:64:29 | req.url | logInjectionBad.js:64:13:64:36 | url.par ... , true) |
147+
| logInjectionBad.js:65:9:65:35 | username | logInjectionBad.js:67:15:67:22 | username |
148+
| logInjectionBad.js:65:9:65:35 | username | logInjectionBad.js:67:15:67:22 | username |
149+
| logInjectionBad.js:65:20:65:20 | q | logInjectionBad.js:65:20:65:26 | q.query |
150+
| logInjectionBad.js:65:20:65:26 | q.query | logInjectionBad.js:65:20:65:35 | q.query.username |
151+
| logInjectionBad.js:65:20:65:35 | q.query.username | logInjectionBad.js:65:9:65:35 | username |
133152
#select
134153
| 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 |
135154
| 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 |
@@ -146,3 +165,4 @@ edges
146165
| logInjectionBad.js:56:17:56:55 | kleur.b ... ername) | logInjectionBad.js:46:23:46:29 | req.url | logInjectionBad.js:56:17:56:55 | kleur.b ... ername) | $@ flows to log entry. | logInjectionBad.js:46:23:46:29 | req.url | User-provided value |
147166
| logInjectionBad.js:57:17:57:48 | chalk.u ... ername) | logInjectionBad.js:46:23:46:29 | req.url | logInjectionBad.js:57:17:57:48 | chalk.u ... ername) | $@ flows to log entry. | logInjectionBad.js:46:23:46:29 | req.url | User-provided value |
148167
| logInjectionBad.js:58:17:58:59 | stripAn ... rname)) | logInjectionBad.js:46:23:46:29 | req.url | logInjectionBad.js:58:17:58:59 | stripAn ... rname)) | $@ flows to log entry. | logInjectionBad.js:46:23:46:29 | req.url | User-provided value |
168+
| logInjectionBad.js:67:15:67:22 | username | logInjectionBad.js:64:23:64:29 | req.url | logInjectionBad.js:67:15:67:22 | username | $@ flows to log entry. | logInjectionBad.js:64:23:64: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
@@ -56,4 +56,13 @@ const server2 = http.createServer((req, res) => {
5656
console.log(kleur.blue().bold().underline(username)); // NOT OK
5757
console.log(chalk.underline.bgBlue(username)); // NOT OK
5858
console.log(stripAnsi(chalk.underline.bgBlue(username))); // NOT OK
59+
});
60+
61+
const pino = require('pino')()
62+
63+
const server3 = http.createServer((req, res) => {
64+
let q = url.parse(req.url, true);
65+
let username = q.query.username;
66+
67+
pino.info(username); // NOT OK
5968
});

0 commit comments

Comments
 (0)