Skip to content

fix(detectors): safely parse invoice attachment file IDs in InflatedPaymentDetector (#260) - #603

Open
rohanbuilds-ai wants to merge 1 commit into
GenAI-Security-Project:mainfrom
rohanbuilds-ai:fix/detector-inflated-payment-file-id
Open

rohanbuilds-ai wants to merge 1 commit into
GenAI-Security-Project:mainfrom
rohanbuilds-ai:fix/detector-inflated-payment-file-id

Conversation

@rohanbuilds-ai

Copy link
Copy Markdown

Summary

Fixes #260: Prevent an unhandled ValueError in InflatedPaymentDetector._get_attachment_file_ids when an invoice's attachments JSON contains non-integer file_id values.

Problem

In finbot/ctf/detectors/implementations/inflated_payment.py, _get_attachment_file_ids() converted attachment file_ids directly via int(a["file_id"]) inside a list comprehension without error handling:

return [
    int(a["file_id"])
    for a in attachments
    if isinstance(a, dict) and "file_id" in a
]

If an invoice's attachment metadata contained non-integer strings (e.g. "not-an-int", "1.5"), booleans (True), or None, int() raised ValueError: invalid literal for int() with base 10. Because check_event() calls _get_attachment_file_ids() outside any try/except block, the exception propagated out to challenge_service.py, causing a transaction rollback and silently dropping challenge evaluation.

Solution

  • Safely extract attachment file_ids:
    • Verify that file_id is an int or str and not a bool.
    • Wrap int(raw_id) in try/except (ValueError, TypeError) and skip malformed entries.
    • Return the list of valid integer file IDs for subsequent FinDrive lookups.
  • When an invoice has only malformed or non-integer attachment IDs, the detector gracefully returns detected=False ("Invoice has no FinDrive attachments to scan") without crashing.
  • Legitimate inflated-payment detection and valid integer attachment IDs remain completely intact.

Verification & Test Evidence

  1. Baseline Regression: Running the new test suite against origin/main baseline 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'
  2. Post-Fix: All 5 tests in tests/unit/ctf/test_inflated_payment_detector.py pass in 0.39s.
  3. Full CTF Suite: All 32 existing passing tests in tests/unit/ctf/ continue to pass cleanly.
  4. Linters & Style: isort, black, and git diff --check are clean.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug_102_MUST_FIX: Test Case DET-INF-DEF-001: InflatedPaymentDetector crashes with ValueError when invoice attachment has non-integer file_id

1 participant