Skip to content

jp: Improve security of rsync proxy#47736

Merged
kraftbj merged 2 commits into
trunkfrom
fix/jp-rsync-proxy-security
Mar 23, 2026
Merged

jp: Improve security of rsync proxy#47736
kraftbj merged 2 commits into
trunkfrom
fix/jp-rsync-proxy-security

Conversation

@anomiex
Copy link
Copy Markdown
Contributor

@anomiex anomiex commented Mar 23, 2026

Proposed changes

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.

Other information

  • Generate changelog entries for this PR (using AI).

Related product discussion/links

Fixes MONOREP-397

Does this pull request change what data or activity we track or use?

No

Testing instructions

  • Try it out, ideally without using a saved destination. A jp rsync should 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 to docker run.

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.
@anomiex anomiex requested review from a team and kraftbj March 23, 2026 14:45
@anomiex anomiex self-assigned this Mar 23, 2026
@anomiex anomiex added [Status] Needs Review This PR is ready for review. [Pri] Normal labels Mar 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

Copy link
Copy Markdown
Contributor

@kraftbj kraftbj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review comments from automated analysis — 1 critical, 2 important.

} );

const oldumask = process.umask( 0o077 );
proxyServer.listen( { path: socketPath }, () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether the AI introduced a race condition there, though: will proxySever.listen return before creating the socket?

Comment thread projects/js-packages/jetpack-cli/bin/jp.js
Comment thread tools/docker/bin/monorepo
@kraftbj kraftbj merged commit 226fff9 into trunk Mar 23, 2026
96 checks passed
@kraftbj kraftbj deleted the fix/jp-rsync-proxy-security branch March 23, 2026 21:50
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants