Before you begin
- Python 3.12 or later.
- A requirements-style text file. The report does not install packages, resolve includes, or verify vulnerability status.
Set up your example
- Save as security-requirements-source-review.py.
- Open a terminal in its folder.
- Run python "security-requirements-source-review.py" --help and prepare the listed input files.
Sample files in this download:
- requirements.txt
Download the ZIP, extract it, and open a terminal inside the extracted folder. The source file is security-requirements-source-review.py.
Run the script
python "security-requirements-source-review.py" "requirements.txt"If your system uses python3 instead of python, use that command for Python examples. Keep paths containing spaces in quotes. Required inputs and optional settings are described in the code and setup steps.
What to expect
requests>=2 is flagged as not exactly pinned; the raw requirement is not printed.
The complete script
#!/usr/bin/env python3
"""Inspect a requirements file for plaintext URLs, direct references, and unpinned package declarations."""
import argparse
import sys
import json
from pathlib import Path
def main():
parser = argparse.ArgumentParser(description='Inspect a requirements file for plaintext URLs, direct references, and unpinned package declarations.')
parser.add_argument('requirements',type=Path)
args = parser.parse_args()
for number,line in enumerate(args.requirements.read_text(encoding='utf-8-sig').splitlines(),1):
value=line.strip()
if not value or value.startswith('#'):continue
reasons=[]
if 'http://' in value:reasons.append('plaintext source URL')
if '://' in value or ' @ ' in value:reasons.append('direct source reference; review privately')
if value.startswith(('-r ','-c ','--')):reasons.append('directive needs separate review')
elif '==' not in value and ' @ ' not in value:reasons.append('not exactly pinned with ==')
if reasons:print(json.dumps({'line':number,'findings':reasons}))
if __name__ == '__main__':
try:
main()
except (OSError, ValueError, RuntimeError) as exc:
print(f'Error: {exc}', file=sys.stderr)
sys.exit(1)
Open source as plain text · Download source and sample files
How it works
- Inspect a requirements file for plaintext URLs, direct references, and unpinned package declarations.
- Arguments are explicit and expected input errors produce a message with a nonzero exit code.
- Results reflect your selected local data or the specific endpoint you choose; the example illustrates the result shape.
Make it your own
Adapt the task
Adapt the == policy for your project. Exact pinning alone does not establish integrity; this tool does not query vulnerability databases.
Adjust presentation
Edit final print statements or json.dumps indentation to adjust the report layout. Keep input validation and exclusive-create file modes intact.
Change one setting at a time, run it again on sample data, and compare the output. The customization guide walks through this process.
If something goes wrong
An input or dependency is unavailable.
A requirements-style text file. The report does not install packages, resolve includes, or verify vulnerability status.
Actual results differ from the example.
Inputs and system state determine values. Review each finding in context; a report is not proof of system health or a complete security assessment.
Reference & next steps
These official references explain the underlying tools. The Scriptage example and guide are original instructional content. See verification notes for what has been checked and the limits of those checks.
Copies a template for your own notes. It does not send anything.