Skip to content

security(analysis): diff parser path traversal — +++ b/../../../etc/passwd escapes workspace root unconfined #2099

Closed

Description

@EffortlessSteven

Problem

`crates/ripr/src/analysis/diff/path.rs:3-11` — `parse_new_path_marker`
strips the `b/` prefix and returns `PathBuf::from(rest)` with no
traversal check and no canonicalization
:

```rust
pub(super) fn parse_new_path_marker(raw: &str) -> Option {
let marker = raw.strip_prefix("+++ ")?;
let path = parse_diff_path_token(marker)?;
if path == "/dev/null" {
return None;
}
let path = path.strip_prefix("b/").unwrap_or(&path);
Some(PathBuf::from(path))
}
```

The unvalidated result is joined verbatim to root at
`crates/ripr/src/analysis/probes/diff.rs:210`:

```rust
location: SourceLocation::new(context.root.join(&context.changed.path), new_line, 1),
```

A crafted diff containing `+++ b/../../../etc/passwd` yields a
`SourceLocation` whose `file` escapes the workspace. The path is then
embedded in SARIF / JSON output and used for snapshot/context lookups.

The LSP layer enforces canonicalize+starts_with confinement
(`crates/ripr/src/lsp/uri.rs:84-93, 129-150` with the symlink-escape
test at uri.rs:298-324), and the explicit-flag CLI validators do the same
(`crates/ripr/src/cli/commands_agent_support.rs:11-42, 99-131, 150-182`
for `--verify-json`, `--diff`, verify-snapshot, brief-diff). But the
contents of the diff bypass that — the parsed `changed.path` reaches
`root.join()` unconfined.

This is distinct from #1941 (which scoped only explicit CLI path flags
and the receipt/verify surface).

Risk

Depends on downstream consumers of `SourceLocation::file`:

  • If any path reads the file (snapshot, context, repair packet), a crafted
    diff can read arbitrary files the ripr process can access.
  • Even read-only, the escape leaks absolute paths into SARIF / JSON
    output, which is then uploaded to GitHub / CI logs.

Fix

In `parse_new_path_marker` (or at the join site in `probes/diff.rs:210`),
reject or normalize any path containing `..` components or an absolute
prefix before returning. Mirror the canonicalize+`starts_with` helper the
LSP layer uses, applied to the parsed diff path against the workspace
root.

`security(analysis)` rather than `fix(analysis)` because the fix is a
defensive confinement, not a behavior change.

Evidence

  • `crates/ripr/src/analysis/diff/path.rs:3-11` — no traversal check
  • `crates/ripr/src/analysis/probes/diff.rs:210` — `root.join(&context.changed.path)` joins unvalidated
  • `crates/ripr/src/lsp/uri.rs:84-93, 129-150` — the LSP confinement pattern to mirror
  • `crates/ripr/src/cli/commands_agent_support.rs:11-42` — the explicit-flag confinement pattern

Non-goals

Activity

  1. coderabbitai commented on Jul 21, 2026

    @coderabbitai
    🔗 Related PRs

    #1612 - fix(lsp): reject ambiguous workspace roots [merged]
    #1671 - fix(lsp): retain full analysis input identity [merged]
    #1714 - audit(goals): add fail-closed authority audit framework [merged]
    #2037 - fix: 5 quick correctness fixes from deep audit (--no-ext-diff, JSON escape, push_missing trim, dirty-worktree warning, OUTPUT_SCHEMA) [merged]
    #2050 - fix(analysis): close three diff-parser gaps — combined, binary, overflow (#1884) [merged]


    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  2. EffortlessSteven commented on Jul 21, 2026

    @EffortlessSteven
    MemberAuthor

    Fixed in #2139. parse_new_path_marker now lexically confines the parsed path: only Component::Normal components are kept, and any path with a parent-directory, root, or prefix component is rejected. Rejection returns None, which the parser treats like /dev/null — the file is never registered, so no SourceLocation, SARIF/JSON record, or snapshot lookup can escape the workspace root. Covered by 5 new tests in analysis/diff/parse.rs including an end-to-end test that a traversal diff registers zero files. goldens check exit 0 (no drift; no legitimate diff contains escaping paths).

  3. EffortlessSteven commented on Jul 21, 2026

    @EffortlessSteven
    MemberAuthor

    Status: still open on current main

    Verified crates/ripr/src/analysis/diff/path.rs:3-11: parse_new_path_marker still returns the unvalidated path. No traversal check, no canonicalization. The result is joined at crates/ripr/src/analysis/probes/diff.rs:210 via root.join(&context.changed.path) — a .. in the path would escape the workspace root.

    Evidence

    • crates/ripr/src/analysis/diff/path.rs:3-11 — no traversal guard.
    • crates/ripr/src/analysis/probes/diff.rs:210 — root.join(&context.changed.path) uses the unvalidated path.
  4. added
    status/needs-work
    on Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/needs-work

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions