Skip to content

Commit ea21d75

Browse files
committedJun 24, 2020
Fix a vulnerability from a crafted argument to 'bunyan -p ARG'
This was reported privately as: https://hackerone.com/reports/902739 bunyan - RCE via insecure command formatting After this change: % ./bin/bunyan -p "S'11;touch hacked ;'\\" bunyan: error: no matching PIDs found for "S'11;touch hacked ;'\" With _DEBUG self-logging to show the escaped command: % ./bin/bunyan -p "S'11;touch hacked ;'\\" (bunyan: exec cmd: "ps -A -o pid,command | grep '[S]'\\''11;touch hacked ;'\\''\\\\'") bunyan: error: no matching PIDs found for "S'11;touch hacked ;'\" (bunyan: cleanupAndExit) (bunyan: process.exit(2)) Before this change these would create a "hacked" file in the current dir.
1 parent 033b37d commit ea21d75

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed
 

‎CHANGES.md

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ Known issues:
1010
(nothing yet)
1111

1212

13+
## 1.8.13
14+
15+
- Fix a vulnerability from a crafted argument to 'bunyan -p ARG'
16+
17+
This was reported privately as:
18+
https://hackerone.com/reports/902739
19+
bunyan - RCE via insecure command formatting
20+
21+
Previous to this version the 'bunyan' CLI was not escaping a given argument
22+
to the '-p' option before executing `ps -A -o pid,command | grep '$ARG'`
23+
which could lead to unintended execution.
24+
1325
## 1.8.12
1426

1527
- [issue #444] Fix the `bunyan` CLI to not duplicate the "HTTP/1.1 ..." status

‎bin/bunyan

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
/**
3-
* Copyright 2017 Trent Mick
4-
* Copyright 2017 Joyent Inc.
3+
* Copyright 2020 Trent Mick
4+
* Copyright 2020 Joyent Inc.
55
*
66
* bunyan -- filter and pretty-print Bunyan log files (line-delimited JSON)
77
*
@@ -11,7 +11,7 @@
1111
* vim: expandtab:ts=4:sw=4
1212
*/
1313

14-
var VERSION = '1.8.12';
14+
var VERSION = '1.8.13';
1515

1616
var p = console.log;
1717
var util = require('util');
@@ -1266,7 +1266,15 @@ function processPids(opts, stylize, callback) {
12661266
// own search.
12671267
regex = '[' + regex[0] + ']' + regex.slice(1);
12681268
}
1269-
exec(format('ps -A -o pid,command | grep \'%s\'', regex),
1269+
var cmd = format('ps -A -o pid,command | grep \'%s\'',
1270+
// Escape single-quotes to avoid breaking the grep arg quoting
1271+
// (leading to a possible *code execution*) and backslashes to
1272+
// avoid undoing that escaping.
1273+
regex.replace(/\\/g, '\\\\')
1274+
// JSSTYLED
1275+
.replace(/'/g, "'\\''"));
1276+
if (_DEBUG) { warn('(bunyan: exec cmd: %j)', cmd); }
1277+
exec(cmd,
12701278
function (pidsErr, stdout, stderr) {
12711279
if (pidsErr) {
12721280
warn('bunyan: error getting PIDs for "%s": %s\n%s\n%s',

‎lib/bunyan.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* vim: expandtab:ts=4:sw=4
99
*/
1010

11-
var VERSION = '1.8.12';
11+
var VERSION = '1.8.13';
1212

1313
/*
1414
* Bunyan log format version. This becomes the 'v' field on all log records.

‎package.json

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
{
22
"name": "bunyan",
3-
"version": "1.8.12",
3+
"version": "1.8.13",
44
"description": "a JSON logging library for node.js services",
55
"author": "Trent Mick <trentm@gmail.com> (http://trentm.com)",
66
"main": "./lib/bunyan.js",
77
"bin": {
88
"bunyan": "./bin/bunyan"
99
},
10-
1110
"repository": {
1211
"type": "git",
1312
"url": "git://github.com/trentm/node-bunyan.git"
1413
},
15-
"engines": ["node >=0.10.0"],
16-
"keywords": ["log", "logging", "log4j", "json", "bunyan"],
14+
"engines": [
15+
"node >=0.10.0"
16+
],
17+
"keywords": [
18+
"log",
19+
"logging",
20+
"log4j",
21+
"json",
22+
"bunyan"
23+
],
1724
"license": "MIT",
18-
1925
"// dtrace-provider": "required for dtrace features",
2026
"// mv": "required for RotatingFileStream",
2127
"// moment": "required for local time with CLI",
@@ -32,10 +38,8 @@
3238
"verror": "1.3.3",
3339
"vasync": "1.4.3"
3440
},
35-
3641
"scripts": {
3742
"test": "make test"
3843
},
39-
"dependencies": {
40-
}
44+
"dependencies": {}
4145
}

0 commit comments

Comments
 (0)
Please sign in to comment.