diff --git a/CHANGELOG.md b/CHANGELOG.md index 7569e39..230ad82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --- +## [0.6.0] - 2026-10-19 + +### Added +- **Discord bot auto-roles and event log**: new members get the Members role (after accepting the rules) and bots get the Bots role; joins, leaves, member and role changes, bans, deleted, edited and bulk-deleted messages, channels, threads, roles, invites and voice activity are logged to `EVENT_LOG_CHANNEL_ID` +- **Blocklist** (Admin → Blocklist) for email addresses, email domains and sending domains. Blocked addresses can't sign up, become an account email or a backup email, and blocked sending domains (and their subdomains) can't be added by any team +- **Ban evasion detection**: banning a user now opens a dialog that blocks their email addresses (including `+` and Gmail dot aliases), optionally blocks their sending domains, and offers to ban related accounts. The users list flags **Ban evasion** (same mailbox as a banned user) and **Possible evasion** (same name), and each user page lists related accounts. Unbanning removes what the ban blocked. Users banned before this release have their addresses blocked automatically +- Admins get a Discord alert when a blocked sign-up is refused, and when a domain on a shared namespace is added + +### Security +- Sending domains on dynamic-DNS, tunnel and free-hosting services (DynDNS, No-IP, DuckDNS, ngrok, `github.io`, `vercel.app` and similar) can no longer be added on ByteSend Cloud, and email from such hostnames is held for review +- Spam protection recognises phishing phrases in German, French, Spanish, Italian and Dutch, and more impersonated brands (eBay, Kleinanzeigen, European banks and couriers) + +### Fixed +- Signing in by email with a banned or blocked address now shows why, instead of claiming a sign-in link was sent + +--- + ## [0.5.0] - 2026-10-19 ### Added @@ -931,7 +948,8 @@ Initial public beta release of ByteSend: an all-in-one email infrastructure plat --- -[Unreleased]: https://github.com/ByteSendApp/ByteSend/compare/v0.5.0...HEAD +[Unreleased]: https://github.com/ByteSendApp/ByteSend/compare/v0.6.0...HEAD +[0.6.0]: https://github.com/ByteSendApp/ByteSend/compare/v0.5.0...v0.6.0 [0.5.0]: https://github.com/ByteSendApp/ByteSend/compare/v0.4.4...v0.5.0 [0.4.4]: https://github.com/ByteSendApp/ByteSend/compare/v0.4.3...v0.4.4 [0.4.3]: https://github.com/ByteSendApp/ByteSend/compare/v0.4.2...v0.4.3 diff --git a/apps/web/prisma/migrations/20261020000000_add_blocklist/migration.sql b/apps/web/prisma/migrations/20261020000000_add_blocklist/migration.sql new file mode 100644 index 0000000..39e6521 --- /dev/null +++ b/apps/web/prisma/migrations/20261020000000_add_blocklist/migration.sql @@ -0,0 +1,45 @@ +-- CreateEnum +CREATE TYPE "BlocklistType" AS ENUM ('EMAIL', 'EMAIL_DOMAIN', 'SENDING_DOMAIN'); + +-- CreateTable +CREATE TABLE "BlocklistEntry" ( + "id" TEXT NOT NULL, + "type" "BlocklistType" NOT NULL, + "value" TEXT NOT NULL, + "reason" TEXT, + "sourceUserId" INTEGER, + "createdById" INTEGER, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "BlocklistEntry_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "BlocklistEntry_type_value_key" ON "BlocklistEntry"("type", "value"); + +-- CreateIndex +CREATE INDEX "BlocklistEntry_sourceUserId_idx" ON "BlocklistEntry"("sourceUserId"); + +-- Backfill: block the canonical email of every user banned before the blocklist existed. +-- Mirrors canonicalEmail() in src/lib/canonical-email.ts. +WITH banned AS ( + SELECT "id", lower(trim("email")) AS email + FROM "User" + WHERE "isBanned" = true AND "email" IS NOT NULL AND position('@' in "email") > 1 +), +parts AS ( + SELECT + "id", + split_part(split_part(email, '@', 1), '+', 1) AS local, + CASE WHEN split_part(email, '@', 2) = 'googlemail.com' THEN 'gmail.com' ELSE split_part(email, '@', 2) END AS domain + FROM banned +) +INSERT INTO "BlocklistEntry" ("id", "type", "value", "reason", "sourceUserId") +SELECT + 'bl' || md5(random()::text || clock_timestamp()::text), + 'EMAIL', + CASE WHEN domain = 'gmail.com' THEN replace(local, '.', '') ELSE local END || '@' || domain, + 'Banned user', + "id" +FROM parts +ON CONFLICT ("type", "value") DO NOTHING; diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma index 7e32c50..41e3904 100644 --- a/apps/web/prisma/schema.prisma +++ b/apps/web/prisma/schema.prisma @@ -742,3 +742,25 @@ model SpamScan { @@index([emailId]) @@index([campaignId]) } + +enum BlocklistType { + EMAIL + EMAIL_DOMAIN + SENDING_DOMAIN +} + +/// Addresses and domains that can't be used to sign up or be added as sending domains. +/// EMAIL values are canonical (see src/lib/canonical-email.ts) so aliases of a blocked address match. +model BlocklistEntry { + id String @id @default(cuid()) + type BlocklistType + value String + reason String? + /// The banned user this entry was created for; unbanning them removes it. + sourceUserId Int? + createdById Int? + createdAt DateTime @default(now()) + + @@unique([type, value]) + @@index([sourceUserId]) +} diff --git a/apps/web/src/app/(dashboard)/admin/_components/admin-nav.tsx b/apps/web/src/app/(dashboard)/admin/_components/admin-nav.tsx index fcc7277..23c9a69 100644 --- a/apps/web/src/app/(dashboard)/admin/_components/admin-nav.tsx +++ b/apps/web/src/app/(dashboard)/admin/_components/admin-nav.tsx @@ -5,6 +5,7 @@ import { usePathname } from "next/navigation"; import type { LucideIcon } from "lucide-react"; import { Activity, + Ban, Building2, CreditCard, Globe, @@ -49,6 +50,7 @@ const NAV_GROUPS: AdminNavGroup[] = [ { href: "/admin/deliverability", label: "Deliverability", icon: ShieldAlert }, { href: "/admin/blacklists", label: "Blacklists", icon: ShieldBan, cloudOnly: true }, { href: "/admin/spam", label: "Spam review", icon: MailWarning }, + { href: "/admin/blocklist", label: "Blocklist", icon: Ban }, ], }, { diff --git a/apps/web/src/app/(dashboard)/admin/blocklist/page.tsx b/apps/web/src/app/(dashboard)/admin/blocklist/page.tsx new file mode 100644 index 0000000..2d32b05 --- /dev/null +++ b/apps/web/src/app/(dashboard)/admin/blocklist/page.tsx @@ -0,0 +1,209 @@ +"use client"; + +import { useState } from "react"; +import Link from "next/link"; +import { formatDistanceToNow } from "date-fns"; +import { Trash2 } from "lucide-react"; +import { Button } from "@bytesend/ui/src/button"; +import { Input } from "@bytesend/ui/src/input"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@bytesend/ui/src/select"; +import { Skeleton } from "@bytesend/ui/src/skeleton"; +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@bytesend/ui/src/table"; +import { toast } from "@bytesend/ui/src/toaster"; +import { api } from "~/trpc/react"; +import { AdminPageHeader } from "../_components/admin-page-header"; +import { Pagination } from "../_components/pagination"; +import { SearchInput } from "../_components/search-input"; +import { StatusPill } from "../_components/status-pill"; + +const PAGE_SIZE = 25; +const ALL = "ALL"; + +type BlocklistType = "EMAIL" | "EMAIL_DOMAIN" | "SENDING_DOMAIN"; + +const TYPE_LABELS: Record = { + EMAIL: { label: "Email", hint: "Blocks this mailbox and its aliases from signing up", placeholder: "someone@gmail.com" }, + EMAIL_DOMAIN: { label: "Email domain", hint: "Blocks sign-ups from any address at this domain", placeholder: "throwaway-mail.com" }, + SENDING_DOMAIN: { label: "Sending domain", hint: "Blocks adding this domain or its subdomains", placeholder: "scam-example.com" }, +}; + +export default function AdminBlocklistPage() { + const utils = api.useUtils(); + const [page, setPage] = useState(1); + const [query, setQuery] = useState(""); + const [filter, setFilter] = useState(ALL); + + const [newType, setNewType] = useState("SENDING_DOMAIN"); + const [newValue, setNewValue] = useState(""); + const [newReason, setNewReason] = useState(""); + + const listQuery = api.admin.listBlocklist.useQuery( + { page, pageSize: PAGE_SIZE, query: query || undefined, type: filter === ALL ? undefined : filter }, + { placeholderData: (prev) => prev }, + ); + + const refresh = () => Promise.all([utils.admin.listBlocklist.invalidate(), utils.admin.listAuditLog.invalidate()]); + + const add = api.admin.addBlocklistEntry.useMutation({ + onSuccess: async (entry) => { + toast.success(`Blocked ${entry.value}`); + setNewValue(""); + setNewReason(""); + await refresh(); + }, + onError: (error) => toast.error("Could not add entry", { description: error.message }), + }); + const remove = api.admin.removeBlocklistEntry.useMutation({ + onSuccess: async (entry) => { + toast.success(`Unblocked ${entry.value}`); + await refresh(); + }, + onError: (error) => toast.error("Could not remove entry", { description: error.message }), + }); + + const entries = listQuery.data?.entries ?? []; + + return ( + <> + + +
{ + event.preventDefault(); + add.mutate({ type: newType, value: newValue, reason: newReason || undefined }); + }} + > + + setNewValue(event.target.value)} + placeholder={TYPE_LABELS[newType].placeholder} + aria-label="Value" + /> + setNewReason(event.target.value)} placeholder="Reason (optional)" aria-label="Reason" /> + +

