fix: sanitize Pipfile.lock to prevent upstream dparse KeyError (Issue…#887
Open
Palodeaza wants to merge 1 commit into
Open
fix: sanitize Pipfile.lock to prevent upstream dparse KeyError (Issue…#887Palodeaza wants to merge 1 commit into
Palodeaza wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
2 tasks
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.
… 849)
Description
Fixes #849.
This PR addresses a bug where running a scan on a
Pipfile.lockcauses an unhandledKeyError: 'hashes'exception, aborting the entire scan process.Root Cause Analysis
After tracing the unhandled exception, it was discovered that the bug originates in the upstream
dparselibrary (dparse.parser).dparseassumes that every dependency object in aPipfile.lockcontains a"hashes"key. If even a single dependency lacks this key (which can happen with certain local or legacy package installations),dparsethrows aKeyErrorand fails.Solution
Since we cannot directly modify the upstream
dparselibrary in the user's environment, this PR introduces a defensive middleware approach within Safety'sprocess_filespipeline.In
safety/scan/ecosystems/python/dependencies.py:dparse.Pipfile.lock, we parse the JSON and iterate through thedefaultanddevelopsections."hashes"key, we inject an empty list ("hashes": []).dparse's strict requirement, allowing the parser to successfully extract the dependency names and versions without crashing.Type of Change
Related Issues
Testing
Although tests were checked before commiting to ensure that everything works as it should
Checklist
Additional Notes
Scope limitation: The sanitization logic is strictly gated behind
if path.endswith("Pipfile.lock"):to ensure we do not accidentally attempt to parserequirements.txt(plain text) orpoetry.lock(TOML) as JSON, preventing any unintended side effects.