Why ODAC Rejects Spoofed Mail Before Disk

December 4, 2026
10 min read
13 reads
Why ODAC Rejects Spoofed Mail Before Disk

Self-hosting your own email used to mean choosing between two bad options. Either you bolted on a sprawling stack of third-party daemons that ate more RAM than your apps, or you accepted every inbound SMTP message at face value and hoped nobody noticed they could spoof ceo@yourdomain over a raw TCP socket.

That shortcut breaks down the moment a real domain goes live. Until recently, ODAC's built-in mail server accepted unauthenticated inbound mail for local recipients without verifying sender authentication or rejecting forged local addresses, and it refused null-sender bounces (MAIL FROM:<>) outright. That kept bad mail flowing into inboxes while silently dropping legitimate delivery status notifications.

So we built native inbound screening directly into the ODAC mail server (internal/mail/spam, wired into internal/mail/smtp/backend.go). Every unauthenticated message now passes through SPF, DKIM, DMARC, HELO, and local anti-spoofing checks during the SMTP DATA transaction, before a single byte is written to disk.

Screen at the Door, Never Bounce Back

A mail filter that runs after a message hits disk is already too late. Once you accept an SMTP 250 OK and later decide a message was forged, you only have two ugly choices: clutter the user's storage with junk or generate a bounce email to a forged return address (creating backscatter spam).

ODAC screens inbound mail inline inside Session.Data before calling storeRaw or expanding Outlook winmail.dat attachments. That architectural choice gives operators two immediate guarantees:

  • Zero disk footprint on refused mail: Messages that fail policy receive an SMTP 550 5.7.1 reply during the transaction. Zero mailbox rows and zero content-addressed blobs ever touch the filesystem.
  • Zero backscatter: Because ODAC refuses the message before acknowledging DATA, the sending MTA (not ODAC) is responsible for reporting the error to its sender.
  • Clean boundaries for internal traffic: Authenticated SMTP sessions bypass screening completely. Messages sent via the ODAC API (mail.send) to local accounts commit straight into the recipient's mailbox transaction rather than looping through MX onto port 25 unauthenticated.

At the same time, ODAC enforces screening on both inbound port 25 (STARTTLS) and port 465 (implicit TLS) whenever a session has no login, because port 465 accepts unauthenticated local delivery too. And unauthenticated sessions now accept the null reverse path (MAIL FROM:<>) as RFC 5321 requires, checking SPF against the HELO domain (postmaster@<helo>) per RFC 7208 so legitimate bounces arrive safely instead of disappearing.

ODAC inbound SMTP screening flow showing authenticated bypass versus unauthenticated screening through internal/mail/spam with 550 5.7.1 reject, 451 4.7.0 defer, and INBOX or Junk delivery

Inside the Multi-Layer Screening Pipeline

Every unauthenticated message enters Filter.Check with a strict 15-second context deadline and a panic-recovery boundary. Rather than trusting any single signal, ODAC combines connection hygiene, cryptographic authentication, and structural header validation:

  • HELO validation: ODAC inspects how the remote MTA introduces itself. Bare IP addresses (HELO_BARE_IP, +1.0), non-FQDN strings without a dot (HELO_NOT_FQDN, +1.0), and external servers claiming one of your own domains or hostnames (HELO_FORGED_LOCAL, +3.0) all raise the spam score. Bracketed address literals remain legal per RFC 5321.
  • SPF verification: Evaluates the MAIL FROM domain (or HELO domain for null senders) against the connecting IP. Failures add SPF_FAIL (+3.5), SPF_SOFTFAIL (+1.5), or SPF_PERMERROR (+1.0).
  • DKIM verification: Verifies up to 5 DKIM signatures (maxDKIMSignatures = 5) per message. If no signature passes and at least one fails, ODAC scores DKIM_INVALID (+1.5).
  • DMARC evaluation: Evaluates RFC 7489 alignment (honoring sp= subdomain policies and pct= sampling) for every author domain. When all author domains pass, ODAC awards DMARC_PASS (-1.0) once per message so an attacker cannot farm negative scores by listing multiple domains they control.
  • No-auth penalty: Messages that pass neither SPF nor DKIM pick up NO_AUTH (+1.5).

