Skip to content

fix(fraud): validate recommended_action to prevent None being accepted#256

Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-18
Open

fix(fraud): validate recommended_action to prevent None being accepted#256
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-18

Conversation

@Jean-Regis-M
Copy link

Summary

Fixes #188 by adding input validation to flag_invoice_for_review so that None (and any other invalid value) raises a ValueError instead of being silently stored as the string "None".

Problem

When recommended_action=None is passed, the function:

  • Stores "Recommended action: None." in the fraud note.
  • Never triggers the status change for "reject" because None != "reject".
  • Leaves the invoice in its original state with a misleading note.

Root Cause

The function lacks any validation of the recommended_action parameter. It is used directly in string formatting and a conditional without being checked against a whitelist of allowed actions.

Solution

  1. Define a set VALID_ACTIONS = {"hold", "reject", "escalate", "monitor"}.
  2. Immediately after logging, check if recommended_action not in VALID_ACTIONS and raise a descriptive ValueError if the check fails.
  3. Update the docstring to include 'monitor' in the list of accepted actions (it was already implied as valid by the issue's acceptance criteria).

Impact

  • No breaking changes : all existing calls with valid actions ("hold", "reject", "escalate") work exactly as before.
  • Minimal diff : only a few lines added; no refactoring or unrelated changes.
  • Improved correctness : invalid inputs are now rejected early, preventing silent data corruption.

Testing

  • Manually tested with recommended_action=NoneValueError.
  • Verified that "hold", "reject", "escalate", and "monitor" are accepted.
  • Confirmed that "reject" still changes the invoice status when appropriate.

Root cause:
No input validation allowed None to pass, leading to "None" being stored
in the fraud note and bypassing the intended action logic.

Solution:
Add a validation step that checks recommended_action against the set of
allowed values {"hold", "reject", "escalate", "monitor"} and raises
ValueError if the value is invalid. Also update the docstring to include
'monitor' in the list of accepted actions.

Impact:
- Prevents invalid values (including None) from being accepted.
- Maintains full backward compatibility for existing valid callers.
- Minimal diff, no side effects. 

Signed-off-by: JEAN REGIS <240509606@firat.edu.tr>
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_077_EVALUATE: Test Case FRAUD-FLAG-017: flag_invoice_for_review accepts None as recommended_action

1 participant