Skip to content

fix: validate reviewAgentLogPath to prevent path injection#1133

Closed
msukkari wants to merge 2 commits intomainfrom
cursor/fix-path-injection-review-agent-eb42
Closed

fix: validate reviewAgentLogPath to prevent path injection#1133
msukkari wants to merge 2 commits intomainfrom
cursor/fix-path-injection-review-agent-eb42

Conversation

@msukkari
Copy link
Copy Markdown
Contributor

Summary

This PR addresses CodeQL security alerts #18 and #19 for js/path-injection in the review agent log writing functionality.

Changes

Added path validation in invokeDiffReviewLlm to ensure the reviewAgentLogPath parameter stays within the expected review-agent directory. The validation:

  1. Resolves the provided path to an absolute path using path.resolve()
  2. Verifies the resolved path starts with the expected base directory (DATA_CACHE_DIR/review-agent/)
  3. Throws an error if the path escapes the log directory

This single guard covers both fs.appendFileSync calls in the function (lines 36 and 49), preventing potential path traversal attacks.

Security Context

While the current risk is low (since pullRequest.number is an integer from the GitHub webhook payload), this validation provides defense-in-depth against future code changes that might introduce different data sources for path construction.

Testing

  • Lint passes
  • All 391 existing tests pass

Fixes #931

Linear Issue: SOU-931

Open in Web Open in Cursor 

Add path validation in invokeDiffReviewLlm to ensure the log file path
stays within the expected review-agent directory. This prevents potential
path traversal attacks by validating that the resolved path starts with
the expected base directory (DATA_CACHE_DIR/review-agent).

Fixes CodeQL js/path-injection alerts #18 and #19.

Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 18, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: af5e67fa-b6ab-4e02-954a-f23640a01542

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/fix-path-injection-review-agent-eb42

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
@msukkari msukkari closed this Apr 18, 2026
@msukkari msukkari deleted the cursor/fix-path-injection-review-agent-eb42 branch April 18, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants