Repository navigation
fix(security): reject a red teaming target_field that matches an object, a list or null - #2620
Conversation
…ct, a list or null The red teaming middleware applies its payload to each value its target_field JSONPath matches. A string or number takes the payload; any other value fell through `_apply_payload_to_simple_type`, which returned None, so the field was overwritten with null (or a null field stayed null), the payload never reached the function, and the call still counted toward call_limit. A red teaming run configured with, for example, `$.reviews[*]` instead of `$.reviews[*].review` then scored attacks that were never delivered. Raise a ValueError naming the matched path instead, as the middleware already does when target_field matches nothing or matches several values. Signed-off-by: Siddhant Rajhans <[email protected]>
|
Warning
Pull request policy: Only bug fixes may be opened as pull requests. |
|
No actionable comments were generated in the recent review. WalkthroughThe middleware now raises ChangesTarget validation
Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk:
|
|
/ok to test 700bbff |
|
/merge |
Description
Closes #2619
RedTeamingMiddlewareapplies its payload to each value itstarget_fieldmatches, but only a string or a number can take it. For an object, a list or null,_apply_payload_to_simple_typereturnedNone, which was written into the field: the payload never reached the function or the agent, and_call_countstill went up, so the run scored attacks that were never delivered._apply_payload_to_complex_typenow checks every match before applying the payload and raises aValueErrornaming the matched path and the type it holds, as the middleware already does whentarget_fieldmatches nothing or, under theerrorstrategy, several values. The value and the call count are left as they were.Tests, in
packages/nvidia_nat_security/tests/middleware/red_teaming/test_red_teaming_middleware.py:test_target_field_must_resolve_to_string_or_number, for an object, a list and a null match on an output: each raises, the output is unchanged and no attack is counted.test_null_target_field_does_not_count_as_an_attack: an input attack on a null field raises before the function runs.All four cases fail on
develop.pytest packages/nvidia_nat_security/tests: 236 passed and 3 skipped; the 18 PII defense tests fail at import becausepresidiois not installed in my environment, and they do not touch this code.yapf0.43.0 andruff check0.15.0 are clean on the changed files. The reproducer in #2619 now stops on its first call withValueError: target_field $.reviews[*] matched reviews.[0], which holds dict, not a string or number.By Submitting this PR I confirm:
Summary by CodeRabbit