Skip to content

Commit 2c36507

Browse files
Niall O'Higginsindexzero
Niall O'Higgins
authored andcommitted
problem: don't want to run my server as root to bind to privileged ports (e.g. 80, 443).
solution: support privilege drop after socket bind via new --user <username> parameter.
1 parent 89d43c2 commit 2c36507

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

bin/node-http-proxy

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var help = [
1717
" --target HOST:PORT Location of the server the proxy will target",
1818
" --config OUTFILE Location of the configuration file for the proxy server",
1919
" --silent Silence the log output from the proxy server",
20+
" --user USER User to drop privileges to once server socket is bound",
2021
" -h, --help You're staring at it"
2122
].join('\n');
2223

@@ -28,6 +29,7 @@ var location, config = {},
2829
port = argv.port || 80,
2930
host = argv.host || undefined,
3031
target = argv.target;
32+
user = argv.user;
3133

3234
//
3335
// If we were passed a config, parse it
@@ -85,6 +87,14 @@ if (host) {
8587
server.listen(port);
8688
}
8789

90+
91+
//
92+
// Drop privileges if requested
93+
//
94+
if (typeof user === 'string') {
95+
process.setuid(user);
96+
}
97+
8898
//
8999
// Notify that the server is started
90100
//

0 commit comments

Comments
 (0)