When a domain's DMARC policy is p=quarantine, failing messages receive DMARC_QUARANTINE (+3.0) and land in the Junk folder. When a domain publishes p=reject, failing messages hit DMARC_REJECT (+4.0) and are refused at SMTP time with 550 5.7.1.

Catching the Header Tricks That Fool Strict Parsers

Real-world spammers love parser mismatches. Go's standard net/textproto header reader stops parsing the moment it hits a malformed header line, while most email clients keep scanning past the broken line and render whatever From: header appears below it.

If a spam filter used a strict parser and gave up early, a crafted malformed line above a forged From: header would skip DMARC and spoofing checks while the recipient's mail client still displayed the forged sender.

ODAC avoids that trap by reading headers through mimetree.Fields (internal/mail/mimetree/fields.go), the exact same lenient reader that populates ODAC's mailbox display columns. Every From: field is inspected, every @ address inside unparseable From: values is extracted, and multiple safeguards kick in:

  • Missing Date: adds DATE_MISSING (+1.0), missing Message-ID: adds MSGID_MISSING (+0.5), malformed header blocks add HEADER_MALFORMED (+2.0), and missing or broken From: headers add FROM_MISSING (+3.0) or FROM_INVALID (+2.0).
  • Multiple From: headers or multiple addresses in a single From: trigger FROM_MULTIPLE (+3.0), and every single address is checked independently.
  • When multiple author domains appear, ODAC applies the strictest failing DMARC policy across all of them.
  • Any message naming more than 8 From: addresses (maxAuthors = 8) triggers FROM_TOO_MANY (+5.0) and is rejected outright with 550 5.7.1.

Comparison of strict net/textproto header parsing stopping on a broken line versus ODAC mimetree.Fields scanning through to check DMARC, local domains, and local accounts

Two Rules That Stop Local Impersonation Cold

External DMARC policies only protect domains that actually publish _dmarc DNS records. Self-hosted servers often manage domains whose DNS lives elsewhere, or domains without strict DMARC policies yet, making them prime targets for internal phishing.

ODAC closes that gap with two dedicated local rules that run unconditionally on unauthenticated inbound sessions:

  1. Forged local accounts (LOCAL_ACCOUNT_FORGED, +10.0): Every mailbox account on an ODAC server sends outbound mail through an authenticated SMTP session (or mail.send). If an external, unauthenticated session names one of your local accounts in MAIL FROM or any From: address, ODAC rejects it with 550 5.7.1, even if SPF and DKIM appear to pass.
  2. Local domain spoofing (FROM_LOCAL_SPOOF / MAILFROM_LOCAL_SPOOF, +4.0): If an external session claims any address on one of your configured local domains (or subdomains) without an aligned SPF or DKIM pass for that domain, ODAC rejects it with 550 5.7.1. This holds true regardless of what DMARC record the domain publishes, and even if it publishes no DMARC record at all.

Why is this so effective? Because only the domain owner controls the DNS records required to pass SPF or DKIM for that domain. Legitimate third-party transactional services configured by you still get through cleanly, while drive-by spoofers are stopped at the TCP door.

Fail-Safe Reliability: DNS Glitches Never Drop Mail

A spam filter that panics on weird MIME or turns a DNS timeout into a permanent 550 bounce is worse than no filter at all. A single stalled resolver could turn every incoming customer email into a permanent rejection.

ODAC treats every transient failure as "unknown", never as spam evidence:

  • DNS timeouts add zero points: If SPF, DKIM, or DMARC hits a temporary DNS error (TempError), it contributes 0.0 to the score.
  • Temporary 451 deferral on pending refusals: If a message would be rejected by DMARC p=reject or local domain spoofing, AND an aligned SPF or DKIM lookup hit a temporary DNS failure (evaluation.pending), ODAC replies with 451 4.7.0 instead of 550. The sending MTA keeps the message in its queue and retries once DNS recovers.
  • Database lookup safety: If the local account lookup errors out while checking for LOCAL_ACCOUNT_FORGED, ODAC logs the error and returns 451 4.7.0 rather than guessing.
  • Panic isolation: Filter.Check wraps evaluation in a recover() guard. If a crafted message ever trips a parser panic, ODAC logs the stack trace and falls back to an unscreened INBOX verdict, preventing a remotely triggerable crash loop in the mail daemon.

