mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
- svg-sanitize.ts: strip each dangerous element repeatedly until stable with whitespace-tolerant end tags, defeating nested/overlapping tags (closes 5 incomplete-multi-character-sanitization + 1 bad-tag-filter; the prior single-pass regex could leave a residual <script>/<iframe>). - file-preview.ts: add a resolve()+containment barrier (the path-traversal guard CodeQL recognizes) on top of the id charset check (closes 9 path-injection). - metadata.ts: bound the XMP namespace:name key segments so parseXmp cannot backtrack polynomially (closes js/polynomial-redos). - analytics-disabled.spec.ts: match analytics by URL host, not substring (closes 4 incomplete-url-substring-sanitization). typecheck + lint green; svg (119), preview (22), metadata (164) tests pass.
96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
// ─── Analytics Disabled (ANALYTICS_ENABLED=false) ───────────────────
|
|
// These tests verify behavior when the server has ANALYTICS_ENABLED=false.
|
|
// They need a Docker container started with ANALYTICS_ENABLED=false.
|
|
//
|
|
// If the container has analytics enabled, these tests will be skipped
|
|
// automatically by checking the config endpoint first.
|
|
|
|
const BASE_URL = process.env.API_URL ?? "http://localhost:1349";
|
|
|
|
async function loginFresh(page: import("@playwright/test").Page) {
|
|
await page.goto("/login");
|
|
await page.getByLabel("Username").fill("admin");
|
|
await page.getByLabel("Password").fill("admin");
|
|
await page.getByRole("button", { name: /login/i }).click();
|
|
}
|
|
|
|
test.describe("Analytics disabled by server", () => {
|
|
test.use({ storageState: { cookies: [], origins: [] } });
|
|
|
|
test.beforeEach(async ({ request: _request }, testInfo) => {
|
|
// Skip this suite if the container has analytics enabled
|
|
const res = await fetch(`${BASE_URL}/api/v1/config/analytics`);
|
|
const config = await res.json();
|
|
if (config.enabled) {
|
|
testInfo.skip();
|
|
}
|
|
});
|
|
|
|
test("config endpoint returns disabled with empty fields", async ({ request }) => {
|
|
const res = await request.get("/api/v1/config/analytics");
|
|
expect(res.ok()).toBeTruthy();
|
|
|
|
const config = await res.json();
|
|
expect(config).toEqual({
|
|
enabled: false,
|
|
posthogApiKey: "",
|
|
posthogHost: "",
|
|
sentryDsn: "",
|
|
sampleRate: 0,
|
|
instanceId: "",
|
|
});
|
|
});
|
|
|
|
test("no consent screen when analytics disabled — goes directly to home", async ({ page }) => {
|
|
await loginFresh(page);
|
|
|
|
// Should go directly to home, NOT to /analytics-consent
|
|
await page.waitForURL("/", { timeout: 30_000 });
|
|
await expect(page).toHaveURL("/");
|
|
});
|
|
|
|
test("no outbound network requests to PostHog or Sentry", async ({ page }) => {
|
|
const analyticsRequests: string[] = [];
|
|
|
|
// Intercept ALL network requests and log any that hit analytics domains
|
|
await page.route("**/*", (route) => {
|
|
const url = route.request().url();
|
|
// Match on the URL host, not a substring, so an unrelated host that merely
|
|
// contains "posthog"/"sentry" can't false-trigger (CodeQL
|
|
// js/incomplete-url-substring-sanitization).
|
|
let host = "";
|
|
try {
|
|
host = new URL(url).hostname.toLowerCase();
|
|
} catch {
|
|
// non-URL scheme (data:/blob:) -- not an analytics host
|
|
}
|
|
if (
|
|
host === "posthog.com" ||
|
|
host.endsWith(".posthog.com") ||
|
|
host === "sentry.io" ||
|
|
host.endsWith(".sentry.io")
|
|
) {
|
|
analyticsRequests.push(url);
|
|
}
|
|
return route.continue();
|
|
});
|
|
|
|
// Login
|
|
await loginFresh(page);
|
|
await page.waitForURL("/", { timeout: 30_000 });
|
|
|
|
// Navigate around
|
|
await page.goto("/resize");
|
|
await page.waitForTimeout(2_000);
|
|
await page.goto("/compress");
|
|
await page.waitForTimeout(2_000);
|
|
await page.goto("/");
|
|
await page.waitForTimeout(2_000);
|
|
|
|
// Assert ZERO analytics requests
|
|
expect(analyticsRequests).toEqual([]);
|
|
});
|
|
});
|