Local disposable-email policy in Laravel Rust
Scope and attribution
Replace a local disposable-domain rule, not email syntax validation, SMTP checks or deliverability verification. Support exact domain checks, optional subdomains and effective-list allowlist removal. MX inspection and a network update daemon are outside this recipe. Reconcile the package/framework refs in this recipe's metadata with the destination application's lockfile first.
Inspect Propaganistas' src/DisposableDomains.php, src/Validation/Indisposable.php, config and domain/validation tests. The package is MIT licensed; retain its notice for adapted code/fixtures. The selected blocklist needs its own immutable ref/checksum and license review; retain dataset notices separately. Do not assume package-code licensing settles every external dataset's terms.
At the time of writing, the Package Port catalog listed a community Rust port at eramitgupta/laravel-rust-disposable-email and another email-validator alternative; check get-recipe's current port catalog. Offer those options before inlining, but inspect their syntax, dataset and network behavior rather than assuming equivalence. The local matcher below uses the Rust standard library after the app's normal validation.
Source semantics and explicit limits
If the package uses the inspected implementation, domain matching lowercases the part after the first @; this domain helper alone is not an email validator. Its actual validation rule runs email validation first. The allowlist is removed from the loaded domain array. Subdomains default off; enabling them adds only dot-boundary suffix matches. Optional MX inspection adds resolved hostnames and checks their parent boundaries even with subdomains off.
This recipe requires MX inspection to be unused. If current callers enable it, preserve it separately or obtain explicit acceptance for removing it. Do not treat a network-enabled library's default behavior as a substitute for defining DNS timeout/failure policy. An allowlisted child still matches another effective parent if subdomain checks are enabled; this is not a broad allow-first policy.
Adapt the existing validation path
- Keep required, type, length and email-format validation before this rule. Extract a domain only from a validated mailbox, not an arbitrary display-name address. Never lowercase the whole address or use a simple split as proof of validity.
- For the bounded initial contract, accept canonical ASCII DNS domains; lowercase ASCII and reject whitespace, trailing dots, empty labels and non-ASCII domains unless the app already has a tested IDNA normalization pipeline. That restriction is a deliberate difference. If Unicode is required, pin the same IDNA policy/dependency for addresses, blocklist and allowlist.
- Parse a bounded local JSON array at boot, validate every entry, normalize and deduplicate it, remove exact normalized allowlist entries, then build an immutable
HashSet<String>. All data paths and policy switches are trusted app configuration. Keep network access out of requests. - Given the validated normalized
domain: &str, the core check is:
let blocked = effective.contains(domain)
|| (include_subdomains
&& effective.iter().any(|root| {
domain.strip_suffix(root.as_str())
.is_some_and(|prefix| prefix.ends_with('.'))
}));
Here effective is the allowlist-filtered set. Bound its size and entry lengths; for large lists, walk the candidate's DNS-label ancestors and do set lookups instead of scanning all roots. Share an immutable snapshot, not mutable per-request state. If hot reload is added, validate a complete new snapshot before replacing the shared one; a read must use one coherent generation.
- Integrate the boolean as a field-level error through the existing request validator, with the app's normal translation and error format. Do not leak the blocklist or detailed email diagnostics. Keep email ownership verification and signup rate limits; list matching cannot prove ownership or identify all abuse.
- Missing/invalid initial data fails readiness or disables signup according to an explicit operational policy. Do not silently load an empty set. Failed refreshes retain the last valid snapshot and alert. Policy/result cache keys include list generation and tenant policy where relevant; bound such caches to avoid user-controlled cardinality.
Acceptance trial
Use fixture domains rather than live provider behavior. With effective blocked.test, child.blocked.test and mx-only.test, test exact and case-normalized blocks, notblocked.test and blocked.test.attacker.test boundary nonmatches, and other.blocked.test with subdomains both off and on. After allowlisting only the root, a separately listed child remains blocked. Allowlisting only the child does not bypass a remaining listed root when subdomains are enabled.
- Missing/non-string/malformed email input fails earlier validation, never masquerading as a safe unknown domain.
- Unicode, trailing-dot and invalid-label inputs exercise the declared normalization boundary.
- Validation performs no DNS/HTTP; MX fixtures do not alter local-only decisions.
- Corrupt, missing, oversized or partially written snapshots follow readiness/last-known-good policy.
- Concurrent reads and any reloads preserve snapshot consistency and tenant isolation.
Run the target app's cargo fmt --check, cargo test and strict Clippy checks. Record Rust/framework versions, dataset ref/checksum/license, normalization policy and actual results with the change.