fix: validate risk_level in update_vendor_risk to prevent mixed-case values#220
Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Open
fix: validate risk_level in update_vendor_risk to prevent mixed-case values#220Jean-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:
Missing input validation allowed mixed-case strings like "Medium" to be
persisted, breaking downstream comparisons expecting exact "medium".
Solution:
Add membership check against VALID_RISK_LEVELS = {"low", "medium", "high"}
at function entry. Invalid values now raise ValueError.
Impact:
Minimal change, no side effects for valid inputs, prevents silent data
corruption, aligns with documented behavior.
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 #182 by adding input validation to
update_vendor_riskso that only exactly"low","medium", or"high"are accepted.Problem
Currently,
update_vendor_riskaccepts any string asrisk_leveland stores it without validation. This allows mixed‑case values like"Medium"to be saved. Downstream logic that comparesrisk_level == "medium"fails because the stored value is"Medium", breaking fraud assessment and risk escalation.Root Cause
The function lacks input validation. The
risk_levelparameter is passed directly to the repository without checking against the allowed set defined in the docstring. This is a validation gap.Solution
Add a membership check at the start of the function:
VALID_RISK_LEVELS = {"low", "medium", "high"}risk_levelis not in the set, raiseValueErrorwith a clear message.This ensures only the documented values are persisted, and any deviation fails fast.
Impact
Testing
test_fraud_upd_013_mixed_case_risk_level_accepted_without_validation) which now passes."medium"→ succeeds"Medium"→ raisesValueError"MEDIUM"→ raisesValueError""→ raisesValueErrorNone→ raisesValueError123→ raisesValueErrorChecklist
ValueError)