-
Notifications
You must be signed in to change notification settings - Fork 749
feat(chat): Add validation to fileRead, ListDir and ExecBash tool #6987
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,9 @@ import { fs } from '../../shared/fs/fs' | |
| import { ChildProcess, ChildProcessOptions } from '../../shared/utilities/processUtils' | ||
| import { InvokeOutput, OutputKind, sanitizePath } from './toolShared' | ||
| import { split } from 'shlex' | ||
| import path from 'path' | ||
| import * as vscode from 'vscode' | ||
| import { isInDirectory } from '../../shared/filesystemUtilities' | ||
|
|
||
| export enum CommandCategory { | ||
| ReadOnly, | ||
|
|
@@ -191,6 +194,27 @@ export class ExecuteBash { | |
| return { requiresAcceptance: true } | ||
| } | ||
| } | ||
| for (const cmdArgs of allCommands) { | ||
| for (const arg of cmdArgs) { | ||
| if (this.looksLikePath(arg)) { | ||
|
Comment on lines
+197
to
+199
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. what is going on here? you have coded a double loop without a comment giving a hint about what it does. |
||
| // If not absolute, resolve using workingDirectory if available. | ||
| let fullPath = arg | ||
| if (!path.isAbsolute(arg) && this.workingDirectory) { | ||
| fullPath = path.join(this.workingDirectory, arg) | ||
| } | ||
| const workspaceFolders = vscode.workspace.workspaceFolders | ||
| if (!workspaceFolders || workspaceFolders.length === 0) { | ||
| return { requiresAcceptance: true } | ||
| } | ||
| const isInWorkspace = workspaceFolders.some((folder) => | ||
| isInDirectory(folder.uri.fsPath, fullPath) | ||
| ) | ||
| if (!isInWorkspace) { | ||
| return { requiresAcceptance: true } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return { requiresAcceptance: false } | ||
| } catch (error) { | ||
| this.logger.warn(`Error while checking acceptance: ${(error as Error).message}`) | ||
|
|
@@ -306,4 +330,8 @@ export class ExecuteBash { | |
| updates.write('```shell\n' + this.command + '\n```') | ||
| updates.end() | ||
| } | ||
|
|
||
| private looksLikePath(arg: string): boolean { | ||
| return arg.startsWith('/') || arg.startsWith('./') || arg.startsWith('../') | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nls.json is only necessary if these strings are used in package.json
and for common strings, update
packages/core/src/shared/localizedText.ts, don't repeat them with different ids. Why would "fsRead" and "listDirectory" have different words for "Run"? Avoid over-abstracting, that is even more costly than not abstracting at all.