Skip to content

fix: validate risk_level in update_vendor_risk against allowed values#213

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

fix: validate risk_level in update_vendor_risk against allowed values#213
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-8

Conversation

@Jean-Regis-M
Copy link

Summary

Adds input validation to update_vendor_risk to ensure risk_level is one of the allowed strings: 'low', 'medium', 'high'.

Problem

The function currently accepts any string (e.g., " low") and persists it directly, causing downstream fraud detection logic that relies on exact matches to fail. This can lead to silent data corruption and incorrect fraud assessments.

Solution

  • Defined a set VALID_RISK_LEVELS = {"low", "medium", "high"}.
  • Immediately after logging, check if risk_level is in this set.
  • Raise a ValueError with a clear message if validation fails.
  • Updated the docstring to reflect the exception.

Impact

  • Prevents invalid risk levels from being stored.
  • No breaking changes for valid inputs.
  • Improves data integrity and aligns the function with its documented behavior.

Testing

  • Added validation logic and verified that:
    • "low", "medium", "high" pass.
    • " low", "low ", "LOW", "" all raise ValueError.
  • The existing unit test test_fraud_upd_012_leading_space_risk_level_accepted_without_validation should now pass.

The update_vendor_risk function previously accepted any string as
risk_level, including those with leading/trailing spaces (e.g., " low").
This allowed invalid data to be persisted, breaking downstream logic
that expects exact matches for 'low', 'medium', or 'high'.

Added a validation check using a set of allowed values. If the provided
risk_level is not exactly one of the three, a ValueError is raised
before any database operation occurs. This ensures data integrity and
adheres to the function's documented contract.

Fixes GenAI-Security-Project#181

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.

1 participant