Delete unused login links each day, keep those URLs out of logs, and write the privacy-policy numbers #103
No files matched your search
@@ -294,8 +294,9 @@ Periods the privacy policy states. Source of truth:
|
||||
`node /app/prune-expired.bundle.cjs` (the production bundle of
|
||||
[`scripts/prune-sessions.ts`](../../scripts/prune-sessions.ts)) and
|
||||
deletes expired sessions, unused login / save-progress / email-change
|
||||
tokens and the drafts they carry, unused invitation tokens, and workshop
|
||||
inquiries older than 12 months.
|
||||
tokens and the drafts they carry, and workshop inquiries older than 12
|
||||
months. It leaves invitation token hashes in place: an expired link cannot
|
||||
be used to join, and that hash is how the person requests a new link.
|
||||
|
||||
Manual runs:
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ read this text. Do not switch the route on from this file.
|
||||
| --- | --- | --- |
|
||||
| Login and save-progress links | Work for **60 minutes**. Unused rows, and any draft they carry, are deleted once expired. A daily job runs the delete, so they are gone **within 24 hours** of expiry. | `MAGIC_LINK_TTL_MS`, Cloudron scheduler `prune-expired` |
|
||||
| Email-change links | Same as login links: **60 minutes**, then gone within **24 hours**. | `EMAIL_CHANGE_TTL_MS` |
|
||||
| Unused invitation tokens | The unused token is cleared once the invite expires. Gone within **24 hours** of expiry. The invitation row stays so it can be sent again. | Daily prune |
|
||||
| Unused invitation tokens | The link stops granting access when it expires (**60 minutes**). The hash stays on the invitation so the person can request a new link from the expired page, and so the organizer can send it again. The daily job does not delete it. | `STAKEHOLDER_INVITE_TTL_MS` |
|
||||
| Workshop inquiries that do not lead to a workshop | **12 months**, then deleted. | `WORKSHOP_INQUIRY_RETENTION_MS` |
|
||||
| Ask an organizer messages | **Not stored** on CommunityRule. They are emailed to MEDLab. MEDLab deletes mailbox copies after **12 months**. | Mail only |
|
||||
| Unused accounts | **Kept until the person deletes the account.** There is no unused-account timer at launch. | — |
|
||||
|
||||
@@ -16,15 +16,6 @@ export interface PruneStore {
|
||||
where: { expiresAt: { lt: Date } };
|
||||
}) => Promise<{ count: number }>;
|
||||
};
|
||||
ruleStakeholder: {
|
||||
updateMany: (args: {
|
||||
where: {
|
||||
inviteTokenHash: { not: null };
|
||||
inviteExpiresAt: { lt: Date };
|
||||
};
|
||||
data: { inviteTokenHash: null; inviteExpiresAt: null };
|
||||
}) => Promise<{ count: number }>;
|
||||
};
|
||||
workshopInquiry: {
|
||||
deleteMany: (args: {
|
||||
where: { createdAt: { lt: Date } };
|
||||
@@ -36,7 +27,6 @@ export interface PruneExpiredResult {
|
||||
sessions: number;
|
||||
magicLinkTokens: number;
|
||||
emailChangeTokens: number;
|
||||
unusedInviteTokens: number;
|
||||
workshopInquiries: number;
|
||||
}
|
||||
|
||||
@@ -53,8 +43,12 @@ export async function deleteExpiredWorkshopInquiries(
|
||||
|
||||
/**
|
||||
* Delete expired sessions, login/save-progress tokens (and the draft they
|
||||
* carry), email-change tokens, unused invitation tokens, and old workshop
|
||||
* inquiries. Does not delete stakeholder rows or accounts.
|
||||
* carry), email-change tokens, and old workshop inquiries.
|
||||
*
|
||||
* Does not delete stakeholder rows, accounts, or invitation token hashes.
|
||||
* Verify already rejects an invite once `inviteExpiresAt` has passed. The
|
||||
* hash is how `/invite/expired` finds that row to send a new link, and a
|
||||
* null hash is treated as an accepted invite.
|
||||
*/
|
||||
export async function pruneExpiredRecords(
|
||||
db: PruneStore,
|
||||
@@ -69,23 +63,12 @@ export async function pruneExpiredRecords(
|
||||
const emailChangeTokens = await db.emailChangeToken.deleteMany({
|
||||
where: { expiresAt: { lt: now } },
|
||||
});
|
||||
const unusedInviteTokens = await db.ruleStakeholder.updateMany({
|
||||
where: {
|
||||
inviteTokenHash: { not: null },
|
||||
inviteExpiresAt: { lt: now },
|
||||
},
|
||||
data: {
|
||||
inviteTokenHash: null,
|
||||
inviteExpiresAt: null,
|
||||
},
|
||||
});
|
||||
const workshopInquiries = await deleteExpiredWorkshopInquiries(db, now);
|
||||
|
||||
return {
|
||||
sessions: sessions.count,
|
||||
magicLinkTokens: magicLinkTokens.count,
|
||||
emailChangeTokens: emailChangeTokens.count,
|
||||
unusedInviteTokens: unusedInviteTokens.count,
|
||||
workshopInquiries,
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Prune expired sessions, unused login/save-progress/email-change tokens
|
||||
* (and any draft they carry), unused invitation tokens, and old workshop
|
||||
* inquiries.
|
||||
* (and any draft they carry), and old workshop inquiries. Invitation token
|
||||
* hashes are left in place so an expired link can still request a new one.
|
||||
*
|
||||
* Usage (from repo root):
|
||||
* node --env-file=.env --import tsx scripts/prune-sessions.ts # global sweep
|
||||
|
||||
@@ -44,7 +44,6 @@ beforeEach(() => {
|
||||
sessions: 1,
|
||||
magicLinkTokens: 2,
|
||||
emailChangeTokens: 0,
|
||||
unusedInviteTokens: 3,
|
||||
workshopInquiries: 4,
|
||||
});
|
||||
retryPendingWorkshopInquiryMailMock.mockResolvedValue(1);
|
||||
@@ -79,7 +78,6 @@ describe("POST /api/ops/prune", () => {
|
||||
sessions: 1,
|
||||
magicLinkTokens: 2,
|
||||
emailChangeTokens: 0,
|
||||
unusedInviteTokens: 3,
|
||||
workshopInquiries: 4,
|
||||
});
|
||||
expect(pruneExpiredRecordsMock).toHaveBeenCalledWith(
|
||||
|
||||
@@ -6,7 +6,6 @@ function store(counts: {
|
||||
sessions?: number;
|
||||
magicLinkTokens?: number;
|
||||
emailChangeTokens?: number;
|
||||
unusedInviteTokens?: number;
|
||||
workshopInquiries?: number;
|
||||
}) {
|
||||
const sessionDeleteMany = vi.fn().mockResolvedValue({
|
||||
@@ -18,9 +17,7 @@ function store(counts: {
|
||||
const emailChangeDeleteMany = vi.fn().mockResolvedValue({
|
||||
count: counts.emailChangeTokens ?? 0,
|
||||
});
|
||||
const inviteUpdateMany = vi.fn().mockResolvedValue({
|
||||
count: counts.unusedInviteTokens ?? 0,
|
||||
});
|
||||
const inviteUpdateMany = vi.fn().mockResolvedValue({ count: 0 });
|
||||
const workshopDeleteMany = vi.fn().mockResolvedValue({
|
||||
count: counts.workshopInquiries ?? 0,
|
||||
});
|
||||
@@ -41,13 +38,12 @@ function store(counts: {
|
||||
}
|
||||
|
||||
describe("pruneExpiredRecords", () => {
|
||||
it("deletes expired tokens and sessions, and clears unused invite hashes", async () => {
|
||||
it("deletes expired tokens and sessions without clearing invite hashes", async () => {
|
||||
const now = new Date("2026-11-10T12:00:00.000Z");
|
||||
const mocks = store({
|
||||
sessions: 2,
|
||||
magicLinkTokens: 3,
|
||||
emailChangeTokens: 1,
|
||||
unusedInviteTokens: 4,
|
||||
workshopInquiries: 5,
|
||||
});
|
||||
|
||||
@@ -57,7 +53,6 @@ describe("pruneExpiredRecords", () => {
|
||||
sessions: 2,
|
||||
magicLinkTokens: 3,
|
||||
emailChangeTokens: 1,
|
||||
unusedInviteTokens: 4,
|
||||
workshopInquiries: 5,
|
||||
});
|
||||
|
||||
@@ -70,16 +65,7 @@ describe("pruneExpiredRecords", () => {
|
||||
expect(mocks.emailChangeDeleteMany).toHaveBeenCalledWith({
|
||||
where: { expiresAt: { lt: now } },
|
||||
});
|
||||
expect(mocks.inviteUpdateMany).toHaveBeenCalledWith({
|
||||
where: {
|
||||
inviteTokenHash: { not: null },
|
||||
inviteExpiresAt: { lt: now },
|
||||
},
|
||||
data: {
|
||||
inviteTokenHash: null,
|
||||
inviteExpiresAt: null,
|
||||
},
|
||||
});
|
||||
expect(mocks.inviteUpdateMany).not.toHaveBeenCalled();
|
||||
|
||||
const workshopArg = mocks.workshopDeleteMany.mock.calls[0]?.[0] as {
|
||||
where: { createdAt: { lt: Date } };
|
||||
@@ -96,7 +82,6 @@ describe("pruneExpiredRecords", () => {
|
||||
mocks.sessionDeleteMany.mock.calls,
|
||||
mocks.magicLinkDeleteMany.mock.calls,
|
||||
mocks.emailChangeDeleteMany.mock.calls,
|
||||
mocks.inviteUpdateMany.mock.calls,
|
||||
]);
|
||||
expect(payload).not.toMatch(/tokenHash|email/);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user