Repository navigation
fix(detectors): safely parse invoice attachment file IDs in InflatedPaymentDetector (#260) - #603
Open
rohanbuilds-ai wants to merge 1 commit into
Conversation
…aymentDetector - Prevent uncaught ValueError when invoice attachments contain non-integer file_id - Ignore boolean, None, float, and non-numeric string values in attachments JSON - Ensure valid integer file IDs continue to be extracted and scanned for hidden text - Add regression unit test suite in tests/unit/ctf/test_inflated_payment_detector.py Fixes GenAI-Security-Project#260
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
Fixes #260: Prevent an unhandled
ValueErrorinInflatedPaymentDetector._get_attachment_file_idswhen an invoice's attachments JSON contains non-integerfile_idvalues.Problem
In
finbot/ctf/detectors/implementations/inflated_payment.py,_get_attachment_file_ids()converted attachmentfile_ids directly viaint(a["file_id"])inside a list comprehension without error handling:If an invoice's attachment metadata contained non-integer strings (e.g.
"not-an-int","1.5"), booleans (True), orNone,int()raisedValueError: invalid literal for int() with base 10. Becausecheck_event()calls_get_attachment_file_ids()outside anytry/exceptblock, the exception propagated out tochallenge_service.py, causing a transaction rollback and silently dropping challenge evaluation.Solution
file_ids:file_idis anintorstrand not abool.int(raw_id)intry/except (ValueError, TypeError)and skip malformed entries.detected=False("Invoice has no FinDrive attachments to scan") without crashing.Verification & Test Evidence
origin/mainbaseline confirmed 2 failures with the expected error:test_det_inf_def_001_non_integer_file_id_crashes_detector:ValueError: invalid literal for int() with base 10: 'not-an-int'test_mixed_attachments_extracts_valid_file_ids:ValueError: invalid literal for int() with base 10: 'malformed_string'tests/unit/ctf/test_inflated_payment_detector.pypass in 0.39s.tests/unit/ctf/continue to pass cleanly.isort,black, andgit diff --checkare clean.