Skip to content

Commit 8e7fa75

Browse files
committed
Add path validation to handle_go_to_file handler
└── apps └── editor └── src ├── commands │ └── apply-response-command │ ├── response-processor │ │ └── handlers │ │ └── fast-replace-handler.ts │ └── utils │ └── file-operations │ └── create-file-if-needed.ts ├── utils │ └── path-sanitizer.ts └── views └── prompt ├── backend │ ├── message-handlers │ │ ├── handle-go-to-file.ts │ │ ├── handle-patch-repair.ts │ │ └── index.ts │ └── prompt-view-provider.ts ├── frontend │ ├── Main │ │ ├── Main.tsx │ │ └── MainView │ │ └── MainView.tsx │ └── Prompt.tsx └── types └── messages.ts
1 parent d51b1d3 commit 8e7fa75

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-go-to-file.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode'
22
import { GoToFileMessage } from '@/views/prompt/types/messages'
33
import { Logger } from '@shared/utils/logger'
44
import { t } from '@/i18n'
5+
import { create_safe_path } from '@/utils/path-sanitizer'
56

67
export const handle_go_to_file = async (
78
message: GoToFileMessage
@@ -58,7 +59,24 @@ export const handle_go_to_file = async (
5859
return
5960
}
6061

61-
const file_uri = vscode.Uri.joinPath(target_workspace.uri, relative_file_path)
62+
const safe_path = create_safe_path(
63+
target_workspace.uri.fsPath,
64+
relative_file_path
65+
)
66+
67+
if (!safe_path) {
68+
Logger.error({
69+
function_name: 'handle_go_to_file',
70+
message: `Invalid file path: ${file_path}`,
71+
data: { file_path }
72+
})
73+
vscode.window.showErrorMessage(
74+
t('common.error.could-not-open-file', { file_path })
75+
)
76+
return
77+
}
78+
79+
const file_uri = vscode.Uri.file(safe_path)
6280

6381
try {
6482
const document = await vscode.workspace.openTextDocument(file_uri)

0 commit comments

Comments
 (0)