Skip to content

fix: reject malformed PII target paths#561

Open
afourniernv wants to merge 1 commit into
NVIDIA:mainfrom
afourniernv:fix/pii-target-path-validation
Open

fix: reject malformed PII target paths#561
afourniernv wants to merge 1 commit into
NVIDIA:mainfrom
afourniernv:fix/pii-target-path-validation

Conversation

@afourniernv

@afourniernv afourniernv commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Overview

Reject malformed RFC 6901 target_paths before the PII redaction backend activates. Invalid pointers previously activated successfully and could silently leave the intended values unsanitized.

  • I confirm this contribution is my own work, or I have the right to submit it under this project's license.
  • I searched existing issues and open pull requests, and this does not duplicate existing work.

Details

  • Validate legacy and profile target_paths with indexed configuration diagnostics.
  • Enforce the same check while constructing the built-in backend, so malformed paths cannot activate when unsupported-value diagnostics are downgraded to warnings.
  • Preserve valid RFC 6901 behavior, including the empty root pointer, empty path segments, and ~0/~1 escapes.
  • Document the path syntax and fail-fast behavior.
  • Do not require paths to exist in every payload; provider-specific and optional fields may be absent legitimately.

Validation:

  • cargo test -p nemo-relay-pii-redaction -q (91 passed)
  • cargo test -p nemo-relay --features worker-grpc --test worker_plugin_integration (29 passed)
  • cargo clippy --workspace --all-targets -- -D warnings
  • just docs
  • uv run pre-commit run --all-files
  • just test-rust reached one unrelated nemo_guardrails coverage failure caused by an invalid local ./rails path; the exact failing test passed on immediate isolated rerun.

Where should the reviewer start?

Start with is_valid_json_pointer and the backend-construction guard in crates/pii-redaction/src/builtin.rs, then the indexed diagnostics and regression coverage in component.rs and component_tests.rs.

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

Summary by CodeRabbit

  • Bug Fixes

    • Added validation for PII redaction target paths using RFC 6901 JSON Pointer syntax.
    • Invalid paths now produce clear configuration errors and prevent plugin activation.
    • Diagnostics identify the specific invalid path, including its array index.
  • Documentation

    • Clarified valid path formats, root selection, and required escaping rules.
  • Tests

    • Added coverage for valid, invalid, and escaped target paths.

Signed-off-by: Alex Fournier <afournier@nvidia.com>
@afourniernv
afourniernv requested review from a team as code owners July 26, 2026 03:54
@copy-pr-bot

copy-pr-bot Bot commented Jul 26, 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 github-actions Bot added size:M PR is medium Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code labels Jul 26, 2026
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

PII redaction target_paths entries are now validated as RFC 6901 JSON pointers during configuration validation and backend compilation. Invalid entries produce indexed diagnostics and prevent activation. Tests and documentation cover root, escaped, malformed, and profile-qualified paths.

Changes

PII target path validation

