Skip to content
Open
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
13 changes: 13 additions & 0 deletions frontend/src/lib/dialogs/EmailLogModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,19 @@
<AlertTriangle class="w-3 h-3" />
{t('channel.emailLog.rateLimited')}
</span>
{:else if msg.skipped_reason}
<!-- inline-style-guard-exempt: held-mail badge mirrors the rate-limited badge's warning surface. -->
<span
class="inline-flex items-center gap-1 text-xs font-medium px-2 py-0.5 rounded-full"
style="background: var(--ds-surface-warning, rgba(234, 88, 12, 0.12)); color: var(--ds-text-warning, var(--ds-text));"
title={msg.skipped_reason}
data-testid="email-log-skipped-badge"
>
<AlertTriangle class="w-3 h-3" />
{msg.skipped_reason === 'unauthenticated_sender'
? t('channel.emailLog.heldUnauthenticated')
: msg.skipped_reason}
</span>
{:else if msg.item_id}
{@const href = getItemHref(msg)}
<svelte:element this={href ? 'a' : 'span'} href={href} class="inline-flex items-center gap-1 text-xs font-medium px-2 py-0.5 rounded-full {href ? 'hover:opacity-80' : ''}" style="background: var(--ds-surface-selected, rgba(59, 130, 246, 0.1)); color: var(--ds-text-accent, var(--ds-text)); {href ? 'text-decoration: none;' : ''}">
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/de/backfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default {
"outboxStatus": "Status",
"outboxTo": "An",
"rateLimited": "Ratenbegrenzt",
"heldUnauthenticated": "Zurückgehalten: nicht authentifizierter Absender",
"rateLimitedCount": "{count} Nachricht(en) durch das Absender-Ratenlimit zurückgehalten und warten auf erneute Einreihung.",
"requeue": "Erneut einreihen und wiederholen",
"requeueing": "Wird erneut eingereiht...",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/en/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ export default {
next: 'Next',
page: 'Page {page} of {total}',
rateLimited: 'Rate limited',
heldUnauthenticated: 'Held: unauthenticated sender',
rateLimitedCount: '{count} message(s) held back by the per-sender rate limit and waiting for requeue.',
requeue: 'Requeue and retry',
requeueing: 'Requeueing...',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/fa/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ export default {
"next": "بعدی",
"page": "صفحه {page} از {total}",
"rateLimited": "نرخ محدود",
"heldUnauthenticated": "نگه‌داشته شد: فرستنده تأیید نشده",
"rateLimitedCount": "{count} پیام به‌دلیل محدودیت نرخ هر فرستنده متوقف شده و در انتظار بازگردانی به صف است.",
"requeue": "بازگردانی به صف و تلاش مجدد",
"requeueing": "در حال بازگردانی به صف...",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/fr/backfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default {
"outboxStatus": "Statut",
"outboxTo": "À",
"rateLimited": "Limité en débit",
"heldUnauthenticated": "Retenu : expéditeur non authentifié",
"rateLimitedCount": "{count} message(s) retenue(s) par la limite de débit par expéditeur et en attente de remise en file.",
"requeue": "Remettre en file et réessayer",
"requeueing": "Remise en file...",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/nl/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ export default {
next: 'Volgende',
page: 'Pagina {page} van {total}',
rateLimited: 'Limiet bereikt',
heldUnauthenticated: 'Tegenhouden: niet-geverifieerde afzender',
rateLimitedCount: '{count} bericht(en) tegengehouden door de limiet per afzender en wachtend op herplaatsing.',
requeue: 'Herplaatsen en opnieuw proberen',
requeueing: 'Herplaatsen...',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/pl/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ export default {
next: 'Następna',
page: 'Strona {page} z {total}',
rateLimited: 'Limit tempa',
heldUnauthenticated: 'Wstrzymano: nieuwierzytelniony nadawca',
rateLimitedCount: '{count} wiadomości wstrzymanych przez limit tempa na nadawcę i oczekujących na ponowne zakolejkowanie.',
requeue: 'Zakolejkuj ponownie i spróbuj ponownie',
requeueing: 'Ponowne kolejkuje...',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/ru/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export default {
next: 'Далее',
page: 'Страница {page} из {total}',
rateLimited: 'Превышен лимит',
heldUnauthenticated: 'Задержано: отправитель не аутентифицирован',
rateLimitedCount: 'Сообщений, отложенных лимитом отправителя и ожидающих повторной постановки в очередь: {count}.',
requeue: 'Вернуть в очередь и повторить',
requeueing: 'Возврат в очередь…',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/zh-CN/backfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default {
"outboxStatus": "状态",
"outboxTo": "收件人",
"rateLimited": "已限流",
"heldUnauthenticated": "已暂扣:发件人未通过身份验证",
"rateLimitedCount": "{count} 条消息因发件人速率限制被扣留,等待重新入队。",
"requeue": "重新入队并重试",
"requeueing": "正在重新入队...",
Expand Down
17 changes: 12 additions & 5 deletions frontend/src/lib/settings/diagnostics/EmailIntakeSection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
const CATEGORY_LABELS = {
delivery_failure: 'Delivery failure',
auto_reply: 'Auto-reply',
unauthenticated_sender: 'Unauthenticated sender',
};

let window = $state('24h');
Expand Down Expand Up @@ -45,13 +46,14 @@
}

function categoryVariant(category) {
return category === 'delivery_failure' ? 'danger' : 'neutral';
if (category === 'delivery_failure') return 'danger';
return category === 'unauthenticated_sender' ? 'warning' : 'neutral';
}
</script>

<DiagnosticsSection
title="Email intake: system-generated mail"
subtitle="Bounces and auto-replies that arrived by email and were deliberately not turned into work items. They are kept here so delivery failures and responder loops stay visible without cluttering the backlog."
title="Email intake: held and skipped mail"
subtitle="Bounces, auto-replies, and (under a strict sender-authentication policy) mail whose sender could not be authenticated. These messages were deliberately not turned into work items and are kept here so delivery failures, responder loops, and spoofing attempts stay visible without cluttering the backlog."
dataTestId="diagnostics-email-intake"
onLoad={load}
lastRefreshed={lastRefreshed}
Expand All @@ -65,7 +67,7 @@
<IconInbox size={20} stroke={1.75} style="color: var(--ds-icon-subtle);" />
<div>
<div class="text-sm font-medium" style="color: var(--ds-text);">
{total} skipped message{total === 1 ? '' : 's'}
{total} held or skipped message{total === 1 ? '' : 's'}
</div>
<div class="text-xs" style="color: var(--ds-text-subtle);">
Not created as work items; recorded for diagnostics only.
Expand All @@ -92,7 +94,7 @@
{#if !view.loading && !view.error && total === 0}
<Card variant="outlined">
<p class="text-sm" style="color: var(--ds-text-subtle);">
No system-generated mail was skipped in this window.
No held or skipped mail in this window.
</p>
</Card>
{:else if !view.error}
Expand Down Expand Up @@ -132,6 +134,11 @@
<Badge variant={categoryVariant(message.category)} size="xs">
{categoryLabel(message.category)}
</Badge>
{#if message.sender_auth}
<div class="text-xs mt-1 text-ds-text-subtle">
{message.sender_auth}
</div>
{/if}
</td>
<td class="py-2 pr-4" style="color: var(--ds-text);">
{#if message.from_name}
Expand Down
59 changes: 59 additions & 0 deletions internal/database/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3727,6 +3727,65 @@ END $$;
CREATE UNIQUE INDEX IF NOT EXISTS uq_priorities_single_default ON priorities(is_default) WHERE is_default = true;
`,
},
{
// WI-2362: inbound mail authenticated its From address only through the
// attacker-controlled header. sender_auth records the SPF/DKIM/DMARC
// outcome on each tracking row, and intakes.sender_authentication lets an
// operator relax the default strict policy per intake. Empty
// sender_authentication means strict, so existing intakes need no backfill;
// operators whose provider does not add authentication headers must set it
// to 'off' explicitly.
Version: "20261204_email_sender_authentication",
Name: "Record inbound sender authentication and per-intake policy (WI-2362)",
CheckSQLite: "SELECT CASE WHEN (" + sqliteColumnCheck("email_message_tracking", "sender_auth") +
") > 0 AND (" + sqliteColumnCheck("intakes", "sender_authentication") + ") > 0 THEN 1 ELSE 0 END",
CheckPostgres: "SELECT CASE WHEN (" + pgColumnCheck("email_message_tracking", "sender_auth") +
") > 0 AND (" + pgColumnCheck("intakes", "sender_authentication") + ") > 0 THEN 1 ELSE 0 END",
SQLite: `
ALTER TABLE email_message_tracking ADD COLUMN sender_auth TEXT;
ALTER TABLE intakes ADD COLUMN sender_authentication TEXT NOT NULL DEFAULT '';
`,
Postgres: `
ALTER TABLE email_message_tracking ADD COLUMN IF NOT EXISTS sender_auth TEXT;
ALTER TABLE intakes ADD COLUMN IF NOT EXISTS sender_authentication TEXT NOT NULL DEFAULT '';
`,
},
{
// WI-2365: only a recipient-bound outbound Message-ID may authorize an
// email reply. key_generation marks rows issued under that scheme (>= 1);
// pre-upgrade rows default to 0 and never authorize. The marker lives on
// the tracking row too so it survives outbox pruning. contact_email/
// contact_name keep an unverified inbound sender off the customer's
// portal identity until a reply key proves control of the address.
Version: "20261205_email_reply_keys",
Name: "Recipient-bound reply keys and unverified email contacts (WI-2365)",
CheckSQLite: "SELECT CASE WHEN (" + sqliteColumnCheck("email_reply_outbox", "key_generation") +
") > 0 AND (" + sqliteColumnCheck("email_message_tracking", "key_generation") +
") > 0 AND (" + sqliteColumnCheck("items", "contact_email") +
") > 0 AND (" + sqliteIndexCheck("idx_email_reply_outbox_message_id") + ") > 0 THEN 1 ELSE 0 END",
CheckPostgres: "SELECT CASE WHEN (" + pgColumnCheck("email_reply_outbox", "key_generation") +
") > 0 AND (" + pgColumnCheck("email_message_tracking", "key_generation") +
") > 0 AND (" + pgColumnCheck("items", "contact_email") +
") > 0 AND (" + pgIndexCheck("idx_email_reply_outbox_message_id") + ") > 0 THEN 1 ELSE 0 END",
SQLite: `
ALTER TABLE email_reply_outbox ADD COLUMN key_generation INTEGER NOT NULL DEFAULT 0;
ALTER TABLE email_message_tracking ADD COLUMN key_generation INTEGER NOT NULL DEFAULT 0;
ALTER TABLE items ADD COLUMN contact_email TEXT;
ALTER TABLE items ADD COLUMN contact_name TEXT;
CREATE INDEX IF NOT EXISTS idx_email_reply_outbox_message_id ON email_reply_outbox(message_id);
CREATE INDEX IF NOT EXISTS idx_email_reply_outbox_item_created ON email_reply_outbox(item_id, created_at);
CREATE INDEX IF NOT EXISTS idx_email_message_tracking_key_generation ON email_message_tracking(key_generation);
`,
Postgres: `
ALTER TABLE email_reply_outbox ADD COLUMN IF NOT EXISTS key_generation INTEGER NOT NULL DEFAULT 0;
ALTER TABLE email_message_tracking ADD COLUMN IF NOT EXISTS key_generation INTEGER NOT NULL DEFAULT 0;
ALTER TABLE items ADD COLUMN IF NOT EXISTS contact_email TEXT;
ALTER TABLE items ADD COLUMN IF NOT EXISTS contact_name TEXT;
CREATE INDEX IF NOT EXISTS idx_email_reply_outbox_message_id ON email_reply_outbox(message_id);
CREATE INDEX IF NOT EXISTS idx_email_reply_outbox_item_created ON email_reply_outbox(item_id, created_at);
CREATE INDEX IF NOT EXISTS idx_email_message_tracking_key_generation ON email_message_tracking(key_generation);
`,
},
}

// domainEventClaimableIndexMigration adds the partial index the claim query
Expand Down
33 changes: 29 additions & 4 deletions internal/database/schema/email.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ CREATE TABLE IF NOT EXISTS intakes (
item_type_id INTEGER, -- item type created for the routing workspace
rate_limit_per_hour INTEGER,
processing_disposition TEXT NOT NULL DEFAULT '',
-- sender_authentication overrides the mailbox's inbound sender
-- authentication policy for this intake. Empty inherits the mailbox default.
sender_authentication TEXT NOT NULL DEFAULT '',
send_confirmation BOOLEAN NOT NULL DEFAULT false,
import_existing_mail BOOLEAN NOT NULL DEFAULT false,
status TEXT NOT NULL DEFAULT 'enabled',
Expand Down Expand Up @@ -122,6 +125,11 @@ CREATE TABLE IF NOT EXISTS email_message_tracking (
subject TEXT,
item_id INTEGER,
comment_id INTEGER,
-- key_generation marks the reply-key scheme that issued an outbound
-- Message-ID: 1 is the recipient-bound scheme (WI-2365), 0 is a
-- pre-upgrade row. Only generation >= 1 authorizes a reply, and the marker
-- survives outbox pruning so a pruned key can never become valid again.
key_generation INTEGER NOT NULL DEFAULT 0,
-- attachments_status records whether the email's attachments survived
-- processing. NULL = no attachments / not yet computed. 'ok' = all stored.
-- 'partial' = some stored, some dropped due to fatal write/insert errors
Expand All @@ -142,11 +150,18 @@ CREATE TABLE IF NOT EXISTS email_message_tracking (
-- reprocessing the same email. It is only cleared when the channel is
-- deleted and cascades the tracking rows.
completed_at DATETIME,
-- skipped_reason records machine-generated mail (bounces, auto-replies)
-- that intake deliberately did not turn into a ticket. The value is a
-- SystemMailCategory; NULL for mail that was processed normally. Surfaced
-- by the admin email-intake diagnostics view.
-- skipped_reason records mail intake deliberately did not turn into a
-- ticket: machine-generated mail (bounces, auto-replies) and, under a
-- strict sender-authentication policy, mail whose From address could not
-- be authenticated. The value is a SystemMailCategory or
-- 'unauthenticated_sender'; NULL for mail that was processed normally.
-- Surfaced by the admin email-intake diagnostics view.
skipped_reason TEXT,
-- sender_auth records the outcome of evaluating the message's SPF, DKIM,
-- and DMARC results against the From domain, e.g. 'dmarc=pass', 'spf=fail',
-- or 'none'. NULL for rows written before the check existed. Surfaced by
-- the channel email log and admin diagnostics.
sender_auth TEXT,
processed_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE CASCADE,
FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE SET NULL,
Expand All @@ -155,6 +170,7 @@ CREATE TABLE IF NOT EXISTS email_message_tracking (

CREATE INDEX IF NOT EXISTS idx_email_message_tracking_channel_id ON email_message_tracking(channel_id);
CREATE INDEX IF NOT EXISTS idx_email_message_tracking_message_id ON email_message_tracking(message_id);
CREATE INDEX IF NOT EXISTS idx_email_message_tracking_key_generation ON email_message_tracking(key_generation);
CREATE INDEX IF NOT EXISTS idx_email_message_tracking_in_reply_to ON email_message_tracking(in_reply_to);
CREATE UNIQUE INDEX IF NOT EXISTS idx_email_message_tracking_dedup ON email_message_tracking(channel_id, dedup_key);
CREATE INDEX IF NOT EXISTS idx_email_message_tracking_sender ON email_message_tracking(from_email);
Expand All @@ -179,6 +195,8 @@ CREATE TABLE IF NOT EXISTS email_reply_outbox (
html_body TEXT NOT NULL,
text_body TEXT NOT NULL,
message_id TEXT NOT NULL,
-- key_generation: see email_message_tracking for the reply-key contract.
key_generation INTEGER NOT NULL DEFAULT 0,
in_reply_to TEXT NOT NULL DEFAULT '',
references_json TEXT NOT NULL DEFAULT '[]',
from_email TEXT NOT NULL,
Expand Down Expand Up @@ -207,6 +225,13 @@ CREATE TABLE IF NOT EXISTS email_reply_outbox (
CREATE INDEX IF NOT EXISTS idx_email_reply_outbox_pending
ON email_reply_outbox(delivered_at, next_attempt_at);

-- Reply-key lookup by Message-ID and thread assembly by item. Without these,
-- every inbound reply scans the retained outbox.
CREATE INDEX IF NOT EXISTS idx_email_reply_outbox_message_id
ON email_reply_outbox(message_id);
CREATE INDEX IF NOT EXISTS idx_email_reply_outbox_item_created
ON email_reply_outbox(item_id, created_at);

-- One outbound reply per comment recipient (WI-1136): the creator plus every
-- external request participant gets their own row.
CREATE UNIQUE INDEX IF NOT EXISTS uq_email_reply_outbox_comment_recipient
Expand Down
16 changes: 15 additions & 1 deletion internal/database/schema/email_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ CREATE TABLE IF NOT EXISTS intakes (
item_type_id INTEGER,
rate_limit_per_hour INTEGER,
processing_disposition TEXT NOT NULL DEFAULT '',
-- sender_authentication: see email.sql for the column contract.
sender_authentication TEXT NOT NULL DEFAULT '',
send_confirmation BOOLEAN NOT NULL DEFAULT false,
import_existing_mail BOOLEAN NOT NULL DEFAULT false,
status TEXT NOT NULL DEFAULT 'enabled',
Expand Down Expand Up @@ -110,6 +112,8 @@ CREATE TABLE IF NOT EXISTS email_message_tracking (
subject TEXT,
item_id INTEGER,
comment_id INTEGER,
-- key_generation: see email.sql for the reply-key contract.
key_generation INTEGER NOT NULL DEFAULT 0,
-- attachments_status: see email.sql for the column contract.
attachments_status TEXT CHECK(attachments_status IN ('ok','partial','failed') OR attachments_status IS NULL),
direction TEXT DEFAULT 'inbound' CHECK(direction IN ('inbound', 'outbound')),
Expand All @@ -118,8 +122,9 @@ CREATE TABLE IF NOT EXISTS email_message_tracking (
uid_validity BIGINT NOT NULL DEFAULT 0,
rate_limited_at TIMESTAMPTZ,
completed_at TIMESTAMPTZ,
-- skipped_reason: see email.sql for the column contract.
-- skipped_reason/sender_auth: see email.sql for the column contract.
skipped_reason TEXT,
sender_auth TEXT,
processed_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE CASCADE,
FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE SET NULL,
Expand All @@ -128,6 +133,7 @@ CREATE TABLE IF NOT EXISTS email_message_tracking (

CREATE INDEX IF NOT EXISTS idx_email_message_tracking_channel_id ON email_message_tracking(channel_id);
CREATE INDEX IF NOT EXISTS idx_email_message_tracking_message_id ON email_message_tracking(message_id);
CREATE INDEX IF NOT EXISTS idx_email_message_tracking_key_generation ON email_message_tracking(key_generation);
CREATE INDEX IF NOT EXISTS idx_email_message_tracking_in_reply_to ON email_message_tracking(in_reply_to);
CREATE UNIQUE INDEX IF NOT EXISTS idx_email_message_tracking_dedup ON email_message_tracking(channel_id, dedup_key);
CREATE INDEX IF NOT EXISTS idx_email_message_tracking_sender ON email_message_tracking(from_email);
Expand All @@ -150,6 +156,8 @@ CREATE TABLE IF NOT EXISTS email_reply_outbox (
html_body TEXT NOT NULL,
text_body TEXT NOT NULL,
message_id TEXT NOT NULL,
-- key_generation: see email.sql for the reply-key contract.
key_generation INTEGER NOT NULL DEFAULT 0,
in_reply_to TEXT NOT NULL DEFAULT '',
references_json TEXT NOT NULL DEFAULT '[]',
from_email TEXT NOT NULL,
Expand All @@ -176,6 +184,12 @@ CREATE TABLE IF NOT EXISTS email_reply_outbox (
CREATE INDEX IF NOT EXISTS idx_email_reply_outbox_pending
ON email_reply_outbox(delivered_at, next_attempt_at);

-- Reply-key lookup by Message-ID and thread assembly by item.
CREATE INDEX IF NOT EXISTS idx_email_reply_outbox_message_id
ON email_reply_outbox(message_id);
CREATE INDEX IF NOT EXISTS idx_email_reply_outbox_item_created
ON email_reply_outbox(item_id, created_at);

-- One outbound reply per comment recipient (WI-1136).
CREATE UNIQUE INDEX IF NOT EXISTS uq_email_reply_outbox_comment_recipient
ON email_reply_outbox(comment_id, to_email)
Expand Down
6 changes: 6 additions & 0 deletions internal/database/schema/items.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ CREATE TABLE IF NOT EXISTS items (
creator_id INTEGER REFERENCES users(id) ON DELETE SET NULL,
reporter_id INTEGER REFERENCES users(id) ON DELETE SET NULL,
creator_portal_customer_id INTEGER REFERENCES portal_customers(id) ON DELETE SET NULL,
-- Unverified contact recorded for an inbound email before its sender proved
-- control of the address. Kept separate from creator_portal_customer_id so
-- a claimed From cannot make the item appear in a customer's portal or
-- organisation sharing (WI-2365). Cleared when the contact is verified.
contact_email TEXT,
contact_name TEXT,
custom_field_values TEXT,
virtual_field_data TEXT,
calendar_data TEXT,
Expand Down
Loading
Loading