Skip to main content

security-constraints

Security-constraints is a command-line application used to fetch security vulnerabilities in Python packages from external sources and from them generate version constraints for the packages.

The constraints can then be given to pip install with the -c option, either on the command line or in a requirements file.

Installation

Just install it with pip:

pip install security-constraints

Usage

The environment variable SC_GITHUB_TOKEN needs to be set to a valid GitHub token which provides read access to public repositories. This is needed in order to access GitHub Security Advisory. Once this is set, you can simply run the program to output safe pip constraints to stdout.

>security-constraints
# Generated by security-constraints 1.0.0 on 2022-11-04T08:33:54.523625Z
# Data sources: Github Security Advisory
# Configuration: {'ignore_ids': [], 'min_severity': 'CRITICAL'}
...
vncauthproxy>=1.2.0  # CVE-2022-36436 (ID: GHSA-237r-mx84-7x8c)
waitress!=1.4.2  # CVE-2020-5236 (ID: GHSA-73m2-3pwg-5fgc)
waitress>=1.4.0  # GHSA-4ppp-gpcr-7qf6 (ID: GHSA-4ppp-gpcr-7qf6)
ymlref>0.1.1  # CVE-2018-20133 (ID: GHSA-8r8j-xvfj-36f9)
>

You can use --output to instead output to a file.

>security-constraints --output constraints.txt
>cat constraints.txt
# Generated by security-constraints 1.0.0 on 2022-11-04T08:33:54.523625Z
# Data sources: Github Security Advisory
# Configuration: {'ignore_ids': [], 'min_severity': 'CRITICAL'}
...
vncauthproxy>=1.2.0  # CVE-2022-36436 (ID: GHSA-237r-mx84-7x8c)
waitress!=1.4.2  # CVE-2020-5236 (ID: GHSA-73m2-3pwg-5fgc)
waitress>=1.4.0  # GHSA-4ppp-gpcr-7qf6 (ID: GHSA-4ppp-gpcr-7qf6)
ymlref>0.1.1  # CVE-2018-20133 (ID: GHSA-8r8j-xvfj-36f9)
>

You can provide a space-separated list of IDs of vulnerabilities that should be ignored. The IDs in question are those that appear in after ID: in the comments in the output.

>security-constraints --ignore-ids GHSA-4ppp-gpcr-7qf6 GHSA-8r8j-xvfj-36f9
# Generated by security-constraints 1.0.0 on 2022-11-04T08:33:54.523625Z
# Data sources: Github Security Advisory
# Configuration: {'ignore_ids': ['GHSA-4ppp-gpcr-7qf6', 'GHSA-8r8j-xvfj-36f9'], 'min_severity': 'CRITICAL'}
...
vncauthproxy>=1.2.0  # CVE-2022-36436 (ID: GHSA-237r-mx84-7x8c)
waitress!=1.4.2  # CVE-2020-5236 (ID: GHSA-73m2-3pwg-5fgc)
>

The IDs to ignore can also be given in a configuration file using --config. To create an initial configuration file, you can use --dump-config. This will dump the current configuration (including any --ignore-ids passed) to stdout and then exit. You can redirect this into a file to create an initial configuration file. The configuration file is in yaml format.

>security-constraints --ignore-ids GHSA-4ppp-gpcr-7qf6 GHSA-8r8j-xvfj-36f9 --dump-config > sc_config.yaml
>cat sc_config.yaml
ignore_ids:
- GHSA-4ppp-gpcr-7qf6
- GHSA-8r8j-xvfj-36f9
min_severity: CRITICAL
>security-constraints --config sc_config.yaml
# Generated by security-constraints 1.0.0 on 2022-11-04T08:33:54.523625Z
# Data sources: Github Security Advisory
# Configuration: {'ignore_ids': ['GHSA-4ppp-gpcr-7qf6', 'GHSA-8r8j-xvfj-36f9'], 'min_severity': 'CRITICAL'}
...
vncauthproxy>=1.2.0  # CVE-2022-36436 (ID: GHSA-237r-mx84-7x8c)
waitress!=1.4.2  # CVE-2020-5236 (ID: GHSA-73m2-3pwg-5fgc)
>

By default, security-constraints fetches all security vulnerabilities with severity "CRITICAL" or higher (as understood by Github Security Advisory). The minimum severity can be configured using the option --min-severity or by setting min_severity in the config file (if both are set, their common minimum will be used).

>security-constraints --min-severity high

Contributing

Pull requests as well as new issues are welcome.

Code style: black CI

Metadata

Release files for security-constraints 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for security-constraints 1.3.0
File Size Uploaded Provenance Actions
security_constraints-1.3.0.tar.gz 30.5 kB Without provenance Details for security_constraints-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for security-constraints 1.3.0
File Interpreter ABI Platform Actions
security_constraints-1.3.0-py3-none-any.whl Python 3 none any Details for security_constraints-1.3.0-py3-none-any.whl

Total release size: 49.8 kB

Release files / security_constraints-1.3.0.tar.gz

Download URL security_constraints-1.3.0.tar.gz
Size 30.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d28a29e8c90a4de8e99b6f00af37c66048db2979de257a1cbb67eeff5a393046
BLAKE2b-256 checksum
How to use checksums
b1a372355e14bf85811a4067035011ed82ae7a7ce0200fe208572d6e71793082
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / security_constraints-1.3.0-py3-none-any.whl

Download URL security_constraints-1.3.0-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6845ae9db4953661bf3085b5b86cd6e19f8e9b4c9450e12d12eb7256a46b3d1d
BLAKE2b-256 checksum
How to use checksums
0e8d496d2d62ae14915e7ce1e952d88698ca3f8b0469759460c8103d643bebb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Security for security-constraints 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page