Skip to content

fix(github-dev-assistant): reject path traversal in repo path parameters#122

Open
konard wants to merge 3 commits intoxlabtg:mainfrom
konard:issue-115-e5ad359022df
Open

fix(github-dev-assistant): reject path traversal in repo path parameters#122
konard wants to merge 3 commits intoxlabtg:mainfrom
konard:issue-115-e5ad359022df

Conversation

@konard
Copy link
Copy Markdown

@konard konard commented Apr 7, 2026

Summary

Fixes #115 — path traversal vulnerability in github_get_file (and related tools) where a caller could supply a path like ../.github/workflows/deploy.yml and the GitHub API would resolve the .. segments, potentially exposing files outside the intended scope.

Root cause

Six tools in repo-ops.js and file-ops.js interpolated the path parameter directly into the GitHub API URL without validating it:

  • github_get_file
  • github_update_file
  • github_delete_file
  • github_list_directory
  • github_list_files
  • github_download_file

While encodeURIComponent was used on owner and repo, path was passed raw, allowing .. segments to be sent to the API.

Fix

Added a validateRepoPath(path) helper to utils.js that:

  1. Rejects paths starting with / (repo paths are always relative)
  2. Splits on / and \ and rejects any segment equal to ..

Each of the six affected tools now calls validateRepoPath immediately after validateRequired, returning { success: false, error: "..." } before any API call is made.

Tests

Added plugins/github-dev-assistant/tests/repo-ops.test.js with 20 unit tests covering:

  • .. alone, ../etc/passwd, src/../../etc/passwd
  • Backslash traversal src\..\..\etc\passwd
  • Absolute paths /src/index.js, /
  • Non-string inputs (number, null)
  • Valid paths: src/index.js, .github/workflows/ci.yml, README.md, empty string

All 232 existing and new tests pass.

Test plan

  • npm test passes (232 pass, 0 fail)
  • validateRepoPath unit tests cover traversal attacks, absolute paths, edge cases, and valid paths
  • Affected tools validated: github_get_file, github_update_file, github_delete_file, github_list_directory, github_list_files, github_download_file

🤖 Generated with Claude Code

konard and others added 2 commits April 7, 2026 11:10
Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: xlabtg#115
…ers (issue xlabtg#115)

Add `validateRepoPath` helper to `utils.js` that rejects any path
containing `..` segments or starting with `/`. Apply the check in
`github_get_file`, `github_update_file`, `github_delete_file`,
`github_list_directory`, `github_list_files`, and `github_download_file`
before the path is interpolated into the GitHub API URL, preventing
directory traversal attacks. Add `repo-ops.test.js` with 20 unit tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] Security: github_get_file allows path traversal via '..' in path parameter fix(github-dev-assistant): reject path traversal in repo path parameters Apr 7, 2026
@konard konard marked this pull request as ready for review April 7, 2026 11:14
@konard
Copy link
Copy Markdown
Author

konard commented Apr 7, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $0.977176
  • Calculated by Anthropic: $0.977176 USD
  • Difference: $-0.000000 (-0.00%)

📊 Context and tokens usage:

  • Context window: 61.1K / 1M input tokens (6%), 12.1K / 64K output tokens (19%)

Total: 52.4K + 2.0M cached input tokens, 12.1K output tokens, $0.977176 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: sonnet
  • Model: Claude Sonnet 4.6 (claude-sonnet-4-6)

📎 Log file uploaded as Gist (924KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Author

konard commented Apr 7, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

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.

Security: github_get_file allows path traversal via '..' in path parameter

1 participant