Delete unused login and invite tokens on a daily job, and keep their URLs out of logs.

Expired sign-in, save-progress, email-change, and invitation tokens (and any draft they carry) are cleared by a Cloudron scheduler task. Page timing logs record the path without the query string, and mail failures log a request id instead of an address.
This commit is contained in:
adilallo committed 2026-11-10 15:34:33 -07:00
1 parent 73d0856004
commit 46c34a6323
28 files changed
+636 -45

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
import { NextRequest } from "next/server";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
const loggerInfoMock = vi.fn();
const getWebVitalsStorageModeMock = vi.fn();
const appendLocalWebVitalMock = vi.fn();
vi.mock("../../lib/logger", () => ({
logger: {
info: (...args: unknown[]) => loggerInfoMock(...args),
warn: vi.fn(),
error: vi.fn(),
debug: vi.fn(),
},
}));
vi.mock("../../lib/server/webVitals/mode", () => ({
getWebVitalsStorageMode: () => getWebVitalsStorageModeMock(),
}));
vi.mock("../../lib/server/webVitals/localFileStore", () => ({
appendLocalWebVital: (...args: unknown[]) => appendLocalWebVitalMock(...args),
readLocalAggregatedMetrics: () => ({}),
}));
import { POST } from "../../app/api/web-vitals/route";
function post(url: string) {
return new NextRequest("https://x.test/api/web-vitals", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
metric: "lcp",
data: { value: 1200, rating: "good" },
url,
userAgent: "test",
timestamp: "2026-11-10T12:00:00.000Z",
}),
});
}
beforeEach(() => {
loggerInfoMock.mockReset();
getWebVitalsStorageModeMock.mockReset();
appendLocalWebVitalMock.mockReset();
getWebVitalsStorageModeMock.mockReturnValue("external");
});
afterEach(() => {
vi.unstubAllEnvs();
});
describe("POST /api/web-vitals", () => {
it("logs origin and path without the query string", async () => {
const res = await POST(
post(
"https://communityrule.info/api/invites/rule-stakeholder/verify?token=secret",
),
undefined,
);
expect(res.status).toBe(200);
const line = String(loggerInfoMock.mock.calls[0]?.[0]);
expect(line).toContain(
"https://communityrule.info/api/invites/rule-stakeholder/verify",
);
expect(line).not.toContain("token=");
expect(line).not.toContain("secret");
});
it("stores a path-only URL in local mode", async () => {
getWebVitalsStorageModeMock.mockReturnValue("local");
const res = await POST(
post("https://example.test/create/name?facet.size=small"),
undefined,
);
expect(res.status).toBe(200);
expect(appendLocalWebVitalMock).toHaveBeenCalledWith(
expect.objectContaining({
url: "https://example.test/create/name",
}),
);
});
});