T03 · Remote Payload Retrieval and Execution
Error
- Location
- kagi-fastgpt.sh:43
- Finding
- Unverified Remote Binary Download and Execution<![CDATA[ ## Vulnerability Details **File Location**: `kagi-fastgpt.sh`, lines 43–87 **Vulnerability Type**: Unverified retrieval and execution of a mutable remote payload **Risk Level**: High ### Vulnerable Code ```bash if command -v curl >/dev/null 2>&1; then RELEASE_META="$(curl -fsSL "https://api.github.com/repos/joelazar/kagi-skills/releases/latest")" elif command -v wget >/dev/null 2>&1; then RELEASE_META="$(wget -qO- "https://api.github.com/repos/joelazar/kagi-skills/releases/latest")" else echo "Error: Neither curl nor wget found. Please download the binary manually from:" >&2 echo " https://github.com/joelazar/kagi-skills/releases/latest" >&2 exit 1 fi TAG="$(printf '%s\n' "$RELEASE_META" | grep -m1 '"tag_name"' | cut -d'"' -f4 || true)" if [[ -z "$TAG" ]]; then echo "Error: Could not resolve latest release tag from GitHub API." >&2 echo "Please download manually from: https://github.com/joelazar/kagi-skills/releases/latest" >&2 exit 1 fi BINARY="kagi-fastgpt_${TAG}_${OS}_${ARCH}" URL="https://github.com/joelazar/kagi-skills/releases/download/${TAG}/${BINARY}" echo "kagi-fastgpt binary not found. Download pre-built binary from GitHub releases?" >&2 echo " $URL" >&2 read -r -p "Download? [Y/n] " reply >&2 </dev/tty case "${reply:-Y}" in [Yy]*|"") ;; *) echo "Aborted. Install Go 1.26+ to build from source, or download manually:" >&2 echo " $URL" >&2 exit 1 ;; esac if command -v curl >/dev/null 2>&1; then curl -fsSL "$URL" -o "$BIN" else wget -qO "$BIN" "$URL" fi chmod +x "$BIN" fi fi exec "$BIN" "$@" ``` ### Technical Analysis When a suitable Go compiler or an existing executable is unavailable, the wrapper queries the mutable GitHub `latest` release endpoint, downloads the corresponding executable, grants it execution permission, and subsequently executes it. The downloaded artif ...[truncated 2544 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Prefer compiling the included, reviewed Go source rather than automatically retrieving an executable. 2. Pin downloads to an explicitly reviewed release version instead of resolving the mutable `latest` release at runtime. 3. Publish a cryptographic digest for every platform-specific artifact and pin the expected digest in reviewed local code or trusted release metadata. 4. Verify the downloaded file before granting executable permission or running it: - Download into a newly created temporary file. - Calculate its SHA-256 digest. - Compare the complete digest using an exact, fail-closed comparison. - Delete the file and abort if verification fails. 5. Do not rely solely on a checksum manifest downloaded from the same potentially compromised release. Authenticate the manifest with a trusted signing mechanism, such as a pinned public key or a verified Sigstore identity and transparency-log policy. 6. Move the verified artifact atomically into `.bin/kagi-fastgpt` only after all checks succeed. 7. Use restrictive file and directory permissions so other local users cannot replace the cached executable. 8. Remove the default affirmative download response or require an explicit opt-in that explains that native code will be executed. 9. In high-assurance deployments, disable runtime downloads entirely and require binaries to be installed through a controlled, integrity-verified build or package pipeline. ]]>