{TYPE_LABELS[newType].hint}.

+
+ +
+ { + setPage(1); + setQuery(value); + }} + placeholder="Search blocked values" + label="Search blocklist" + className="sm:max-w-md" + /> + +
+ +
+
+ + + + Value + Type + Reason + Added + + + + + {listQuery.isLoading ? ( + Array.from({ length: 6 }, (_, i) => ( + + {Array.from({ length: 5 }, (__, j) => ( + + + + ))} + + )) + ) : entries.length === 0 ? ( + + + Nothing blocked{query || filter !== ALL ? " matches" : " yet"}. + + + ) : ( + entries.map((entry) => ( + + {entry.value} + + + {TYPE_LABELS[entry.type as BlocklistType].label} + + + + {entry.reason ?? "No reason given"} + {entry.sourceUserId ? ( + + From ban of #{entry.sourceUserId} + + ) : null} + + + {formatDistanceToNow(entry.createdAt, { addSuffix: true })} + + + + + + )) + )} + +
+
+
+ + {listQuery.data ? ( + + ) : null} + + ); +} diff --git a/apps/web/src/app/(dashboard)/admin/users/[userId]/ban-user-dialog.tsx b/apps/web/src/app/(dashboard)/admin/users/[userId]/ban-user-dialog.tsx new file mode 100644 index 0000000..e5a8199 --- /dev/null +++ b/apps/web/src/app/(dashboard)/admin/users/[userId]/ban-user-dialog.tsx @@ -0,0 +1,197 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { Button } from "@bytesend/ui/src/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@bytesend/ui/src/dialog"; +import { Skeleton } from "@bytesend/ui/src/skeleton"; +import { Textarea } from "@bytesend/ui/src/textarea"; +import { toast } from "@bytesend/ui/src/toaster"; +import { api } from "~/trpc/react"; + +function CheckRow({ + checked, + onChange, + title, + detail, +}: { + checked: boolean; + onChange: (checked: boolean) => void; + title: React.ReactNode; + detail?: React.ReactNode; +}) { + return ( + + ); +} + +export function BanUserDialog({ + user, + open, + onOpenChange, + onDone, +}: { + user: { id: number; email: string | null; name: string | null }; + open: boolean; + onOpenChange: (open: boolean) => void; + onDone: () => Promise; +}) { + const preview = api.admin.getBanPreview.useQuery({ userId: user.id }, { enabled: open }); + const [reason, setReason] = useState(""); + const [blockMailboxes, setBlockMailboxes] = useState(true); + const [domains, setDomains] = useState>(new Set()); + const [related, setRelated] = useState>(new Set()); + + // Pre-tick strong signals (same mailbox, domains on teams only this user is in); leave weak ones for the admin. + useEffect(() => { + if (!preview.data) return; + setDomains(new Set(preview.data.domains.filter((d) => !d.sharedTeam).map((d) => d.name))); + setRelated(new Set(preview.data.related.filter((r) => r.reason === "same_mailbox").map((r) => r.id))); + }, [preview.data]); + + const ban = api.admin.banUser.useMutation({ + onSuccess: async () => { + const extra = related.size ? ` and ${related.size} related account${related.size === 1 ? "" : "s"}` : ""; + toast.success(`Banned ${user.email ?? `#${user.id}`}${extra}`); + onOpenChange(false); + setReason(""); + await onDone(); + }, + onError: (error) => toast.error("Could not ban user", { description: error.message }), + }); + + const toggle = (set: Set, value: T, on: boolean) => { + const next = new Set(set); + if (on) next.add(value); + else next.delete(value); + return next; + }; + + return ( + + + + Ban {user.name ?? user.email ?? `#${user.id}`} + + They lose dashboard and API access. Choose what else to block so they can't simply come back. + + + +
{ + event.preventDefault(); + ban.mutate({ + userId: user.id, + isBanned: true, + reason, + blockMailboxes, + blockDomains: [...domains], + alsoBanUserIds: [...related], + }); + }} + > +