Layer / File(s) Summary
RFC 6901 pointer validation
crates/pii-redaction/src/builtin.rs
Adds JSON-pointer syntax validation and rejects malformed target_paths during backend compilation.
Plugin configuration diagnostics
crates/pii-redaction/src/component.rs
Validates each configured path, reports the invalid array index, and documents RFC 6901 path syntax.
Validation and activation coverage
crates/pii-redaction/tests/unit/component_tests.rs, docs/configure-plugins/pii-redaction/configuration.mdx
Tests malformed, valid, profile-qualified, and activation-time paths; documents root selection, leading slashes, and escaping rules.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy #559 by rejecting malformed JSON pointers before activation and preserving valid root and escape forms with indexed diagnostics.
Out of Scope Changes check ✅ Passed The diff is focused on validation, tests, and documentation for target_paths and does not show unrelated scope creep.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title follows Conventional Commits and accurately summarizes the malformed PII target path validation fix.
Description check ✅ Passed The description matches the template with Overview, Details, reviewer start, checklist items, and related issues, and is sufficiently specific.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/pii-redaction/src/builtin.rs`:
- Around line 118-124: Validate config.target_paths before constructing or
checking the preset so malformed RFC 6901 pointers always produce indexed
diagnostics and activation errors. Apply this ordering in
crates/pii-redaction/src/builtin.rs at lines 118-124 and
crates/pii-redaction/src/component.rs at lines 1038-1049, preserving valid
preset behavior. Add preset-plus-malformed-path assertions covering both
diagnostics and activation in crates/pii-redaction/tests/unit/component_tests.rs
at lines 1514-1539.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: f457302c-5165-4d84-9cab-1c569252c3ad

📥 Commits

Reviewing files that changed from the base of the PR and between 9d16c07 and 69bef14.

📒 Files selected for processing (4)
  • crates/pii-redaction/src/builtin.rs
  • crates/pii-redaction/src/component.rs
  • crates/pii-redaction/tests/unit/component_tests.rs
  • docs/configure-plugins/pii-redaction/configuration.mdx
📜 Review details
🧰 Additional context used
📓 Path-based instructions (16)
**/*.mdx

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/SKILL.md)

MDX top-of-file SPDX comments must use {/* ... */} delimiters instead of HTML comment delimiters (Must-Fix)

In MDX files, top-of-file comments must use JSX comment delimiters ({/* to open and */} to close); do not use HTML comments for MDX SPDX headers

Files:

  • docs/configure-plugins/pii-redaction/configuration.mdx
**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

Update README.md, fern/, package READMEs, and binding-support notes when public behavior, package names, examples, or supported bindings change.

**/*.{md,mdx}: Prefer the documented public API, not internal shortcuts
Keep package names, repo references, and build commands current
Keep release-process and release-notes guidance in repo-maintainer docs such as RELEASING.md, not as user-facing docs pages or CHANGELOG.md
Keep stable user-facing wrappers at scripts/ root in docs and examples; only point at namespaced helper paths when documenting internal maintenance work
When detailed dynamic plugin guides exist, keep Rust native plugin examples, Python worker plugin examples, and grpc-v1 protocol details on separate pages

If links in documentation change, run just docs-linkcheck.

Files:

  • docs/configure-plugins/pii-redaction/configuration.mdx
**/*.{md,markdown,mdx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add the SPDX license header to all Markdown/MDX documentation files using the HTML comment block form.

Files:

  • docs/configure-plugins/pii-redaction/configuration.mdx
{docs,examples}/**/*

📄 CodeRabbit inference engine (.agents/skills/rename-surfaces/SKILL.md)

Update docs and examples.

Files:

  • docs/configure-plugins/pii-redaction/configuration.mdx
**/*

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

**/*: Format changed files with the language-native formatter before the final lint/test pass.
If dynamic plugin behavior changed, use maintain-dynamic-plugins and include the native SDK, worker protocol, Python SDK, docs, packaging, and Codecov surfaces in the validation plan.
If code changes alter APIs, bindings, commands, paths, packaging behavior, observability/adaptive semantics, or documented best practices, update any dependent maintainer or consumer skills in the same branch.
During iteration, prefer uv run pre-commit run --files <changed files...>.
Before review or handoff, run uv run pre-commit run --all-files.

Files:

  • docs/configure-plugins/pii-redaction/configuration.mdx
  • crates/pii-redaction/src/builtin.rs
  • crates/pii-redaction/src/component.rs
  • crates/pii-redaction/tests/unit/component_tests.rs
docs/**/*

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

If documentation examples or commands under docs/ change, run the targeted docs checks appropriate to the change.

Files:

  • docs/configure-plugins/pii-redaction/configuration.mdx
{docs/**,README.md,CONTRIBUTING.md,RELEASING.md,SECURITY.md}

⚙️ CodeRabbit configuration file

{docs/**,README.md,CONTRIBUTING.md,RELEASING.md,SECURITY.md}: Review documentation for technical accuracy against the current API, command correctness, and consistency across language bindings.
Flag stale examples, missing SPDX headers where required, and instructions that no longer match CI or pre-commit behavior.

Files:

  • docs/configure-plugins/pii-redaction/configuration.mdx
**/*.rs

📄 CodeRabbit inference engine (.agents/skills/prepare-pr/SKILL.md)

**/*.rs: Any Rust change must run just test-rust
Any Rust change must run cargo fmt --all
Any Rust change must run cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all for all FFI work since it is Rust work
Run just test-rust to validate FFI changes
Run cargo clippy --workspace --all-targets -- -D warnings to enforce strict linting on FFI work

When Rust files changed as part of Go work, also run cargo fmt --all, just test-rust, and cargo clippy --workspace --all-targets -- -D warnings

**/*.rs: Run cargo fmt --all when Rust files are changed as part of Node work
Run cargo clippy --workspace --all-targets -- -D warnings when Rust files are changed as part of Node work
Run just test-rust when Rust files are changed as part of Node work

When changing the core Rust runtime or Rust-facing API surface, format Rust code with cargo fmt (rustfmt defaults), keep cargo clippy -- -D warnings clean, and satisfy cargo deny check per deny.toml.

**/*.rs: If any Rust code changed, always run just test-rust.
If any Rust code changed, also run cargo fmt --all.
If any Rust code changed, also run cargo clippy --workspace --all-targets -- -D warnings.
For Rust changes headed for review, run cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings even if relying on pre-commit.

Files:

  • crates/pii-redaction/src/builtin.rs
  • crates/pii-redaction/src/component.rs
  • crates/pii-redaction/tests/unit/component_tests.rs
**/*.{rs,py}

📄 CodeRabbit inference engine (AGENTS.md)

Follow binding naming conventions in Rust and Python: use snake_case.

Files:

  • crates/pii-redaction/src/builtin.rs
  • crates/pii-redaction/src/component.rs
  • crates/pii-redaction/tests/unit/component_tests.rs
**/*.{rs,py,js,mjs,cjs,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{rs,py,js,mjs,cjs,ts,tsx}: Use Json = serde_json::Value in Rust-facing runtime APIs where the existing code expects JSON payloads.
Use Result<T> with FlowError in core runtime paths, and keep errors explicit and binding-appropriate at the wrapper layer.
Keep async behavior on the existing tokio-based model; bindings should preserve callback and future lifetimes rather than blocking or hiding async work unexpectedly.

Files:

  • crates/pii-redaction/src/builtin.rs
  • crates/pii-redaction/src/component.rs
  • crates/pii-redaction/tests/unit/component_tests.rs
**/*.{rs,py,go,js,ts,c,h}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Use language-appropriate naming conventions: Rust snake_case, C FFI exports prefixed nemo_relay_, Go PascalCase, Node.js camelCase, and Python snake_case.

Files:

  • crates/pii-redaction/src/builtin.rs
  • crates/pii-redaction/src/component.rs
  • crates/pii-redaction/tests/unit/component_tests.rs
**/*.{rs,go,js,ts}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add the SPDX license header to all Rust, Go, JavaScript, and TypeScript source files using the corresponding // comment form.

Files:

  • crates/pii-redaction/src/builtin.rs
  • crates/pii-redaction/src/component.rs
  • crates/pii-redaction/tests/unit/component_tests.rs
{crates/**/src/**/*.rs,python/**/*.py}

📄 CodeRabbit inference engine (.agents/skills/maintain-dynamic-plugins/SKILL.md)

Do not add tests under src; Rust tests belong in crate tests/ trees, and Python SDK tests belong under python/tests.

Files:

  • crates/pii-redaction/src/builtin.rs
  • crates/pii-redaction/src/component.rs
**/*.{rs,py,go,js,ts}

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

If a language surface changed, always run that language's test target even when Rust core did not change.

Files:

  • crates/pii-redaction/src/builtin.rs
  • crates/pii-redaction/src/component.rs
  • crates/pii-redaction/tests/unit/component_tests.rs
**/*.{rs,py,js,ts,tsx,go,java,kt,swift}

📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)

Add tests covering registration and duplicate names, deregistration and missing names, priority ordering, callback failure policy, scope-local inheritance and cleanup, event payload semantics, immutable mark and scope fields, and parity across affected bindings.

Files:

  • crates/pii-redaction/src/builtin.rs
  • crates/pii-redaction/src/component.rs
  • crates/pii-redaction/tests/unit/component_tests.rs
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}

⚙️ CodeRabbit configuration file

{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}: Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.
Prefer assertions on lifecycle events, scope stacks, middleware ordering, and binding parity over shallow smoke tests.

Files:

  • crates/pii-redaction/tests/unit/component_tests.rs
🔇 Additional comments (4)
crates/pii-redaction/src/builtin.rs (1)

409-424: LGTM!

crates/pii-redaction/src/component.rs (1)

21-22: LGTM!

Also applies to: 189-189

crates/pii-redaction/tests/unit/component_tests.rs (1)

1541-1563: LGTM!

Also applies to: 1565-1607

docs/configure-plugins/pii-redaction/configuration.mdx (1)

289-293: LGTM!

Comment on lines +118 to +124
for (index, target_path) in config.target_paths.iter().enumerate() {
if !is_valid_json_pointer(target_path) {
return Err(PluginError::InvalidConfig(format!(
"builtin.target_paths[{index}] must be a valid RFC 6901 JSON pointer"
)));
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Validate malformed paths before preset short-circuiting.

A config with preset: "trajectory_context" and target_paths: ["invalid"] bypasses both indexed RFC 6901 diagnostics and the indexed activation error because preset validation returns first.

  • crates/pii-redaction/src/builtin.rs#L118-L124: validate target_paths before constructing/checking the preset.
  • crates/pii-redaction/src/component.rs#L1038-L1049: run pointer validation before the preset early return.
  • crates/pii-redaction/tests/unit/component_tests.rs#L1514-L1539: add preset-plus-malformed-path assertions for diagnostics and activation.
📍 Affects 3 files
  • crates/pii-redaction/src/builtin.rs#L118-L124 (this comment)
  • crates/pii-redaction/src/component.rs#L1038-L1049
  • crates/pii-redaction/tests/unit/component_tests.rs#L1514-L1539
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/pii-redaction/src/builtin.rs` around lines 118 - 124, Validate
config.target_paths before constructing or checking the preset so malformed RFC
6901 pointers always produce indexed diagnostics and activation errors. Apply
this ordering in crates/pii-redaction/src/builtin.rs at lines 118-124 and
crates/pii-redaction/src/component.rs at lines 1038-1049, preserving valid
preset behavior. Add preset-plus-malformed-path assertions covering both
diagnostics and activation in crates/pii-redaction/tests/unit/component_tests.rs
at lines 1514-1539.

@willkill07 willkill07 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I would address the outstanding CodeRabbit feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code size:M PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Reject malformed PII target_paths before activation

2 participants