T08 · Insecure Dependencies
- Location
scripts/setup_env.py:23- Finding
Unpinned Automatic Installation of Third-Party Dependencies
- Content
View full analysis
Vulnerability Details
File Location:
scripts/setup_env.py, lines 23–47
Vulnerability Type: Unverified and unpinned dependency installation
Risk Level: MediumVulnerable Code
python REQUIRED_PACKAGES: List[str] = [ "akshare", "pandas", ] def is_package_installed(package: str) -> bool: """Use `python -m pip show` to determine whether a package is installed.""" try: subprocess.check_output( [sys.executable, "-m", "pip", "show", package], stderr=subprocess.DEVNULL, ) return True except subprocess.CalledProcessError: return False def install_package(package: str) -> None: """Install a package through the current interpreter.""" print(f"[INFO] Installing dependency: {package} ...") subprocess.check_call([sys.executable, "-m", "pip", "install", package])Technical Analysis
The environment setup script installs
akshareandpandaswithout version constraints, cryptographic hashes, a lockfile, or an explicitly trusted package index. Consequently, package resolution depends on the invoking environment's current pip configuration and the latest versions available from its configured repositories.Python package installation can execute package build and installation logic. If a configured package repository, a selected release, or a transitive dependency is compromised, running this script could execute attacker-controlled code. The use of a subprocess argument list prevents shell metacharacter injection through the package argument; therefore, this is a dependency supply-chain issue rather than command injection.
Automatic installation is also unnecessary for the core analysis operation when dependencies are already available. Safer behavior would be to report missing packages and require a separate, explicit installation step based on a reviewed lockfile.
Attack Path
- An ...[truncated 1350 chars]
- Remediation
View remediation
Remediation Suggestions
- Pin every direct and transitive dependency to reviewed versions using a lockfile.
- Generate and verify cryptographic hashes for all distributions, and install with pip's
--require-hashesoption. - Use an explicitly configured, trusted package index rather than inheriting arbitrary pip index settings.
- Prefer prebuilt wheels from trusted sources and disable source builds where operationally practical.
- Separate dependency checking from installation. Report missing packages and require explicit user confirmation before changing the environment.
- Install dependencies in a dedicated virtual environment with ordinary user privileges, never as an administrator or root user.
- Add automated dependency vulnerability and provenance scanning to the release process.
- Document a reproducible installation command, for example:
bash python -m pip install \ --require-hashes \ --only-binary=:all: \ -r requirements.lock
