T08 · Insecure Dependencies
Warning
- Location
- src/installer.js:174
- Finding
- <![CDATA[Untrusted Package Retrieval Without Origin, Integrity, or Size Validation]]><![CDATA[ ## Vulnerability Details **File Location**: `src/installer.js:174-194` **Vulnerability Type**: Arbitrary package source retrieval, server-side request forgery, and unverified supply-chain content **Risk Level**: Medium ### Vulnerable Code ```javascript if (skill.downloadUrl) { return new Promise((resolve, reject) => { const url = skill.downloadUrl; const client = url.startsWith('https:') ? https : http; const req = client.get(url, { timeout: 60000 }, (res) => { if (res.statusCode !== 200) { reject(new Error(`Download failed with status ${res.statusCode}`)); return; } const chunks = []; res.on('data', chunk => chunks.push(chunk)); res.on('end', () => { const data = Buffer.concat(chunks); fs.writeFileSync(targetDir, data); resolve(targetDir); }); }); ``` ### Technical Analysis The installer treats the registry-provided `skill.downloadUrl` as trusted. It selects either the HTTPS or HTTP client based solely on the URL prefix and then requests the destination without validating: - The URL protocol - The destination hostname or resolved IP address - Whether the destination belongs to an approved package host - Whether the destination resolves to loopback, link-local, private-network, or cloud metadata infrastructure - The package's cryptographic digest or publisher signature - The response content type or package format - The maximum response size The response is accumulated completely in memory through `Buffer.concat(chunks)` and written to disk without authenticity verification. Consequently, a malicious or compromised registry can direct the process to internal services or provide a modified package. The lack of a response-size limit also permits memory exhaustion if the remote endpoint sends a very large response. The current repository's `installer.js` is incomplete and is not exported by `src/index.js`. This reduces immediate reachability through ...[truncated 1689 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Parse package URLs with the standard `URL` class and reject malformed URLs. 2. Permit only `https:` URLs in production. 3. Maintain an explicit allowlist of trusted package distribution hostnames. 4. Resolve the hostname before connecting and reject loopback, private, link-local, multicast, reserved, and cloud metadata address ranges for both IPv4 and IPv6. 5. Revalidate the destination after redirects and either reject redirects or enforce the same policy on every redirect target. 6. Require an immutable SHA-256 or stronger package digest from a signed registry manifest. 7. Verify publisher signatures and package provenance before writing or installing content. 8. Enforce a strict maximum response size while streaming rather than buffering the entire response in memory. 9. Validate the response status, content type, expected package format, and archive structure. 10. Write downloads to a securely created temporary file, verify them, and then atomically move them into place. 11. Add tests covering internal IP addresses, DNS rebinding, redirects, plaintext HTTP, digest mismatches, malformed packages, and oversized responses. ]]>
