import { readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; import { resolveRepoPath } from "~/utils/testing/repoPaths"; import { normalizeSignatureSvg, SignatureServiceError } from "./signatureService.server"; describe("signature payload security", () => { it("removes scriptable SVG elements and event handlers before persistence", () => { const sanitized = normalizeSignatureSvg('bad'); expect(sanitized).toContain(" { expect(() => normalizeSignatureSvg("plain text")).toThrowError( expect.objectContaining>({ messageKey: "signature.error.signatureInvalid" }) ); expect(() => normalizeSignatureSvg(`${"x".repeat(65 * 1024)}`)).toThrowError( expect.objectContaining>({ messageKey: "signature.error.signatureInvalid" }) ); }); it("gives generated signature artifacts the narrow own-file scope needed for linking", () => { const source = readFileSync(resolveRepoPath("apps/web/app/modules/signature/services/signatureService.server.ts"), "utf8"); expect(source).toContain('permissions: ["files.read_own", "projects.read_all", "signature.read"]'); }); });