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
@@ -98,7 +98,7 @@ Plain-English entities (names can evolve):
|
||||
|
||||
**RuleTemplate — recommendation matrix (after v1 list):** Product may author templates in **spreadsheets** (e.g. one row per governance pattern, columns for **matching dimensions** such as group size, organization type, location, maturity, plus long-form fields for create-flow prefill). That implies: **normalized schema or versioned JSON** for dimensions × template fit (✓/✗, weights, or scores), an **import path** (export `.xlsx` / Sheets → validate → DB or build-time artifact), and **`GET /api/templates` (or a sibling route)** that accepts **user- or wizard-selected facets** and returns a **ranked or filtered** set. **Out of scope for first ship** of Tickets 7–8 (seed + display list); tracked as **Ticket 16** in [docs/backend-linear-tickets.md](backend-linear-tickets.md) and Linear **[CR-88](https://linear.app/community-rule/issue/CR-88/backend-template-recommendation-matrix-facet-data-seed-and-apis-no)** (**Done** — committed JSON + seed; no runtime `.xlsx`). Prefer **batch import** over live Google Sheets API in production unless ops explicitly wants sync.
|
||||
|
||||
**Session lifecycle (shipped, [CR-85](https://linear.app/community-rule/issue/CR-85/backend-custom-session-lifecycle-cleanup-invalidation-policy)):** **Multi-device** policy — a new sign-in does **not** invalidate the user's other valid sessions. **Exception — verified email change ([CR-103](https://linear.app/community-rule/issue/CR-103/backend-change-account-email-verify-new-address-conflict-session)):** after `User.email` updates via `/api/user/email-change/verify`, all other sessions for that user are revoked; the current browser keeps its session when it opened the verify link with a valid cookie, otherwise a **new** session is issued on the device that completed verify. **Cleanup is lazy and cron-free:** every `createSessionForUser` prunes that user's expired rows (uses `@@index([userId])`); ~5% of sign-ins also run a global sweep so rows from users who never return remain bounded over months. Cleanup failures are logged but never fail the sign-in. **Rotation** on other privilege-sensitive actions is deferred to v1.1. See the ADR comment block at the top of [`lib/server/session.ts`](../../lib/server/session.ts). Revisit a small auth library (e.g. Auth.js, Lucia) only if maintaining custom code becomes costly.
|
||||
**Session lifecycle (shipped, [CR-85](https://linear.app/community-rule/issue/CR-85/backend-custom-session-lifecycle-cleanup-invalidation-policy)):** **Multi-device** policy — a new sign-in does **not** invalidate the user's other valid sessions. **Exception — verified email change ([CR-103](https://linear.app/community-rule/issue/CR-103/backend-change-account-email-verify-new-address-conflict-session)):** after `User.email` updates via `/api/user/email-change/verify`, all other sessions for that user are revoked; the current browser keeps its session when it opened the verify link with a valid cookie, otherwise a **new** session is issued on the device that completed verify. **Cleanup is lazy plus a daily job:** every `createSessionForUser` prunes that user's expired rows (uses `@@index([userId])`); ~5% of sign-ins also run a global sweep so rows from users who never return remain bounded over months. Cloudron also runs [`scripts/prune-sessions.ts`](../../scripts/prune-sessions.ts) daily. Cleanup failures on sign-in are logged but never fail the sign-in. **Rotation** on other privilege-sensitive actions is deferred to v1.1. See the ADR comment block at the top of [`lib/server/session.ts`](../../lib/server/session.ts). Revisit a small auth library (e.g. Auth.js, Lucia) only if maintaining custom code becomes costly.
|
||||
|
||||
**RuleDraft future (not v1):** versioning, multiple drafts per user, easier corruption recovery—only if product needs them.
|
||||
|
||||
@@ -110,7 +110,7 @@ Align JSON shapes with `app/(app)/create/types.ts` as it matures.
|
||||
|
||||
- **Decision:** **Custom** database-backed sessions + **email magic link**; cookies are **httpOnly**; session and magic-link tokens are hashed at rest.
|
||||
- **Rate limiting (magic-link request):** **In-memory** is acceptable for a **single Node process**. It does **not** coordinate across instances—**add a shared limiter (e.g. Redis)** before horizontal scaling or serious abuse exposure.
|
||||
- **Lifecycle policy (shipped, [CR-85](https://linear.app/community-rule/issue/CR-85/backend-custom-session-lifecycle-cleanup-invalidation-policy)):** multi-device (sign-in does not revoke other valid sessions); **email change ([CR-103](https://linear.app/community-rule/issue/CR-103/backend-change-account-email-verify-new-address-conflict-session))** revokes other sessions as documented in [`lib/server/session.ts`](../../lib/server/session.ts) §4; lazy expired-row cleanup on every sign-in (per-user prune + ~5% global sweep) — no cron required. Token rotation deferred to v1.1. Canonical comment block lives at the top of [`lib/server/session.ts`](../../lib/server/session.ts).
|
||||
- **Lifecycle policy (shipped, [CR-85](https://linear.app/community-rule/issue/CR-85/backend-custom-session-lifecycle-cleanup-invalidation-policy)):** multi-device (sign-in does not revoke other valid sessions); **email change ([CR-103](https://linear.app/community-rule/issue/CR-103/backend-change-account-email-verify-new-address-conflict-session))** revokes other sessions as documented in [`lib/server/session.ts`](../../lib/server/session.ts) §4; lazy expired-row cleanup on every sign-in (per-user prune + ~5% global sweep), plus a daily Cloudron scheduler job. Token rotation deferred to v1.1. Canonical comment block lives at the top of [`lib/server/session.ts`](../../lib/server/session.ts).
|
||||
- Do **not** treat “switch to NextAuth/Lucia” as required for v1; document the custom lifecycle above instead.
|
||||
|
||||
---
|
||||
|
||||
@@ -98,9 +98,9 @@ per-app in the manifest and provisioned at install time.
|
||||
[`CloudronManifest.json`](../../CloudronManifest.json) (`memoryLimit:
|
||||
805306368`). The legacy LAMP app ran at 512 MiB; raise further only if
|
||||
Next.js standalone OOMs under load.
|
||||
- Backups: Cloudron's automatic backups are already on for the host
|
||||
(legacy app shows weekly snapshots ~451 MB each). Same default
|
||||
applies to new apps.
|
||||
- Backups: Cloudron's automatic backups are already on for the host.
|
||||
Set the backup site retention to **`30 daily`** so backups match the
|
||||
privacy policy (see [`ops-runbook.md`](ops-runbook.md) §9.3).
|
||||
- TLS for Cloudron app hostnames: handled by Cloudron (Let's Encrypt).
|
||||
- **Mail DNS (SPF/DKIM):** *not* automatic for this domain. Cloudron's
|
||||
DNS provider for `communityrule.info` is Namecheap, but outbound mail
|
||||
|
||||
@@ -246,6 +246,8 @@ persist across image updates unless changed:
|
||||
| `SMTP_FROM` | Visible From on sign-in emails (e.g. `Community Rule <hello@communityrule.info>`). |
|
||||
| `NEXT_PUBLIC_ENABLE_BACKEND_SYNC` | `true` in staging/production — Postgres draft persistence. |
|
||||
| `UPLOAD_ROOT` | `/app/data/uploads` on Cloudron — required for file uploads. |
|
||||
| `OPS_PRUNE_TOKEN` | Bearer token for `POST /api/ops/prune`. Unset hides the route. Optional; the daily scheduler runs the prune inside the container without it. |
|
||||
| `WORKSHOP_INQUIRY_PURGE_TOKEN` | Bearer token for `POST /api/workshop-inquiries/purge`. Unset hides that route. |
|
||||
|
||||
Full detail: [`ops-backend-deploy.md` §3](ops-backend-deploy.md#3-environment-variables).
|
||||
|
||||
@@ -279,8 +281,70 @@ That is expected. Recipients still authenticate the visible `From:` (`staging.ap
|
||||
|
||||
`SMTP_FROM` should stay the Cloudron mailbox (`staging.app@communityrule.info` on staging, `hello@communityrule.info` on the apex app). The app falls back to `CLOUDRON_MAIL_FROM` if `SMTP_FROM` is unset.
|
||||
|
||||
## 9. Related docs
|
||||
## 9. Retention (logs, backups, unused links)
|
||||
|
||||
Periods the privacy policy states. Source of truth:
|
||||
[`docs/privacy-policy-facts.md`](../privacy-policy-facts.md) and
|
||||
[`lib/privacyRetention.ts`](../../lib/privacyRetention.ts).
|
||||
|
||||
### 9.1 Unused links and sessions
|
||||
|
||||
[`CloudronManifest.json`](../../CloudronManifest.json) registers a
|
||||
**scheduler** task `prune-expired` at **07:20 UTC** daily. It runs
|
||||
`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.
|
||||
|
||||
Manual runs:
|
||||
|
||||
```bash
|
||||
# inside the container (no token)
|
||||
cloudron exec --app staging.communityrule.info -- \
|
||||
node /app/prune-expired.bundle.cjs
|
||||
|
||||
# from outside, if OPS_PRUNE_TOKEN is set
|
||||
curl -sS -X POST \
|
||||
-H "Authorization: Bearer $OPS_PRUNE_TOKEN" \
|
||||
https://staging.communityrule.info/api/ops/prune
|
||||
```
|
||||
|
||||
Local:
|
||||
|
||||
```bash
|
||||
node --env-file=.env --import tsx scripts/prune-sessions.ts
|
||||
```
|
||||
|
||||
If the scheduler addon is missing after an image update, add the same
|
||||
command under the app **Cron** tab (`20 7 * * *`, UTC).
|
||||
|
||||
### 9.2 Logs
|
||||
|
||||
App logs (stdout) and Cloudron request logs are deleted after **14
|
||||
days**. That is the platform default and the shortest period Cloudron
|
||||
allows.
|
||||
|
||||
Page timing logs (`POST /api/web-vitals` in `external` mode) record
|
||||
origin + path only. Query strings are stripped before the line is
|
||||
written, so invitation and login tokens never land in app logs.
|
||||
|
||||
Cloudron's reverse-proxy request logs still include the query string.
|
||||
They follow the same 14-day window. Do not export those logs off the
|
||||
host for longer than 14 days.
|
||||
|
||||
Sign-in mail failures log a request id, not the email address.
|
||||
|
||||
### 9.3 Backups
|
||||
|
||||
Set the Cloudron backup site to **`30 daily`** (*Backups* → *Schedule &
|
||||
Retention*). Confirm this on staging and production. Cloudron also keeps
|
||||
a pre-update snapshot for up to three weeks.
|
||||
|
||||
## 10. Related docs
|
||||
|
||||
- [`../privacy-policy-facts.md`](../privacy-policy-facts.md) — periods
|
||||
and hosting facts for the privacy policy.
|
||||
- [`ops-backend-deploy.md`](ops-backend-deploy.md) — first install, cutover
|
||||
plan, legacy rules archive, build/push deep dive.
|
||||
- [`backend-roadmap.md`](backend-roadmap.md) — migrations policy (§8),
|
||||
|
||||
Reference in new issue
Block a user