T08 · Insecure Dependencies
- Location
scripts/generate_mirror.py:60- Finding
Package-Controlled Build Code May Execute During Source Download
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate_mirror.py, lines 60-62
Vulnerability Type: Unsafe processing of untrusted source distributions
Risk Level: Highpython def download_package(package, version, tmp_dir): print(f"Downloading {package}=={version}...") cmd = ["pip", "download", "--no-binary=:all:", f"{package}=={version}", "-d", tmp_dir] subprocess.run(cmd, check=True)Technical Analysis
The generator invokes
pip downloadwith--no-binary=:all:, forcing pip to retrieve a source distribution rather than a prebuilt wheel. Processing a source distribution can cause pip to create an isolated build environment and invoke package-controlled PEP 517 build-backend hooks to obtain metadata or prepare the distribution. Legacy package formats may similarly involve execution of packaging code.The package name and version are accepted directly from command-line arguments. There is no package allowlist, artifact hash verification, trusted publisher validation, build-backend restriction, or execution sandbox. Although the command uses an argument array and is not vulnerable to shell metacharacter injection, it still intentionally passes an untrusted package to a tool capable of invoking package-controlled build logic.
Attack Path
- An attacker publishes a malicious or typo-squatted package, compromises an existing package, or gains control of a selected release.
- The package includes a malicious build backend or other packaging code that runs while pip processes source-distribution metadata.
- A user or Agent invokes the generator with the attacker-controlled package and version.
- The generator runs
pip download --no-binary=:all:. - Pip processes the source distribution and invokes package-controlled build behavior.
- The malicious code executes with the operating-system privileges and environment available to the generator process.
Impact Assessment
Successful exploitation can provide arbit ...[truncated 577 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not use pip to process untrusted source distributions merely to retrieve source files.
- Retrieve artifacts through a data-only mechanism, such as the PyPI JSON API followed by a direct HTTPS artifact download.
- Require an expected cryptographic hash and verify it before processing the artifact.
- Prefer verified wheels when static source inspection is sufficient, while still treating their contents as untrusted.
- Maintain an explicit package and repository allowlist where operationally possible.
- If source-distribution processing is unavoidable, perform it inside a disposable sandbox or container with:
- No host credentials or API keys.
- No writable access to the user’s home directory or Agent configuration.
- No privileged filesystem mounts.
- Restricted outbound network access.
- CPU, memory, process, and execution-time limits.
- Record the resolved artifact URL, hash, package version, and index origin for auditability.
- Consider passing explicit index configuration rather than inheriting potentially unsafe pip configuration from the environment.
