Skip to content

Commit ab402bf

Browse files
committed
fix: improve vscode-cdn.net URL validation and add copy action check
- Fixed CodeQL security issue by properly validating vscode-cdn.net domain instead of substring check - Added missing copy action check for HTTPS/vscode-cdn URLs before opening image - Updated tests to match the more secure URL validation logic
1 parent b10c874 commit ab402bf

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/integrations/misc/__tests__/image-handler.spec.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ vi.mock("vscode", () => {
55
const showErrorMessage = vi.fn()
66
const file = vi.fn((p: string) => ({ fsPath: p, path: p, scheme: "file" }))
77
const parse = (input: string) => {
8-
if (input.startsWith("https://") && input.includes("vscode-cdn.net")) {
8+
if (input.startsWith("https://")) {
99
const url = new URL(input)
10-
return {
11-
scheme: "https",
12-
authority: url.host,
13-
path: url.pathname,
14-
fsPath: url.pathname,
15-
with: vi.fn(),
10+
// More secure check: ensure vscode-cdn.net is the actual domain, not just a substring
11+
if (url.host === "vscode-cdn.net" || url.host.endsWith(".vscode-cdn.net")) {
12+
return {
13+
scheme: "https",
14+
authority: url.host,
15+
path: url.pathname,
16+
fsPath: url.pathname,
17+
with: vi.fn(),
18+
}
1619
}
1720
}
1821
if (input.startsWith("file://")) {

src/integrations/misc/image-handler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@ export async function openImage(dataUriOrPath: string, options?: { values?: { ac
1010
// Example: https://file+.vscode-resource.vscode-cdn.net/file/<absolute_path_to_image>
1111
try {
1212
const u = vscode.Uri.parse(dataUriOrPath)
13-
if (u.scheme === "https" && u.authority.includes("vscode-cdn.net")) {
13+
if (
14+
u.scheme === "https" &&
15+
u.authority &&
16+
(u.authority === "vscode-cdn.net" || u.authority.endsWith(".vscode-cdn.net"))
17+
) {
1418
let fsPath = decodeURIComponent(u.path || "")
1519
// Strip the leading "/file/" prefix if present
1620
if (fsPath.startsWith("/file/")) {
1721
fsPath = fsPath.slice("/file/".length)
1822
}
1923
fsPath = path.normalize(fsPath)
2024
if (fsPath) {
21-
const fileUri = vscode.Uri.file(fsPath)
2225
if (options?.values?.action === "copy") {
2326
await vscode.env.clipboard.writeText(fsPath)
2427
vscode.window.showInformationMessage(t("common:info.path_copied_to_clipboard"))
2528
return
2629
}
30+
const fileUri = vscode.Uri.file(fsPath)
2731
await vscode.commands.executeCommand("vscode.open", fileUri)
2832
return
2933
}

0 commit comments

Comments
 (0)