T03 · Remote Payload Retrieval and Execution
Error
- Location
- install.sh:29
- Finding
- Unverified Remote D2 Installer Is Downloaded and Executed<![CDATA[ ## Vulnerability Details **File Location**: `install.sh:29-32`; also documented in `README.md:14-16` and `README-zh.md:14-16` **Vulnerability Type**: Unverified remote code execution **Risk Level**: High ### Vulnerable Code ```bash # 2. Install D2 CLI if ! command -v d2 &> /dev/null; then echo "Installing D2..." curl -fsSL https://d2lang.com/install.sh | sh ``` The same unsafe installation command is presented directly to users in both README files: ```bash curl -fsSL https://d2lang.com/install.sh | sh ``` ### Technical Analysis The installer retrieves a mutable shell script from an external URL and immediately passes its response to `sh`. The downloaded content is not version-pinned, inspected, signature-verified, or checked against a known cryptographic digest. HTTPS protects the connection under normal conditions, but it does not guarantee that the upstream script will remain unchanged. A compromised upstream server, release process, domain, DNS path, or trusted TLS infrastructure could cause arbitrary shell commands to be returned and executed. D2 is relevant to the declared diagram-rendering functionality. However, executing an unverified remote script is not the minimum privilege or minimum-trust installation approach required to provide that functionality. ### Attack Path 1. A user follows either README or runs `install.sh`. 2. The installer requests `https://d2lang.com/install.sh`. 3. The upstream endpoint or its delivery infrastructure returns modified shell code. 4. The response is streamed directly into `sh` without review or integrity verification. 5. The malicious commands execute with all privileges available to the user running the installer. 6. The payload can read accessible files, alter user configuration, download additional executables, or establish persistence. ### Impact Assessment Successful exploitation provides arbitrary code execution under the installer user's account. This can expose source code, environm ...[truncated 380 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove all `curl | sh` instructions from the installer and documentation. 2. Pin D2 to an explicitly reviewed release version. 3. Download a versioned release artifact to a local file rather than executing a streamed response. 4. Verify the artifact using a pinned SHA-256 digest or a trusted release signature before installation. 5. Abort installation if verification fails. 6. Install into a project-local or user-local directory whenever possible. 7. Document the source URL, expected checksum, target path, and exact files installed. 8. If an upstream installer must be used, download it first, verify a pinned digest, and invoke the verified local file only after allowing inspection. ]]>
