Files
openidea/src/platform/appCsp.test.ts
T
rohitkumardandaandrohitdanda 86f7b747a5 fix(security): stop other pages from embedding the app's own pages (#2998)
The app's CSP now includes `frame-ancestors 'none'`, so no page (for example a project's HTML in the built-in preview) can embed the IDE's own pages in a frame. Notebook HTML output, plugin views (srcdoc frames) and the built-in HTML preview still render in a debug bundle that serves the CSP.

Co-authored-by: rohitdanda <10144914+rohitdanda@users.noreply.github.com>
2026-11-13 13:46:25 +08:00

22 lines
782 B
TypeScript

// @vitest-environment node
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
/** The app's CSP, which Tauri sends as a response header with every HTML page it serves. */
function directives(): Map<string, string[]> {
const conf = JSON.parse(readFileSync("src-tauri/tauri.conf.json", "utf8"));
const csp: string = conf.app.security.csp;
const map = new Map<string, string[]>();
for (const part of csp.split(";")) {
const [name, ...sources] = part.trim().split(/\s+/);
if (name) map.set(name.toLowerCase(), sources);
}
return map;
}
describe("app content security policy", () => {
it("does not let any page embed the app's own pages", () => {
expect(directives().get("frame-ancestors")).toEqual(["'none'"]);
});
});