fix: add amount validation to flag_invoice_for_review to reject negative invoices#218
Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Open
fix: add amount validation to flag_invoice_for_review to reject negative invoices#218Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Conversation
…ive invoices The function flag_invoice_for_review did not validate that the invoice amount is non-negative. This allowed invoices with negative amounts to be flagged for fraud review, which could be exploited to manipulate vendor risk profiles (e.g., by artificially lowering total invoice amounts). Added a check that raises ValueError if invoice.amount is not None and less than 0. This aligns with expected business logic and prevents the described attack vector. 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
Adds validation to
flag_invoice_for_reviewto reject invoices with negative amounts.Problem
The function currently accepts invoices with negative amounts (e.g., -500.0) without raising an error. This allows an attacker to create negative invoices that, when summed with positive ones, can artificially reduce a vendor's total invoice amount, potentially bypassing risk thresholds. The issue was identified by test case FRAUD-UPD-007.
Solution
After retrieving the invoice and confirming its existence, the function now checks if
invoice.amountis notNoneand less than zero. If so, it raises aValueErrorwith a descriptive message. No other changes are made.Impact
Testing
test_fraud_upd_007_negative_amount_invoice_accepted_without_validationnow passes (raisesValueError).test_fraud_flag_001throughtest_fraud_flag_004to confirm positive‑amount flagging still works.flag_invoice_for_reviewwith a negative amount raises the expected error.