Skip to content

fix(detectors): skip non-integer file_id in InflatedPaymentDetector#264

Open
stealthwhizz wants to merge 2 commits intoGenAI-Security-Project:mainfrom
stealthwhizz:fix/inflated-payment-non-integer-file-id
Open

fix(detectors): skip non-integer file_id in InflatedPaymentDetector#264
stealthwhizz wants to merge 2 commits intoGenAI-Security-Project:mainfrom
stealthwhizz:fix/inflated-payment-non-integer-file-id

Conversation

@stealthwhizz
Copy link
Contributor

@stealthwhizz stealthwhizz commented Mar 18, 2026

Summary

Fixes #260: Prevents ValueError when invoice attachment has non-integer file_id.

Problem

In _get_attachment_file_ids, the list comprehension calls int(a["file_id"]) without validation. If file_id is a non-numeric string like "abc" or "1.5", int() raises ValueError, crashing the detector coroutine. This allows an attacker to cause denial-of-detection by injecting a single malformed attachment.

Root Cause

The code lacks exception handling for the int() conversion. The isinstance and key-existence checks filter out non-dict entries and missing keys, but do not protect against non-numeric file_id values. The uncaught ValueError propagates through check_event, stopping all subsequent event evaluations.

Solution

Replace the list comprehension with an explicit loop that wraps int() in a try/except block catching ValueError and TypeError. On exception, the malformed entry is skipped. Valid entries are collected as before. This preserves existing behaviour for valid integer and string-integer file_ids.

Test plan

  • pytest tests/unit/ctf/test_inflated_payment_detector.py passes (10 tests)
  • Non-integer file_id ("abc", "1.5", None) returns empty list or skips entry
  • Valid file_ids (42, "42") still work
  • Mixed valid/invalid attachments only return valid IDs

Fixes GenAI-Security-Project#260: Prevents ValueError when invoice attachment has non-integer file_id.

Problem
In _get_attachment_file_ids, the list comprehension calls int(a["file_id"])
without validation. If file_id is a non-numeric string like "abc" or "1.5",
float(actual) raises ValueError, crashing the detector coroutine. This
allows an attacker to cause denial-of-detection by injecting a single
malformed attachment.

Root Cause
The code lacks exception handling for the int() conversion. The isinstance
and key-existence checks filter out non-dict entries and missing keys, but
do not protect against non-numeric file_id values. The uncaught ValueError
propagates through check_event, stopping all subsequent event evaluations.

Solution
Replace the list comprehension with an explicit loop that wraps int() in a
try/except block catching ValueError and TypeError. On exception, the
malformed entry is skipped. Valid entries are collected as before. This
preserves existing behaviour for valid integer and string-integer file_ids.
Copilot AI review requested due to automatic review settings March 18, 2026 18:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses #260 by hardening InflatedPaymentDetector._get_attachment_file_ids so malformed/non-integer file_id values in invoice attachments don’t raise ValueError and crash detection. It also includes unrelated changes to vendor data tools’ DB session handling.

Changes:

  • Update _get_attachment_file_ids to skip invalid file_id values via try/except around int().
  • Add unit tests covering valid/invalid/mixed attachment file_id inputs.
  • Refactor vendor data tools to use get_db() instead of db_session() (introduces session lifecycle/rollback issues).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
finbot/ctf/detectors/implementations/inflated_payment.py Avoids crashing on non-integer attachment file_id values by skipping invalid entries.
tests/unit/ctf/test_inflated_payment_detector.py Adds targeted unit tests for _get_attachment_file_ids edge cases.
finbot/tools/data/vendor.py Switches DB session acquisition to get_db(); currently risks connection leaks and bypasses rollback semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

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

2 participants