Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test handling of ~= in requirements.txt and add it to docs #3610

Merged
merged 8 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,10 @@ The scanner examines the `Package.resolved` file which is created by the package
The scanner examines the `PKG-INFO` and `METADATA` files for an installed Python package to extract the component name and version which
are used to search the database for vulnerabilities.
Support for scanning the `requirements.txt` file generated by pip is also present.
#### Support for Version Range (`~=`) in `requirements.txt`
The CVE binary tool supports version ranges specified with `~=` in your `requirements.txt` file. This allows you to define a compatible version range for your Python project.
The CVE binary tool utilizes `pip install --dry-run` to seamlessly handle and interpret version ranges specified with `~=`. This ensures effective analysis of potential updates without the need for manual parsing of `~=`.
ayushthe1 marked this conversation as resolved.
Show resolved Hide resolved
Note that `--dry-run` will give "what you get if you installed this requirements list today" so that's what the scan results will show. We do not attempt to retrieve CVEs for all possible versions in that range. If you want to check a specific version within that range (such as the very first allowed one) you would need to use a separate requirements.txt file with that version frozen.

The tool supports the scanning of the contents of any Wheel package files (indicated with a file extension of .whl) and egg package files (indicated with a file extension of .egg).

Expand Down
6 changes: 1 addition & 5 deletions test/test_package_list_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class TestPackageListParser:
"default": {"remarks": Remarks.NewFound, "comments": "", "severity": ""},
"paths": {""},
},
ProductInfo(vendor="html5lib*", product="html5lib", version="0.999999999"): {
"default": {"remarks": Remarks.NewFound, "comments": "", "severity": ""},
"paths": {""},
},
}

# Find the versions of the ubuntu packages
Expand Down Expand Up @@ -124,7 +120,7 @@ def test_valid_requirements(self, filepath, parsed_data):
package_list = PackageListParser(filepath, error_mode=ErrorMode.FullTrace)
assert package_list.parse_list() == parsed_data
# Update the packages back to latest
subprocess.run(["pip", "install", "httplib2", "requests", "html5lib", "-U"])
subprocess.run(["pip", "install", "httplib2", "requests", "-U"])

@pytest.mark.skipif(
distro.id() not in SUPPORTED_DISTROS,
Expand Down
3 changes: 1 addition & 2 deletions test/txt/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
html5lib==0.999999999
httplib2==0.18.1
requests==2.25.1
requests~=2.25.1