fix: reject malformed PII target paths#561
Conversation
Signed-off-by: Alex Fournier <afournier@nvidia.com>
WalkthroughPII redaction ChangesPII target path validation
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
crates/pii-redaction/src/builtin.rscrates/pii-redaction/src/component.rscrates/pii-redaction/tests/unit/component_tests.rsdocs/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 asRELEASING.md, not as user-facing docs pages orCHANGELOG.md
Keep stable user-facing wrappers atscripts/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, andgrpc-v1protocol details on separate pagesIf 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, usemaintain-dynamic-pluginsand 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, preferuv run pre-commit run --files <changed files...>.
Before review or handoff, runuv run pre-commit run --all-files.
Files:
docs/configure-plugins/pii-redaction/configuration.mdxcrates/pii-redaction/src/builtin.rscrates/pii-redaction/src/component.rscrates/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 runjust test-rust
Any Rust change must runcargo fmt --all
Any Rust change must runcargo clippy --workspace --all-targets -- -D warnings
**/*.rs: Runcargo fmt --allfor all FFI work since it is Rust work
Runjust test-rustto validate FFI changes
Runcargo clippy --workspace --all-targets -- -D warningsto enforce strict linting on FFI workWhen Rust files changed as part of Go work, also run
cargo fmt --all,just test-rust, andcargo clippy --workspace --all-targets -- -D warnings
**/*.rs: Runcargo fmt --allwhen Rust files are changed as part of Node work
Runcargo clippy --workspace --all-targets -- -D warningswhen Rust files are changed as part of Node work
Runjust test-rustwhen Rust files are changed as part of Node workWhen changing the core Rust runtime or Rust-facing API surface, format Rust code with
cargo fmt(rustfmt defaults), keepcargo clippy -- -D warningsclean, and satisfycargo deny checkperdeny.toml.
**/*.rs: If any Rust code changed, always runjust test-rust.
If any Rust code changed, also runcargo fmt --all.
If any Rust code changed, also runcargo clippy --workspace --all-targets -- -D warnings.
For Rust changes headed for review, runcargo fmt --allandcargo clippy --workspace --all-targets -- -D warningseven if relying on pre-commit.
Files:
crates/pii-redaction/src/builtin.rscrates/pii-redaction/src/component.rscrates/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.rscrates/pii-redaction/src/component.rscrates/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}: UseJson = serde_json::Valuein Rust-facing runtime APIs where the existing code expects JSON payloads.
UseResult<T>withFlowErrorin 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.rscrates/pii-redaction/src/component.rscrates/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 prefixednemo_relay_, GoPascalCase, Node.jscamelCase, and Pythonsnake_case.
Files:
crates/pii-redaction/src/builtin.rscrates/pii-redaction/src/component.rscrates/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.rscrates/pii-redaction/src/component.rscrates/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 cratetests/trees, and Python SDK tests belong underpython/tests.
Files:
crates/pii-redaction/src/builtin.rscrates/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.rscrates/pii-redaction/src/component.rscrates/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.rscrates/pii-redaction/src/component.rscrates/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!
| 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" | ||
| ))); | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 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: validatetarget_pathsbefore 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-L1049crates/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
left a comment
There was a problem hiding this comment.
LGTM, but I would address the outstanding CodeRabbit feedback.
Overview
Reject malformed RFC 6901
target_pathsbefore the PII redaction backend activates. Invalid pointers previously activated successfully and could silently leave the intended values unsanitized.Details
target_pathswith indexed configuration diagnostics.~0/~1escapes.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 warningsjust docsuv run pre-commit run --all-filesjust test-rustreached one unrelatednemo_guardrailscoverage failure caused by an invalid local./railspath; the exact failing test passed on immediate isolated rerun.Where should the reviewer start?
Start with
is_valid_json_pointerand the backend-construction guard incrates/pii-redaction/src/builtin.rs, then the indexed diagnostics and regression coverage incomponent.rsandcomponent_tests.rs.Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
Summary by CodeRabbit
Bug Fixes
Documentation
Tests