Critical - Fix RCE exposure: restrict pull_request_target prettier workflow to same-repo PRs #4888
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🐸 🐸 JFrog Open Source Security Contribution 🐸 🐸
As part of JFrog’s ongoing Open Source Security initiative, this PR hardens the
prettierworkflow by mitigating a remote-code-execution (RCE) risk caused by runningnpm installunder apull_request_targettrigger.🚨 Security Issue
The workflow is triggered using
pull_request_target, which runs with the base repository’s permissions and secrets.In its original form, the workflow executed:
Because PR authors fully control
package.json, including lifecycle scripts (preinstall,install,postinstall), a fork PR can embed arbitrary shell commands that run automatically duringnpm install.By adding the following text to your Package JSON, an attacker can run RCE on your repository context.
The workflow also uses elevated permissions:
contents: writepull-requests: writesecrets.GITHUB_TOKENCombined, this allows an attacker to execute arbitrary commands and achieve full repository takeover.
✅ What This PR Improves
This PR introduces a safety check to ensure the workflow only runs for PRs originating from the same repository:
This prevents untrusted fork PRs from executing
npm installin a privileged context and removes the RCE attack vector.📝 Important Recommendation
Please review the rest of your GitHub workflows for similar patterns.
Any workflow that:
pull_request_target, andnpm install,pip install, etc.)should be restricted to trusted contributors only.
This is critical to reduce CI-based supply-chain exposure.
🧪 Proof of Concept
Working Attack can be found here.
https://github.com/doocs/leetcode/actions/runs/20007746692/job/57372562158?pr=4887#step:4:11
Full control of the PR and the repository
This PR is part of JFrog’s commitment to strengthening the security posture of the open-source ecosystem.