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
@@ -34,6 +34,7 @@ vi.mock("../../lib/server/rateLimit", () => ({
|
||||
rateLimitKey: () => ({ ok: true }),
|
||||
}));
|
||||
|
||||
import { logger } from "../../lib/logger";
|
||||
import { POST } from "../../app/api/auth/magic-link/request/route";
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -185,4 +186,29 @@ describe("POST /api/auth/magic-link/request", () => {
|
||||
expect(body.error.code).toBe("mail_failed");
|
||||
expect(deleteManyMock).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("logs a request id rather than the email when mail fails", async () => {
|
||||
const errorSpy = vi.spyOn(logger, "error").mockImplementation(() => {});
|
||||
try {
|
||||
sendMagicLinkEmailMock.mockRejectedValueOnce(new Error("smtp down"));
|
||||
const res = await POST(
|
||||
new NextRequest("https://x.test/api/auth/magic-link/request", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ email: "member@example.com" }),
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"x-request-id": "req-no-email",
|
||||
},
|
||||
}),
|
||||
undefined,
|
||||
);
|
||||
expect(res.status).toBe(502);
|
||||
expect(errorSpy).toHaveBeenCalled();
|
||||
const payload = errorSpy.mock.calls[0]?.[0] as Record<string, unknown>;
|
||||
expect(payload.requestId).toBe("req-no-email");
|
||||
expect(JSON.stringify(payload)).not.toContain("member@example.com");
|
||||
} finally {
|
||||
errorSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user