T08 · Insecure Dependencies
- Location
scripts/check_env.py:59- Finding
Optional Dependency Installer Ignores Declared Version Constraints
- Content
View full analysis
Vulnerability Details
File Location:
scripts/check_env.py:59-68
Vulnerability Type: Unconstrained third-party package installation
Risk Level: MediumVulnerable Code
python # 先尝试 conda(更快,二进制包) result = subprocess.run( ["conda", "install", "-y", pkg, "-c", "conda-forge"], capture_output=True, text=True, timeout=300 ) if result.returncode != 0: # 降级到 pip result = subprocess.run( [sys.executable, "-m", "pip", "install", pkg], capture_output=True, text=True, timeout=300 )Technical Analysis
The optional installer passes bare package names from
REQUIRED_PACKAGESto Conda or pip. It does not apply the version constraints declared inrequirements.txt, and it does not use a lock file or package hashes.Consequently, the artifacts installed by
python scripts/check_env.py --installare selected dynamically from Conda Forge or the configured Python package index. Some dependencies include native binary components. Although installation requires the explicit--installoption and no shell command injection is present, installation scripts and subsequently imported package code execute with the privileges of the Python environment owner.The fallback also changes package sources automatically: a failed Conda installation causes an installation attempt from pip. This makes the resulting dependency set less predictable and undermines the security benefit claimed by the version constraints in
requirements.txt.Attack Path
- A user explicitly runs
python scripts/check_env.py --install, as documented by the Skill. - The script identifies a missing dependency.
- The dependency is requested from Conda Forge using only its package name and no fixed version or integrity hash.
- If the Conda operation fails, the script requests the package from the configured pip index, again without a fixed version or hash.
- A compromised repository a ...[truncated 797 chars]
- A user explicitly runs
- Remediation
View remediation
Remediation Suggestions
- Replace bare package installation with a reviewed lock file containing exact versions and cryptographic hashes.
- For pip, use a command such as
pip install --require-hashes -r requirements.lock. - For Conda, use an explicit environment lock generated for each supported platform.
- Do not silently switch package repositories. Require the user to choose Conda or pip explicitly.
- Ensure the installer applies the same constraints as
requirements.txtif a fully locked installation is not feasible. - Separate core and optional dependencies so that only packages required for the requested format are installed.
- Display the exact repository, package version, and planned changes before requesting final installation confirmation.
- Prefer installation into an isolated virtual environment rather than modifying a shared or system Python environment.
