дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
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]>
33 рядки
892 B
TypeScript
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();
|
|
});
|
|
});
|