fix(fraud): validate recommended_action in flag_invoice_for_review#219
Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Open
fix(fraud): validate recommended_action in flag_invoice_for_review#219Jean-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 on recommended_action allowed any string, including
whitespace-padded variants like " hold". These bypassed the only
action-specific logic (== "reject") and were stored verbatim.
Solution:
Add a validation block that checks recommended_action against a set of
allowed values: {"hold", "reject", "escalate", "monitor"}. If not found,
raise ValueError with a clear message.
Impact:
- Invalid inputs now raise an error instead of being silently accepted.
- Valid inputs behave exactly as before.
- Prevents future bugs where downstream code assumes a clean value.
- Minimal, isolated change – easy to review and safe to merge.
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
Prevents
flag_invoice_for_reviewfrom accepting invalidrecommended_actionstrings (e.g.," hold","HOLD") by adding explicit validation against a set of allowed actions.Problem
The function currently accepts any string for
recommended_action. Values with leading/trailing spaces (like" hold") bypass the only action‑specific check (recommended_action == "reject") and are stored unchanged in the database. This violates the documented contract and could cause silent data corruption or future logic failures.Root Cause
There is no input validation for
recommended_action. The function relies solely on an exact‑match check for"reject", which fails for any variant with extra whitespace. Any other action value (including malformed ones) is accepted without verification.Solution
Insert a validation block immediately after confirming the invoice exists: