fix: Validate --requirements path to prevent arbitrary file reads#5
Merged
Desperado merged 1 commit intoQuality-Max:mainfrom Mar 26, 2026
Merged
Conversation
Resolve the path and verify it is a regular file. Also reject paths that don't look like requirements files (no extension and name doesn't start with "requirements") to limit the scope of file access.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add validation to the
--requirementsCLI argument to ensure it points to a regular file that looks like a requirements file, preventing arbitrary file reads.Problem
The
--requirementspytest CLI argument accepts any file path without validation:This means a user (or a malicious CI configuration) could pass:
While the impact is limited (the contents are only parsed as pip requirement lines, not displayed in full), this still violates the principle of least privilege — the scanner should only access files it actually needs.
In automated CI/CD environments where the
--requirementsflag might be configured via environment variables or templates, an injection into the flag value could cause the scanner to read unintended files.OWASP Reference
Fix
Three validations are now applied:
Path.resolve()— resolves the path to its canonical absolute form, eliminating..traversal tricksp.is_file()— rejects directories, symlinks-to-directories, device files, and non-existent paths (replaces the previousp.exists()which accepted directories)requirements(e.g.,/etc/passwdwould be rejected, butrequirements.txt,requirements-dev.txt, andconstraints.txtare all accepted)