31 lines
1.5 KiB
TypeScript
31 lines
1.5 KiB
TypeScript
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('<svg onload="alert(1)"><script>alert(1)</script><foreignObject>bad</foreignObject><path d="M0 0" /></svg>');
|
|
|
|
expect(sanitized).toContain("<svg");
|
|
expect(sanitized).toContain("<path");
|
|
expect(sanitized).not.toMatch(/script|foreignObject|onload/iu);
|
|
});
|
|
|
|
it("rejects non-SVG and oversized signature payloads", () => {
|
|
expect(() => normalizeSignatureSvg("plain text")).toThrowError(
|
|
expect.objectContaining<Partial<SignatureServiceError>>({ messageKey: "signature.error.signatureInvalid" })
|
|
);
|
|
expect(() => normalizeSignatureSvg(`<svg>${"x".repeat(65 * 1024)}</svg>`)).toThrowError(
|
|
expect.objectContaining<Partial<SignatureServiceError>>({ 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"]');
|
|
});
|
|
|
|
});
|