Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
22 changes: 22 additions & 0 deletions apps/web/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { usePathname } from "next/navigation";
import type { LucideIcon } from "lucide-react";
import {
Activity,
Ban,
Building2,
CreditCard,
Globe,
Expand Down Expand Up @@ -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 },
],
},
{
Expand Down
209 changes: 209 additions & 0 deletions apps/web/src/app/(dashboard)/admin/blocklist/page.tsx
Original file line number Diff line number Diff line change
@@ -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<BlocklistType, { label: string; hint: string; placeholder: string }> = {
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<BlocklistType | typeof ALL>(ALL);

const [newType, setNewType] = useState<BlocklistType>("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 (
<>
<AdminPageHeader
title="Blocklist"
description="Email addresses and domains that can't sign up or be added for sending. Banning a user adds their addresses here automatically."
/>

<form
className="grid gap-3 rounded-xl border border-border/60 bg-card p-4 shadow-sm sm:grid-cols-[180px_1fr_1fr_auto]"
onSubmit={(event) => {
event.preventDefault();
add.mutate({ type: newType, value: newValue, reason: newReason || undefined });
}}
>
<Select value={newType} onValueChange={(value) => setNewType(value as BlocklistType)}>
<SelectTrigger aria-label="Type">
<SelectValue />
</SelectTrigger>
<SelectContent>
{(Object.keys(TYPE_LABELS) as BlocklistType[]).map((type) => (
<SelectItem key={type} value={type}>
{TYPE_LABELS[type].label}
</SelectItem>
))}
</SelectContent>
</Select>
<Input
value={newValue}
onChange={(event) => setNewValue(event.target.value)}
placeholder={TYPE_LABELS[newType].placeholder}
aria-label="Value"
/>
<Input value={newReason} onChange={(event) => setNewReason(event.target.value)} placeholder="Reason (optional)" aria-label="Reason" />
<Button type="submit" variant="destructive" disabled={newValue.trim().length < 3 || add.isPending}>
{add.isPending ? "Blocking…" : "Block"}
</Button>
<p className="text-xs text-muted-foreground sm:col-span-4">{TYPE_LABELS[newType].hint}.</p>
</form>

<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
<SearchInput
onSearch={(value) => {
setPage(1);
setQuery(value);
}}
placeholder="Search blocked values"
label="Search blocklist"
className="sm:max-w-md"
/>
<Select
value={filter}
onValueChange={(value) => {
setPage(1);
setFilter(value as BlocklistType | typeof ALL);
}}
>
<SelectTrigger className="sm:w-48" aria-label="Filter by type">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value={ALL}>All types</SelectItem>
{(Object.keys(TYPE_LABELS) as BlocklistType[]).map((type) => (
<SelectItem key={type} value={type}>
{TYPE_LABELS[type].label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>

<div className="overflow-hidden rounded-xl border border-border/60 bg-card shadow-sm">
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow className="bg-muted/30 hover:bg-muted/30">
<TableHead>Value</TableHead>
<TableHead>Type</TableHead>
<TableHead>Reason</TableHead>
<TableHead>Added</TableHead>
<TableHead className="w-12" />
</TableRow>
</TableHeader>
<TableBody>
{listQuery.isLoading ? (
Array.from({ length: 6 }, (_, i) => (
<TableRow key={i}>
{Array.from({ length: 5 }, (__, j) => (
<TableCell key={j}>
<Skeleton className="h-4 w-full max-w-40" />
</TableCell>
))}
</TableRow>
))
) : entries.length === 0 ? (
<TableRow className="hover:bg-transparent">
<TableCell colSpan={5} className="h-32 text-center text-sm text-muted-foreground">
Nothing blocked{query || filter !== ALL ? " matches" : " yet"}.
</TableCell>
</TableRow>
) : (
entries.map((entry) => (
<TableRow key={entry.id}>
<TableCell className="font-mono text-xs">{entry.value}</TableCell>
<TableCell>
<StatusPill tone={entry.type === "SENDING_DOMAIN" ? "warning" : "destructive"}>
{TYPE_LABELS[entry.type as BlocklistType].label}
</StatusPill>
</TableCell>
<TableCell className="max-w-xs text-sm text-muted-foreground">
<span className="line-clamp-2">{entry.reason ?? "No reason given"}</span>
{entry.sourceUserId ? (
<Link href={`/admin/users/${entry.sourceUserId}`} className="text-xs text-primary hover:underline">
From ban of #{entry.sourceUserId}
</Link>
) : null}
</TableCell>
<TableCell className="whitespace-nowrap text-sm text-muted-foreground">
{formatDistanceToNow(entry.createdAt, { addSuffix: true })}
</TableCell>
<TableCell>
<Button
variant="ghost"
size="icon"
aria-label={`Unblock ${entry.value}`}
disabled={remove.isPending}
onClick={() => remove.mutate({ id: entry.id })}
>
<Trash2 className="size-4" />
</Button>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
</div>

{listQuery.data ? (
<Pagination page={page} pageSize={PAGE_SIZE} total={listQuery.data.total} onPageChange={setPage} />
) : null}
</>
);
}
Loading
Loading