Common Misconfigurations
- Using outdated packages with known CVEs
- Not scanning dependencies for vulnerabilities
- Ignoring security advisories
- Missing dependency pinning
- Not checking package integrity
Vulnerable Example
Secure Solution
Key Commands for Updating
Here are the essential commands for securely managing your Python dependencies.1. Audit for Vulnerabilities
Use these tools (listed inrequirements-dev.txt) to scan your project.
2. Generate Pinned Requirements (The Secure Way)
This is the most secure method. It usespip-tools to generate a locked requirements.txt from a simple requirements.in file.
Step 1: Create a requirements.in file with your top-level dependencies:
pip-tools (usually from requirements-dev.txt):
requirements.txt file.
3. Install from Secure Requirements
This command installs the exact versions from your generated file. If your.pip.conf is set up, it will fail if any hashes don’t match.
4. Sync Your Environment
A better way to install is usingpip-sync, which comes with pip-tools. It installs only what’s in requirements.txt and removes anything else, perfectly syncing your environment.
5. Check for Outdated Packages
This command lists any packages that have newer versions available.Best Practices
- Use tools like Safety, pip-audit, or Snyk.
- Pin exact versions in production.
- Use pip-tools to generate pinned
requirements.txtfiles with hashes. - Regularly update dependencies by re-compiling your
requirements.txt. - Use virtual environments.

