fix(fraud): validate recommended_action to prevent None being accepted#256
Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Open
fix(fraud): validate recommended_action to prevent None being accepted#256Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Conversation
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>
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 #188 by adding input validation to
flag_invoice_for_reviewso thatNone(and any other invalid value) raises aValueErrorinstead of being silently stored as the string"None".Problem
When
recommended_action=Noneis passed, the function:"Recommended action: None."in the fraud note."reject"becauseNone != "reject".Root Cause
The function lacks any validation of the
recommended_actionparameter. It is used directly in string formatting and a conditional without being checked against a whitelist of allowed actions.Solution
VALID_ACTIONS = {"hold", "reject", "escalate", "monitor"}.if recommended_action not in VALID_ACTIONSand raise a descriptiveValueErrorif the check fails.'monitor'in the list of accepted actions (it was already implied as valid by the issue's acceptance criteria).Impact
"hold","reject","escalate") work exactly as before.Testing
recommended_action=None→ValueError."hold","reject","escalate", and"monitor"are accepted."reject"still changes the invoice status when appropriate.