Skip to content

fix(security): reject a red teaming target_field that matches an object, a list or null - #2620

Merged
rapids-bot[bot] merged 1 commit into
NVIDIA:developfrom
siddhant-rajhans:fix/red-teaming-non-scalar-target-field
Nov 18, 2026
Merged

rapids-bot[bot] merged 1 commit into
NVIDIA:developfrom
siddhant-rajhans:fix/red-teaming-non-scalar-target-field

Conversation

@siddhant-rajhans

@siddhant-rajhans siddhant-rajhans commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Closes #2619

RedTeamingMiddleware applies its payload to each value its target_field matches, but only a string or a number can take it. For an object, a list or null, _apply_payload_to_simple_type returned None, which was written into the field: the payload never reached the function or the agent, and _call_count still went up, so the run scored attacks that were never delivered.

_apply_payload_to_complex_type now checks every match before applying the payload and raises a ValueError naming the matched path and the type it holds, as the middleware already does when target_field matches nothing or, under the error strategy, 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 because presidio is not installed in my environment, and they do not touch this code. yapf 0.43.0 and ruff check 0.15.0 are clean on the changed files. The reproducer in #2619 now stops on its first call with ValueError: target_field $.reviews[*] matched reviews.[0], which holds dict, not a string or number.

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

Summary by CodeRabbit

  • Bug Fixes
    • Red-teaming payloads now reject selected fields containing unsupported values, such as objects, lists, or nulls, before changing the payload.
    • Errors identify the affected field and matched path, making invalid targets easier to diagnose.
    • Invalid input is rejected before the wrapped function runs, with no partial payload changes or attack-count increments.

…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]>
@siddhant-rajhans
siddhant-rajhans requested a review from a team as a code owner November 16, 2026 20:32
@copy-pr-bot

copy-pr-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions

Copy link
Copy Markdown

Warning

⚠️ Deprecation Notice: NVIDIA NeMo Agent Toolkit has been deprecated as of October 2026 and will reach end of life (EOL) by end of year 2026. Depending on your needs, migrate to: NeMo Relay for observability, middleware, and governance. NeMo Helix for a unified CLI with evaluation, optimization, and hardening capabilities. NeMo Fabric for a consistent interface to run agent harnesses and custom agents.
We recommend completing your migration before the EOL date.

Pull request policy: Only bug fixes may be opened as pull requests.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The middleware now raises ValueError when a JSONPath target matches an object, list, or null value. Tests check that rejection leaves the output unchanged, keeps the attack count at zero, and prevents the wrapped function from being called.

Changes

Target validation

Layer / File(s) Summary
Validate matched targets
packages/nvidia_nat_security/src/nat/plugins/security/middleware/red_teaming/red_teaming_middleware.py, packages/nvidia_nat_security/tests/middleware/red_teaming/test_red_teaming_middleware.py
The middleware rejects matched values that are not strings, integers, or floats before applying the payload. Tests verify that object, list, and null matches raise ValueError without changing output or incrementing the attack count. An input-middleware test also verifies that the wrapped function is not called for a null target.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 700bb

The change makes a misconfigured red teaming target field fail with a clear error instead of silently counting an attack that was not delivered. No merge-blocking risk was identified; only the missing category and breaking labels need to be added.

Security architecture risk: Minimal · up to 700bb

The change rejects unsupported attack targets before modifying their values or counting an attack. It preserves the existing middleware boundaries and error-handling pattern, with no introduced or worsened architecture-level security risk established.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(security): reject a red teaming target_field that matches an object, a list or null" describes the main change: RedTeamingMiddleware now raises ValueError when a target_field match is a…
Linked Issues check Passed Directly linked issue #2619 requires that a target_field match holding an object, list, or null raise a ValueError naming the matched path. It also requires that such a run not count an attack. At hea…
Out of Scope Changes check Passed The source change adds a validation loop of about six lines inside _apply_payload_to_complex_type. It directly implements the #2619 requirement and makes no other behavior change. The PR description r…
Full details: Title check

Explanation

The title "fix(security): reject a red teaming target_field that matches an object, a list or null" describes the main change: RedTeamingMiddleware now raises ValueError when a target_field match is an object, list, or null. It is accurate and specific. It uses a conventional-commit prefix, but it is 87 characters, which exceeds the roughly 72-character guideline, and it is not in imperative mood with a concise phrasing. The title is descriptive, so the check passes on content; the length and mood issues are noted for the author.

Full details: Linked Issues check

Explanation

Directly linked issue #2619 requires that a target_field match holding an object, list, or null raise a ValueError naming the matched path. It also requires that such a run not count an attack. At head 700bbff, _apply_payload_to_complex_type checks every selected match in a loop before any update. It raises ValueError with the target_field, match.full_path, and type name when match.value is not str, int, or float. The check runs before match.full_path.update and before _call_count is incremented in _apply_payload_to_function_value, so the value and count are unchanged on error. Both input (pre_invoke) and output (post_invoke) paths route complex values through this function, so both the output and null-input cases are covered. Under the error strategy, the multiple-match error still fires before this check. The unselected matches under random, first, or last are not validated, which is consistent with those strategies only applying to the selected match. The new tests named in the PR description were not read in this assessment. The conclusion rests on the source at head.

Full details: Out of Scope Changes check

Explanation

The source change adds a validation loop of about six lines inside _apply_payload_to_complex_type. It directly implements the #2619 requirement and makes no other behavior change. The PR description reports the added tests cover the requested object, list, null, and input cases. The test diff was not inspected, but its described scope matches #2619 and supports the fix. No unrelated changes were identified from the source evidence.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 36cbbc0 and 700bbff.

Files selected for processing: 2

  • packages/nvidia_nat_security/src/nat/plugins/security/middleware/red_teaming/red_teaming_middleware.py
  • packages/nvidia_nat_security/tests/middleware/red_teaming/test_red_teaming_middleware.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@willkill07 willkill07 added bug Something isn't working non-breaking Non-breaking change labels Nov 18, 2026
@willkill07

Copy link
Copy Markdown
Member

/ok to test 700bbff

@willkill07

Copy link
Copy Markdown
Member

/merge

@rapids-bot
rapids-bot Bot merged commit db7ae48 into NVIDIA:develop Nov 18, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Red teaming middleware nulls a target_field that matches an object, a list or null, and still counts the attack

2 participants