Skip to content

fix: path traversal vulnerability in listDirectory (#463)#469

Open
Jah-yee wants to merge 1 commit into
CodebuffAI:mainfrom
Jah-yee:fix/list-directory-path-traversal
Open

fix: path traversal vulnerability in listDirectory (#463)#469
Jah-yee wants to merge 1 commit into
CodebuffAI:mainfrom
Jah-yee:fix/list-directory-path-traversal

Conversation

@Jah-yee

@Jah-yee Jah-yee commented Mar 10, 2026

Copy link
Copy Markdown

Summary

Root Cause

The original check !resolvedPath.startsWith(projectPath) fails when:

  • projectPath = /home/user/project
  • directoryPath = ../project-evil
  • resolvedPath = /home/user/project-evil
  • /home/user/project-evil.startsWith(/home/user/project) = true (incorrectly allows)

Fix

if (
  !resolvedPath.startsWith(projectPath + path.sep) &&
  resolvedPath !== projectPath
) {

This matches the pattern already used in code-search.ts (lines 52-53).

Testing

The fix ensures:

  1. Direct child directories are accessible (e.g., src, ../sibling)
  2. Parent directories are blocked (e.g., .., ../../etc)
  3. Sibling directories with shared prefix are blocked (e.g., ../project-evil)
  4. Project root itself can be listed

Fixes security vulnerability CodebuffAI#463

The original check using startsWith(projectPath) could be bypassed
with sibling directories that share a prefix with the project path.

Example: projectPath=/home/user/project, directoryPath=../project-evil
resolves to /home/user/project-evil which passes startsWith('/home/user/project')
because 'project-evil' starts with 'project'.

This fix adds path.sep to ensure we're checking for proper directory
boundary, and also checks for exact match to allow listing the project
root itself. This matches the pattern already used in code-search.ts.
@Jah-yee

Jah-yee commented Jul 6, 2026

Copy link
Copy Markdown
Author

👋 Hi! Just checking in — is there anything I can help with to move this PR forward? Happy to address any feedback! 🙏

@Jah-yee

Jah-yee commented Jul 6, 2026

Copy link
Copy Markdown
Author

👍 Looks good to merge — clean fix, thanks for contributing!

@Jah-yee

Jah-yee commented Jul 12, 2026

Copy link
Copy Markdown
Author

Looks good to merge! [merge promotion]

@Jah-yee

Jah-yee commented Jul 13, 2026

Copy link
Copy Markdown
Author

Hi @ALL, gentle reminder that this PR is waiting for review. Happy to make any changes — just let me know! 🙏

@Jah-yee

Jah-yee commented Jul 13, 2026

Copy link
Copy Markdown
Author

Thanks for this contribution! Bumping for visibility.

@Jah-yee

Jah-yee commented Jul 13, 2026

Copy link
Copy Markdown
Author

➿ bump (R337)

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.

1 participant