feat(invitations): hardening — configurable expiry, 2^40 short codes, sweep (task 1.5, INV-04/06) #60

Merged
amiryahaya merged 1 commit from feat/1.5-invitation-hardening into main 2026-11-05 15:10:40 +01:00
Owner

Closes #20 (task 1.5)

INV-04 — configurable expiry, single source

  • InvitationsOptions.ExpiryDays (default 7) bound from Invitations:ExpiryDays — replaces both hardcoded AddDays(7) sites (CreateInvitation, CreateAdminInvitation); config change takes effect without code change
  • expired invites read as 410 Gone (was 404) on the public token/code preview endpoints — clients can distinguish 'lapsed' from 'unknown'; lazy flip at acceptance read retained

INV-06 — short-code entropy + brute-force defense

  • suffix 4 → 8 chars from the 32-symbol alphabet → 32^8 = 2^40 guessing space (tenant prefix is guessable, doesn't count); structural assertion in tests; 6-char fallback loop removed
  • code-lookup endpoint gets its own invite-code-lookup rate-limit partition (20/min prod, 100/min in Testing so the brute-force test proves it: 1000 wrong guesses → 429)

Sweep job (P1)

  • InvitationExpirySweepService: hourly BackgroundService flipping stale Pending → Expired (startup deferred 5 min); public SweepOnceAsync; materialize-then-filter per house SQLite-compat style

TDD evidence

7 tests written first — RED ×6 confirmed, then implemented to green.
Suite: 774 total / 0 failed / 39 skipped (Release). Coverage gate: 81.77% ≥ 80%

Closes #20 (task 1.5) ## INV-04 — configurable expiry, single source - `InvitationsOptions.ExpiryDays` (default 7) bound from `Invitations:ExpiryDays` — replaces both hardcoded `AddDays(7)` sites (CreateInvitation, CreateAdminInvitation); config change takes effect without code change - expired invites read as **410 Gone** (was 404) on the public token/code preview endpoints — clients can distinguish 'lapsed' from 'unknown'; lazy flip at acceptance read retained ## INV-06 — short-code entropy + brute-force defense - suffix **4 → 8 chars** from the 32-symbol alphabet → **32^8 = 2^40 guessing space** (tenant prefix is guessable, doesn't count); structural assertion in tests; 6-char fallback loop removed - code-lookup endpoint gets its own **`invite-code-lookup` rate-limit partition** (20/min prod, 100/min in Testing so the brute-force test proves it: **1000 wrong guesses → 429**) ## Sweep job (P1) - `InvitationExpirySweepService`: hourly BackgroundService flipping stale Pending → Expired (startup deferred 5 min); public `SweepOnceAsync`; materialize-then-filter per house SQLite-compat style ## TDD evidence 7 tests written first — RED ×6 confirmed, then implemented to green. **Suite: 774 total / 0 failed / 39 skipped (Release). Coverage gate: 81.77% ≥ 80%**
feat(invitations): hardening — configurable expiry, 2^40 short codes, sweep job (task 1.5, INV-04/06)
Some checks failed
API CI / build-and-test (pull_request) Failing after 3m16s
933dc4a1f1
INV-04 — expiry configurable (Invitations:ExpiryDays, default 7):
- InvitationsOptions bound from config; replaces BOTH hardcoded
  AddDays(7) sites (CreateInvitation + CreateAdminInvitation) —
  config changes take effect without code changes
- expired invites now read back as 410 Gone (was 404) on the public
  token/code preview endpoints so clients can say 'lapsed' vs 'unknown';
  lazy flip at acceptance read retained

INV-06 — short codes ≥ 2^40 guessing space:
- suffix 4 → 8 chars from the 32-symbol alphabet (32^8 = 2^40; the
  tenant prefix is guessable and doesn't count); structural assertion
  in tests; 6-char fallback loop removed (space no longer needs it)
- code-lookup endpoint gets its own tighter rate-limit partition
  ('invite-code-lookup', 20/min prod — same as auth; 100/min in tests
  so the brute-force test can prove it: 1000 wrong guesses → 429)

Sweep job (P1):
- InvitationExpirySweepService: hourly BackgroundService (startup
  deferred 5 min) flipping stale Pending → Expired; public
  SweepOnceAsync for tests; complements the lazy flip for rows nobody
  reads; materialize-then-filter per house SQLite-compat style

TDD: 7 new tests written first (RED ×6 confirmed), then implemented.
Suite 774 total / 0 failed / 39 skipped (Release); coverage gate
81.77% >= 80% floor.
Sign in to join this conversation.
No description provided.