Skip to content

fix(vendor): validate trust_level in update_vendor_status (fixes #235)#255

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

fix(vendor): validate trust_level in update_vendor_status (fixes #235)#255
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-17

Conversation

@Jean-Regis-M
Copy link

Summary

Fixes #235 by adding validation to trust_level in update_vendor_status, ensuring only "low", "standard", or "high" are accepted.

Problem

The function currently accepts any string, including values with leading/trailing spaces (e.g., " standard"). These invalid values are stored in the database, causing later comparisons like trust_level == "standard" to fail silently. Test VND-UPD-020 demonstrates this issue.

Root Cause

No input validation is performed on the trust_level parameter. The value is passed directly to the repository and persisted, bypassing any intended restrictions.

Solution

I added a validation block before the repository call:

  • Define VALID_TRUST_LEVELS = {"low", "standard", "high"}
  • Raise ValueError if trust_level is not in this set
  • The error message lists the allowed values for clarity

This change is minimal and isolated to one function.

Impact

  • No breaking changes: Valid inputs ("low", "standard", "high") remain unchanged.
  • Minimal diff: Only 5 lines added.
  • Improved correctness: Invalid values now raise an error, preventing silent data corruption.

Testing

  • Verified manually with the before/after steps described.
  • Ran the failing unit test: test_vnd_upd_020_leading_space_trust_level_accepted_without_validation now passes.
  • Confirmed that valid trust levels still work.

Related Issue

Closes #235

…level in update_vendor_status

Root cause:
Missing input validation allowed any string (including those with spaces)
to be stored as trust_level, breaking downstream trust‑gated logic.

Solution:
Add a membership check against the set {"low", "standard", "high"} and
raise ValueError for invalid values. This rejects values like " standard",
"standard ", etc., while preserving valid inputs.

Impact:
- Minimal change, isolated to one function.
- No breaking changes for valid callers.
- Fixes test VND-UPD-020 and ensures data integrity.

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.

Bug_088_MUST_FIX: Test Case VND-UPD-020: update_vendor_status accepts " standard" (leading space) as trust_level

1 participant