Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security Fix for Command Injection & Arbitrary File Read - huntr.dev #69

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var util = require('util')
, fs = require('fs')
, spawn = require('./spawn')
, errors = require('./errors')
, cwd = process.cwd();
, cwd = process.cwd()
, path = require('path');

/**
* Make some curl opts friendlier.
Expand Down Expand Up @@ -92,7 +93,7 @@ exports.request = function (options, callback) {
, err
, stderr = ''
, stdoutlen
, stdout = new Buffer(stdoutlen = 0)
, stdout = new Buffer.alloc(stdoutlen = 0)
, encoding
, complete
, cleanup
Expand Down Expand Up @@ -236,7 +237,13 @@ exports.request = function (options, callback) {

if (options.file) {
cmd = 'cat';
args = [options.file];
var rootDirectory = path.resolve(cwd, './');
var filename = path.join(rootDirectory, options.file);
if (filename.indexOf(rootDirectory) !== 0) {
// trying to sneak out of the root directory?
return
}
args = [filename];
}

//Simulate the spawn?
Expand Down
30 changes: 19 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
{ "name" : "curlrequest",
"description" : "A curl wrapper for node",
"version" : "1.0.1",
"homepage" : "https://github.com/node-js-libs/curlrequest",
"author" : "Chris O'Hara <cohara87@gmail.com>",
"main" : "index",
{
"name": "curlrequest",
"description": "A curl wrapper for node",
"version": "1.0.1",
"homepage": "https://github.com/node-js-libs/curlrequest",
"author": "Chris O'Hara <cohara87@gmail.com>",
"main": "index",
"repository": {
"type": "git",
"url": "http://github.com/node-js-libs/curlrequest.git"
},
"engines": { "node": ">= 0.4.0" },
"licenses": [{
"type": "MIT",
"url": "http://github.com/node-js-libs/curlrequest/raw/master/LICENSE"
}]
"engines": {
"node": ">= 0.4.0"
},
"licenses": [
{
"type": "MIT",
"url": "http://github.com/node-js-libs/curlrequest/raw/master/LICENSE"
}
],
"dependencies": {
"shell-escape": "^0.2.0"
}
}
3 changes: 2 additions & 1 deletion spawn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var child = require('child_process');
var shellescape = require('shell-escape');

/**
* Limit the amount of processes that can be spawned per tick.
Expand All @@ -13,7 +14,7 @@ var spawned = 0
*/

module.exports = function (cmd, args, options, callback) {
var args = Array.prototype.slice.call(arguments);
var args = shellescape(Array.prototype.slice.call(arguments));
if (spawned < max_per_tick) {
spawned++;
callback(child.spawn.apply(child, args.slice(0, -1)));
Expand Down