Repository navigation
feat(admin): block existing accounts when adding a blacklisted domain - #8596
Conversation
Saving the blacklisted domains list left existing accounts untouched until an admin remembered to open the Backfills page and click "Block next 50 000" one or more times. Run the existing backfill batch from the save mutation for domains that were newly added to the list. Domains that were already listed are skipped, since they were either backfilled when they were added or are handled by the manual backfill button. The list write is authoritative and already enforced by auth checks, so a backfill failure is reported to Sentry without failing the save. The mutation now returns the number of accounts blocked, whether more remain, and whether the automatic run failed, and the edit tab surfaces that result. The backfill batch moves to lib/abuse so both the route and the router can use it without importing a Next.js route module.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryThe incremental hardening commit resolves all prior findings: admin accounts are excluded from both the domain backfill and the unblocked count, an unreadable previous config now fails safe instead of triggering a full-list backfill, and domain lists are bound as two array parameters so large imported lists no longer approach PostgreSQL's bind-parameter limit. Assumptions: Files Reviewed (6 files)
Previous Review Summary (commit 5cdd942)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 5cdd942)Status: 3 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (7 files)
Reviewed by deepseek-flash-latest · Input: 90.4K · Output: 10K · Cached: 481.9K Review guidance: REVIEW.md from base branch |
Skip admin accounts in the domain backfill and its remaining count, so saving a domain cannot lock out an admin who then cannot reach the admin tools needed to unblock the account. Treat a failed previous-config read as unknown instead of an empty list, so a transient Redis error cannot turn a one-domain save into a backfill of every listed domain. Bind the domain lists as array parameters instead of one bind per entry, so a bulk import does not exceed PostgreSQL's bind-parameter limit.
Summary
Adding a domain to the blacklisted domains list now blocks existing accounts on that domain automatically. Previously the list only affected new sign-ups and per-request checks, and an admin had to open the Backfills page and click "Block next 50 000" one or more times to mark existing accounts as blocked.
admin.blacklistDomains.setdiffs the submitted list against the list the admin started from and runs the existing backfill batch for only the newly added domains.{ blocked, remaining, failed }, and the edit tab reports the result, including a pointer to/admin/backfillswhen more work remains.Implementation notes
apps/web/src/lib/abuse/block-blacklisted-domains.tsso the tRPC router can call them without importing a route file. The route now imports the shared module and keeps the sameGET/POSTbehaviour.email_domainwas filled in later.blockUserdoes, and does not match list entries that are subdomains of the stored registrableemail_domain.= ANY/LIKE ANY), so an imported list of tens of thousands of entries no longer risks PostgreSQL's bind-parameter limit.Verification
NODE_ENV=test npx jest src/lib/abuse/block-blacklisted-domains.test.ts src/routers/admin/blacklist-domains-router.test.ts— 2 suites, 36 tests passed (includes new tests for auto-blocking, skipping already-listed domains, and keeping the save when the backfill fails).pnpm --filter web run typecheck— passed (tsgoexit 0).oxlintandoxfmton the changed files — clean.