Repository navigation
fix(core): prevent path traversal in custome command file injection #27234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
2858ab7
7bcadec
fa2af98
baefe05
b92af70
bffe155
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,12 @@ export async function readPathFromWorkspace( | |
| const searchDirs = workspace.getDirectories(); | ||
| for (const dir of searchDirs) { | ||
| const potentialPath = path.resolve(dir, pathStr); | ||
|
|
||
| // Security check: ensure the resolved path is actually within the workspace. | ||
| if (!workspace.isPathWithinWorkspace(potentialPath)) { | ||
|
galdawave marked this conversation as resolved.
|
||
| continue; | ||
| } | ||
|
|
||
| try { | ||
| await fs.access(potentialPath); | ||
| absolutePath = potentialPath; | ||
|
|
@@ -81,6 +87,11 @@ export async function readPathFromWorkspace( | |
| ); | ||
|
|
||
| for (const filePath of finalFiles) { | ||
| // Defense in depth: validate each file found within the directory. | ||
| if (!workspace.isPathWithinWorkspace(filePath)) { | ||
| continue; | ||
| } | ||
|
Comment on lines
+91
to
+97
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this check is important for security (defense in depth), calling |
||
|
|
||
| const relativePathForDisplay = path.relative(absolutePath, filePath); | ||
| allParts.push({ text: `--- ${relativePathForDisplay} ---\n` }); | ||
| const result = await processSingleFileContent( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.