Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/core/src/codewhispererChat/tools/executeBash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,24 +189,24 @@ export class ExecuteBash {
if (cmdArgs.length === 0) {
return { requiresAcceptance: true }
}

let hasOutsideWorkspacePath = false
// For each command, validate arguments for path safety within workspace
for (const arg of cmdArgs) {
if (this.looksLikePath(arg)) {
// 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, warning: destructiveCommandWarningMessage }
hasOutsideWorkspacePath = true
continue
}
const isInWorkspace = workspaceFolders.some((folder) =>
isInDirectory(folder.uri.fsPath, fullPath)
)
if (!isInWorkspace) {
return { requiresAcceptance: true, warning: destructiveCommandWarningMessage }
hasOutsideWorkspacePath = true
}
}
}
Expand All @@ -220,6 +220,9 @@ export class ExecuteBash {
case CommandCategory.Mutate:
return { requiresAcceptance: true, warning: mutateCommandWarningMessage }
case CommandCategory.ReadOnly:
if (hasOutsideWorkspacePath) {
return { requiresAcceptance: true }
}
continue
default:
return { requiresAcceptance: true }
Expand Down