mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Removes Sentry tracing entirely (BullMQ idle polling burned 4.8M transactions in 2 days at the baked 0.1 rate), decouples PostHog sampling, and replaces the type-only error scrub with a vetted-field sanitizer plus SafeError/ToolInputError contracts. One classified capture path with per-signature throttles and a per-process ceiling makes storms impossible (NODE-1E was 4,541 events from one 30s loop). Browser errors move to a dedicated web Sentry project with their own source maps. Adds the SNAPOTTER_TELEMETRY runtime kill switch and silences test fleets. Crash fixes: remote 204/304 SSRF process kill (NODE-20), conversion-preset boot crash loop (NODE-21), Redis version preflight + unhandled subscribe rejection (NODE-1T), Sign PDF on plain-http origins (NODE-1K/1M), wavesurfer/pdf.js teardown rejections (NODE-1P/1N), bundle-import ZlibError to 400 (NODE-1Z), chart-maker input errors declassified (NODE-1H/1J), asset requests skip the session DB lookup (NODE-1D).
93 lines
3.6 KiB
TypeScript
93 lines
3.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildWebBeforeSend,
|
|
DENY_URLS,
|
|
IGNORE_ERRORS,
|
|
scrubBrowserMessage,
|
|
} from "@/lib/sentry-scrub";
|
|
|
|
describe("scrubBrowserMessage", () => {
|
|
it("keeps browser-native messages with urls/paths redacted", () => {
|
|
expect(scrubBrowserMessage("TypeError", "Failed to fetch https://intra.host/x?q=1")).toBe(
|
|
"Failed to fetch <url>",
|
|
);
|
|
expect(scrubBrowserMessage("TypeError", "cannot read /Users/bob/file.png")).toBe(
|
|
"cannot read <path>",
|
|
);
|
|
expect(scrubBrowserMessage("RangeError", "Invalid array length")).toBe("Invalid array length");
|
|
});
|
|
|
|
it("redacts blob urls and windows paths", () => {
|
|
expect(scrubBrowserMessage("DOMException", "load blob:http://x/abc failed")).toBe(
|
|
"load <blob> failed",
|
|
);
|
|
expect(scrubBrowserMessage("TypeError", "open C:\\Users\\bob\\tax.pdf")).toBe("open <path>");
|
|
});
|
|
|
|
it("drops messages for non-native error names", () => {
|
|
expect(scrubBrowserMessage("CustomerDataError", "contains secret.pdf")).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("static filter lists", () => {
|
|
it("deny extension frames and ignore noisy network errors", () => {
|
|
expect(DENY_URLS.some((re) => re.test("chrome-extension://abcdef/content.js"))).toBe(true);
|
|
expect(DENY_URLS.some((re) => re.test("moz-extension://abcdef/content.js"))).toBe(true);
|
|
expect(IGNORE_ERRORS).toContain("Failed to fetch");
|
|
expect(IGNORE_ERRORS).toContain("Load failed");
|
|
});
|
|
});
|
|
|
|
describe("buildWebBeforeSend", () => {
|
|
const baseEvent = (): Record<string, any> => ({
|
|
request: { url: "http://192.168.0.4:1349/image/resize" },
|
|
breadcrumbs: [{}],
|
|
user: { id: "x" },
|
|
contexts: { react: { componentStack: "at ToolPage" }, device: { name: "leak" } },
|
|
exception: {
|
|
values: [
|
|
{
|
|
type: "TypeError",
|
|
value: "secret /Users/a/b",
|
|
stacktrace: { frames: [{ filename: "http://192.168.0.4:1349/assets/app.js" }] },
|
|
},
|
|
],
|
|
},
|
|
tags: { tool_id: "resize", drop_me: "x" },
|
|
});
|
|
|
|
it("gates, strips, keeps react componentStack, redacts values", () => {
|
|
const send = buildWebBeforeSend(() => true);
|
|
const out = send(baseEvent(), { originalException: new TypeError("boom /Users/a/b") })!;
|
|
expect(out.request).toBeUndefined();
|
|
expect(out.breadcrumbs).toBeUndefined();
|
|
expect(out.user).toBeUndefined();
|
|
expect(out.contexts.react.componentStack).toBe("at ToolPage");
|
|
expect(out.contexts.device).toBeUndefined();
|
|
expect(out.exception.values[0].value).toBe("boom <path>");
|
|
expect(out.exception.values[0].stacktrace.frames[0].filename).toBe("/assets/app.js");
|
|
expect(out.tags.tool_id).toBe("resize");
|
|
expect(out.tags.drop_me).toBeUndefined();
|
|
expect(buildWebBeforeSend(() => false)(baseEvent(), {})).toBeNull();
|
|
});
|
|
|
|
it("falls back to type-only for non-native exceptions without a rebuild", () => {
|
|
const send = buildWebBeforeSend(() => true);
|
|
const custom = Object.assign(new Error("user secret"), { name: "WeirdLibError" });
|
|
const out = send(baseEvent(), { originalException: custom })!;
|
|
expect(out.exception.values[0].value).toBe("TypeError");
|
|
});
|
|
|
|
it("enforces the 20-per-hour ceiling", () => {
|
|
const send = buildWebBeforeSend(() => true);
|
|
for (let i = 0; i < 20; i++) expect(send(baseEvent(), {})).not.toBeNull();
|
|
expect(send(baseEvent(), {})).toBeNull();
|
|
});
|
|
|
|
it("never throws on malformed events", () => {
|
|
const send = buildWebBeforeSend(() => true);
|
|
expect(() => send({} as Record<string, any>, {})).not.toThrow();
|
|
expect(() => send({ exception: { values: null } } as any, {})).not.toThrow();
|
|
});
|
|
});
|