jp: Improve security of rsync proxy#47736
Conversation
Make it harder for something on the host system to activate the proxy. * Set umask 0077 when creating the socket. * Pass a secret value to the container, which must be passed back. Note this isn't bulletproof security: if an attacker can read the environment from Docker and access files as the host system user, this would be fairly easy to get around. But if they can do all that, they can probably do worse things already.
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
kraftbj
left a comment
There was a problem hiding this comment.
Review comments from automated analysis — 1 critical, 2 important.
| } ); | ||
|
|
||
| const oldumask = process.umask( 0o077 ); | ||
| proxyServer.listen( { path: socketPath }, () => { |
There was a problem hiding this comment.
Bug: Umask not restored on error path
If proxyServer.listen() fails (triggering the 'error' event), rejectListening(err) is called but the umask is never restored — process.umask(oldUmask) only runs in the success callback. The process would continue with umask 0o077, silently breaking permissions for any subsequent file operations.
Since .listen() creates the socket file synchronously before returning, you can restore the umask immediately after the call rather than in the async callback:
| proxyServer.listen( { path: socketPath }, () => { | |
| const oldumask = process.umask( 0o077 ); | |
| proxyServer.listen( { path: socketPath }, () => { | |
| resolveListening(); | |
| } ); | |
| process.umask( oldumask ); |
This eliminates the restoration problem entirely — no need to handle it in both success and error paths.
There was a problem hiding this comment.
Not sure whether the AI introduced a race condition there, though: will proxySever.listen return before creating the socket?
Proposed changes
Make it harder for something on the host system to activate the proxy.
Note this isn't bulletproof security: if an attacker can read the environment from Docker and access files as the host system user, this would be fairly easy to get around. But if they can do all that, they can probably do worse things already.
Other information
Related product discussion/links
Fixes MONOREP-397
Does this pull request change what data or activity we track or use?
No
Testing instructions
jp rsyncshould work, and while it's waiting at the "No saved entries for XXX. Create one for easier use later?" prompt you can examine the filesystem to see that the socket file (probably/tmp/jp-rsync-XXX) is mode 0700, and the process list to verify that the secret value isn't included in the command line todocker run.