Файли
openidea/src/platform/openUrl.test.ts
T
rohitkumardandaтаrohitdanda 21046c3047 fix(platform): open only http(s) and mailto URLs externally (#2755)
openExternalUrl handed any string to the system opener, and plugins and rendered content (Markdown, notebook output, editor links) reach it with arbitrary input, so file: or app-launching schemes such as ms-msdt: and search-ms: could be passed to the OS. It now opens only http:, https: and mailto: URLs and ignores anything else, including malformed or whitespace-padded strings.

Co-authored-by: rohitdanda <[email protected]>
2026-11-11 23:32:18 +08:00

33 рядки
892 B
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const openUrl = vi.fn(async (_url: string) => {});
vi.mock("./ipc", () => ({ isTauri: () => true }));
vi.mock("@tauri-apps/plugin-opener", () => ({ openUrl }));
import { openExternalUrl } from "./openUrl";
describe("openExternalUrl", () => {
beforeEach(() => openUrl.mockClear());
it.each(["https://example.com/a?b=1", "http://localhost:3000/", "mailto:[email protected]"])("opens %s", async (url) => {
await openExternalUrl(url);
expect(openUrl).toHaveBeenCalledWith(url);
});
it.each([
"file:///C:/Windows/win.ini",
"ms-msdt:/id x",
"search-ms:query=x",
"javascript:alert(1)",
"data:text/html,x",
"//evil.example",
" https://example.com",
"example.com",
"",
])("refuses %j", async (url) => {
await openExternalUrl(url);
expect(openUrl).not.toHaveBeenCalled();
});
});