Файли
openidea/src/platform/paths.test.ts
T
Fabio Nunes Cerqueira a497178b3e fix(security): close the findings of GHSA-442p-gxfg-qxv9
- Restricted Mode git: reads run without a signature verifier, hooks
  (including config-defined ones), an external diff, filters or a lazy
  fetch, also inside submodules; every repository and every git starts
  restricted until the project is trusted.
- project.write and plugin quick fixes cannot reach git's own files under
  any spelling or through links; project.write is a high-risk grant.
- Built-in web server: each served root has its own port and token; a
  file outside the project is served with its folder minus dot names, or
  alone when that folder is the home folder or above it; no fixed port.
- Images, references, Markdown links and language-server links reach no
  network share other than the one already open.
- Marketplace: entries whose id or version no manifest may carry are
  dropped; an index read over the network names nothing on this machine;
  network reads are bounded in size and time.
- Agent replies load remote images on a click; the Markdown preview and
  Mermaid configuration no longer fetch from other hosts.
2026-11-11 22:18:48 +08:00

79 рядки
3.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { ipcPath, onOtherShare, opensOtherShare } from "./paths";
const raw = String.raw;
const APPDATA = raw`C:\Users\me\AppData\Roaming\ai.l0ng.openidea`;
describe("ipcPath", () => {
it("slashes Windows drive paths, plain or verbatim", () => {
expect(ipcPath(APPDATA)).toBe("C:/Users/me/AppData/Roaming/ai.l0ng.openidea");
expect(ipcPath(raw`\\?\C:\Users\me`)).toBe("C:/Users/me");
});
it("slashes network shares", () => {
expect(ipcPath(raw`\\server\share\dir`)).toBe("//server/share/dir");
expect(ipcPath(raw`\\?\UNC\server\share\dir`)).toBe("//server/share/dir");
});
it("leaves UI paths and POSIX paths alone", () => {
expect(ipcPath("C:/Users/me")).toBe("C:/Users/me");
expect(ipcPath("/home/me/notes")).toBe("/home/me/notes");
// A backslash is a legal character in a POSIX file name.
expect(ipcPath(raw`/home/me/a\b.txt`)).toBe(raw`/home/me/a\b.txt`);
});
});
describe("onOtherShare", () => {
it("is true for a share the base is not on", () => {
for (const base of ["C:/repo/a.md", "", "//nas/work/a.md", "//evil/other/a.md", "//evil"]) {
expect(onOtherShare("//evil/share/a.png", base), base).toBe(true);
expect(onOtherShare(raw`\\evil\share\a.png`, base), base).toBe(true);
}
// A server alone, and spellings with no server to compare.
for (const path of ["//evil", "//evil/", raw`/\\evil/share/a.png`]) {
expect(onOtherShare(path, "//evil/share/a.md"), path).toBe(true);
}
});
// A project on a share gets its paths from the host as `//?/UNC/server/share/…`.
it("reads the server and share of a device path", () => {
const base = "//?/UNC/nas/work/app/a.md";
expect(onOtherShare("//?/UNC/evil/share/a.png", base)).toBe(true);
expect(onOtherShare("//?/UNC/nas/private/a.png", base)).toBe(true);
expect(onOtherShare("//evil/share/a.png", base)).toBe(true);
expect(onOtherShare("//?/UNC", base)).toBe(true);
expect(onOtherShare("//?/C:/a.png", "//?/C:/a.md")).toBe(true);
expect(onOtherShare("//?/unc/NAS/Work/lib/a.png", base)).toBe(false);
expect(onOtherShare("//nas/work/lib/a.png", base)).toBe(false);
expect(onOtherShare("//?/UNC/nas/work/lib/a.png", "//nas/work/app/a.md")).toBe(false);
});
it("is false on the base's own share and off any share", () => {
expect(onOtherShare("//NAS/Work/lib/a.png", "//nas/work/app/a.md")).toBe(false);
expect(onOtherShare(raw`\\nas\work\lib\a.png`, "//nas/work/app/a.md")).toBe(false);
expect(onOtherShare("C:/repo/a.png", "//nas/work/app/a.md")).toBe(false);
expect(onOtherShare("/abs/a.png", "C:/repo/a.md")).toBe(false);
});
});
describe("opensOtherShare", () => {
it("is true for a share the text names itself, in any mix of slashes", () => {
for (const written of ["//evil/share/a.png", raw`\\evil\share\a.png`, raw`/\evil/share/a.png`, raw`\/evil/a.png`]) {
expect(opensOtherShare(written, written, "C:/repo"), written).toBe(true);
expect(opensOtherShare(written, written, "//nas/work"), written).toBe(true);
}
});
it("is true for a share that only appears once the path is resolved", () => {
expect(opensOtherShare(raw`/\evil/share/a.png`, raw`\evil/share/a.png`, "")).toBe(true);
expect(opensOtherShare(raw`/\evil/share/a.png`, raw`../\evil/share/a.png`, "/guide.md")).toBe(true);
expect(opensOtherShare("//evil/share/a.png", "a.png", "//nas/work")).toBe(true);
});
it("is false on a local drive and on the share the text is on", () => {
expect(opensOtherShare("C:/repo/docs/a.png", "docs/a.png", "C:/repo")).toBe(false);
expect(opensOtherShare("/abs/a.png", "/abs/a.png", "C:/repo")).toBe(false);
expect(opensOtherShare("//nas/work/docs/a.png", "docs/a.png", "//nas/work")).toBe(false);
});
});