Inspecting Verdict Headers and Rolling Out With ODAC_MAIL_SPAM

Every screened message that reaches INBOX or Junk gets two standard headers prepended at the very top of the raw message: Authentication-Results and X-Spam-Status. Because ODAC prepends its headers above the original payload, mail clients and downstream filters read ODAC's verdict first and ignore any forged Authentication-Results headers an attacker injected lower down.

Authentication-Results: mx.northstar.dev;
	spf=pass smtp.mailfrom=news@mailcraft.net;
	dkim=pass header.d=mailcraft.net;
	dmarc=pass header.from=mailcraft.net
X-Spam-Status: No, score=-1.0 required=5.0 tests=DMARC_PASS

Any score below 5.0 lands in INBOX, while scores of 5.0 or higher (or DMARC p=quarantine failures) move to Junk. The tests= field lists every rule that fired, giving you an instant audit trail whenever an email lands somewhere unexpected.

Operators control how aggressively ODAC acts on those verdicts using the ODAC_MAIL_SPAM environment variable on the ODAC server container:

ODAC_MAIL_SPAM Verdict Behaviour Best For
enforce (default) Delivers to INBOX, moves score >= 5.0 or p=quarantine to Junk, rejects spoofs and p=reject with 550 5.7.1 Production servers after verifying third-party senders
junk Never rejects with 550; anything enforce would reject goes to Junk instead Servers receiving mailing lists or aggressive forwarders
tag Stamps Authentication-Results and X-Spam-Status headers, always delivers to INBOX Auditing third-party relays before enforcing
off Skips all screening checks and adds no headers Dedicated internal relays behind an upstream gateway

Routing matrix for ODAC_MAIL_SPAM modes tag, junk, and enforce across clean, quarantine, and spoof or reject verdicts

Step-by-Step Operator Rollout

Because ODAC_MAIL_SPAM is configured directly on the ODAC server container environment rather than via dashboard toggles, rolling it out safely takes four quick steps:

  1. Audit in tag mode first (optional for complex setups): If your domains receive mail from legacy contact forms, third-party SaaS senders, or mailing-list forwarders, set ODAC_MAIL_SPAM=tag on your ODAC server container and restart it.
  2. Inspect delivered headers: Open a few delivered messages from your newsletters, transactional relays, and external forms. Check Authentication-Results and X-Spam-Status to verify they pass SPF or DKIM for your domain. If you need to verify which local mailboxes exist for your domain, check app.odac.run or run odac mail list -d northstar.dev in your terminal.
  3. Fix unauthorized external senders: Any service sending as a no-mailbox address on your domain (such as noreply@northstar.dev or founder@northstar.dev) must be authorized in your domain's SPF record or configured with a valid DKIM key. Even if your domain has no DMARC DNS record, ODAC will reject unauthorized external mail claiming your domain once enforce is active.
  4. Switch to enforce or junk: Remove the override (since enforce is the default) or set ODAC_MAIL_SPAM=enforce.
# Step 1: Observe verdicts in headers without rejecting or moving messages
ODAC_MAIL_SPAM=tag

# Step 4: Default production setting (rejects forged senders and DMARC p=reject)
ODAC_MAIL_SPAM=enforce

Keep one important edge case in mind if your team subscribes to mailing lists or external auto-forwarders. When one of your local accounts emails a mailing list and that list resends the message back to other members on your ODAC server with your user's address still in From:, that inbound copy arrives unauthenticated from outside and triggers LOCAL_ACCOUNT_FORGED. If your users rely on mailing lists that behave this way, set ODAC_MAIL_SPAM=junk so those messages land safely in Junk where they can be recovered instead of bouncing with 550 5.7.1.

Zero-config security shouldn't require bolting an extra gigabyte of Perl or Python spam daemons onto your server. By screening inbound SMTP traffic inside the transaction path, honoring DNS uncertainty with 451 deferrals, and enforcing strict local anti-spoofing before writing a single blob, ODAC keeps forged mail out of your storage and your users' inboxes by default.