T03 · Remote Payload Retrieval and Execution
Error
- Location
- scripts/ensure_aliyun_cli.py:60
- Finding
- Unverified Remote Executable Download and Execution## Vulnerability Details **File Location**: `scripts/ensure_aliyun_cli.py`, lines 17 and 60-77; execution occurs through lines 37-42 and 132-136 **Vulnerability Type**: Remote payload retrieval and execution without cryptographic integrity verification **Risk Level**: High ### Vulnerable Code ```python DOWNLOAD_URL = "https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz" ``` ```python def run_version(binary: Path) -> tuple[tuple[int, ...], str]: try: out = subprocess.check_output( [str(binary), "version"], text=True, stderr=subprocess.STDOUT ) except Exception: return tuple(), "" return parse_version(out), out.strip() ``` ```python def install_latest(target: Path) -> None: target.parent.mkdir(parents=True, exist_ok=True) with tempfile.TemporaryDirectory(prefix="aliyun-cli-update-") as td: td_path = Path(td) tgz_path = td_path / "aliyun-cli.tgz" with urllib.request.urlopen(DOWNLOAD_URL, timeout=30) as resp: # nosec B310 tgz_path.write_bytes(resp.read()) with tarfile.open(tgz_path, "r:gz") as tf: member = None for m in tf.getmembers(): if Path(m.name).name == "aliyun": member = m break if member is None: raise RuntimeError("aliyun binary not found in archive") tf.extract(member, path=td_path) extracted = td_path / member.name if not extracted.exists(): raise RuntimeError("extracted aliyun binary missing") shutil.copy2(extracted, target) mode = target.stat().st_mode target.chmod(mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) ``` ```python if should_update: print("[aliyun-cli] updating from official latest package...") install_latest(target) ...[truncated 2789 chars]
- Remediation
- ## Remediation Suggestions 1. Replace the mutable `latest` URL with a pinned, explicitly selected CLI version. 2. Store a trusted SHA-256 digest in the reviewed Skill or obtain it from a separately authenticated, signed release manifest. 3. Verify the archive before opening or extracting it, and abort on any mismatch. 4. Verify an official vendor signature where Alibaba Cloud provides one, using a pinned trusted public key. 5. Restrict redirects and validate the final URL scheme and hostname against an explicit allowlist. 6. Download with a strict maximum size to prevent resource exhaustion. 7. Install atomically: verify and inspect the artifact, write it to a temporary file in the destination filesystem, set restrictive permissions, and use an atomic rename. 8. Do not update automatically during normal cloud operations. Separate installation and upgrading into an explicit, user-approved action. 9. Report the exact downloaded version and digest in the audit evidence. 10. If integrity metadata is unavailable, direct the user to install the CLI through a trusted operating-system package mechanism rather than executing an unverified download.
