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:
1 parent
73d0856004
commit
46c34a6323
28 files changed
+636
-45
No files matched your search
@@ -23,8 +23,8 @@ import { safeInternalPath } from "../../../../../lib/safeInternalPath";
|
||||
import { getPublicOrigin } from "../../../../../lib/server/publicOrigin";
|
||||
import { magicLinkRequestBodySchema } from "../../../../../lib/server/validation/createFlowSchemas";
|
||||
import { jsonFromZodError } from "../../../../../lib/server/validation/zodHttp";
|
||||
import { MAGIC_LINK_TTL_MS } from "../../../../../lib/privacyRetention";
|
||||
|
||||
const MAGIC_LINK_TTL_MS = 60 * 60 * 1000;
|
||||
const EMAIL_MIN_INTERVAL_MS = 60 * 1000;
|
||||
const IP_MIN_INTERVAL_MS = 20 * 1000;
|
||||
const SCOPE = "auth.magicLink.request";
|
||||
@@ -106,7 +106,7 @@ export const POST = apiRoute(SCOPE, async (request: NextRequest, _ctx, { request
|
||||
try {
|
||||
await sendMagicLinkEmail(email, verifyUrl);
|
||||
} catch (err) {
|
||||
logRouteError(SCOPE, requestId, err, { phase: "sendMagicLinkEmail", email });
|
||||
logRouteError(SCOPE, requestId, err, { phase: "sendMagicLinkEmail" });
|
||||
await prisma.magicLinkToken.deleteMany({ where: { email } });
|
||||
return errorJson("mail_failed", "Could not send email", 502);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { apiRoute } from "../../../../lib/server/apiRoute";
|
||||
import { prisma } from "../../../../lib/server/db";
|
||||
import { getOpsPruneToken, isDatabaseConfigured } from "../../../../lib/server/env";
|
||||
import { pruneExpiredRecords } from "../../../../lib/server/pruneExpiredRecords";
|
||||
import { dbUnavailable, notFound, unauthorized } from "../../../../lib/server/responses";
|
||||
import { retryPendingWorkshopInquiryMail } from "../../../../lib/server/workshopSignup";
|
||||
|
||||
export const POST = apiRoute("ops.prune", async (request: NextRequest) => {
|
||||
const token = getOpsPruneToken();
|
||||
if (!token) return notFound();
|
||||
|
||||
const header = request.headers.get("authorization") ?? "";
|
||||
if (header !== `Bearer ${token}`) return unauthorized();
|
||||
if (!isDatabaseConfigured()) return dbUnavailable();
|
||||
|
||||
const retried = await retryPendingWorkshopInquiryMail();
|
||||
const pruned = await pruneExpiredRecords(prisma);
|
||||
|
||||
return NextResponse.json({ ok: true, retried, ...pruned });
|
||||
});
|
||||
@@ -234,7 +234,6 @@ export const POST = apiRoute(
|
||||
} catch (err) {
|
||||
logRouteError("rules.publish", requestId, err, {
|
||||
phase: "sendRuleStakeholderInviteEmail",
|
||||
email: inv.email,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ import { getPublicOrigin } from "../../../../../lib/server/publicOrigin";
|
||||
import { readLimitedJson } from "../../../../../lib/server/validation/requestBody";
|
||||
import { emailChangeRequestBodySchema } from "../../../../../lib/server/validation/userEmailChangeSchemas";
|
||||
import { jsonFromZodError } from "../../../../../lib/server/validation/zodHttp";
|
||||
import { EMAIL_CHANGE_TTL_MS } from "../../../../../lib/privacyRetention";
|
||||
|
||||
const EMAIL_CHANGE_TTL_MS = 60 * 60 * 1000;
|
||||
const EMAIL_MIN_INTERVAL_MS = 60 * 1000;
|
||||
const IP_MIN_INTERVAL_MS = 20 * 1000;
|
||||
const SCOPE = "user.emailChange.request";
|
||||
@@ -122,10 +122,7 @@ export const POST = apiRoute(SCOPE, async (request: NextRequest, _ctx, { request
|
||||
try {
|
||||
await sendEmailChangeEmail(newEmail, verifyUrl);
|
||||
} catch (err) {
|
||||
logRouteError(SCOPE, requestId, err, {
|
||||
phase: "sendEmailChangeEmail",
|
||||
newEmail,
|
||||
});
|
||||
logRouteError(SCOPE, requestId, err, { phase: "sendEmailChangeEmail" });
|
||||
await prisma.emailChangeToken.deleteMany({ where: { userId: user.id } });
|
||||
return errorJson("mail_failed", "Could not send email", 502);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
import { readLimitedJson } from "../../../lib/server/validation/requestBody";
|
||||
import { webVitalIngestSchema } from "../../../lib/server/validation/webVitalsSchema";
|
||||
import { jsonFromZodError } from "../../../lib/server/validation/zodHttp";
|
||||
import { pathOnlyUrl } from "../../../lib/server/pathOnlyUrl";
|
||||
|
||||
function normalizeTimestamp(raw: string | number): string {
|
||||
if (typeof raw === "number" && Number.isFinite(raw)) {
|
||||
@@ -47,7 +48,7 @@ export const POST = apiRoute("webVitals.post", async (request: NextRequest) => {
|
||||
value: body.data.value,
|
||||
rating: body.data.rating,
|
||||
},
|
||||
url: body.url,
|
||||
url: pathOnlyUrl(body.url),
|
||||
userAgent: body.userAgent,
|
||||
timestamp: normalizeTimestamp(body.timestamp),
|
||||
receivedAt: new Date().toISOString(),
|
||||
|
||||
Reference in new issue
Block a user