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

Privilege drop support for bin/node-http-proxy via --user <username> parameter #203

Closed
wants to merge 6 commits into from
Closed
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
29 changes: 25 additions & 4 deletions bin/node-http-proxy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var help = [
" --target HOST:PORT Location of the server the proxy will target",
" --config OUTFILE Location of the configuration file for the proxy server",
" --silent Silence the log output from the proxy server",
" --user USER User to drop privileges to once server socket is bound",
" -h, --help You're staring at it"
].join('\n');

Expand All @@ -24,8 +25,10 @@ if (argv.h || argv.help || Object.keys(argv).length === 2) {
}

var location, config = {},
port = argv.port || 80,
target = argv.target;
port = argv.port || 80,
target = argv.target
user = argv.user
;

//
// If we were passed a config, parse it
Expand All @@ -41,11 +44,21 @@ if (argv.config) {
}

//
// If `config.https` is set, then load those files into the config options.
// If `config.https` is set, then load the required file contents into the config options.
//
if (config.https) {
Object.keys(config.https).forEach(function (key) {
config.https[key] = fs.readFileSync(config.https[key], 'utf8');
// If CA certs are specified, load those too.
if (key === "ca") {
for (var i=0; i < config.https.ca.length; i++) {
if (config.https.ca === undefined) {
config.https.ca = [];
}
config.https.ca[i] = fs.readFileSync(config.https[key][i], 'utf8');
}
} else {
config.https[key] = fs.readFileSync(config.https[key], 'utf8');
}
});
}

Expand Down Expand Up @@ -79,6 +92,14 @@ else {
//
server.listen(port);


//
// Drop privileges if requested
//
if (typeof user === 'string') {
process.setuid(user);
}

//
// Notify that the server is started
//
Expand Down