Laravel PHP · Inline✓ Human-reviewed

App-owned disposable-email rule in Laravel PHP

Replace the package's local-only validation path with a Laravel application rule, explicit snapshot operations and tested allowlist/subdomain policy; retain email validation and ownership checks.

Approved 2026-12-04T13:20:41.719819Z · Submission 59

App-owned disposable-email rule in Laravel PHP

Scope and provenance

Inline a local domain-list rule in the app's existing signup validation. Keep Laravel's own email validator and support exact matches, optional subdomains and removal of allowlisted list entries. Exclude MX checks, SMTP verification and a request-time list downloader. Compare the source/framework refs in this recipe's metadata with the app's composer.lock before changing code.

The reference package by Propaganistas is MIT licensed. Read src/DisposableDomains.php, src/Validation/Indisposable.php, config, the update command and validation/domain tests. Preserve notices when adapting source/fixtures. Record a separate immutable ref/checksum and license for the blocklist you choose; external data terms do not automatically follow the wrapper's code license. This recipe supplies no live provider list and has not been exercised in your app.

Compatibility conditions

If your package uses the inspected implementation, isDisposable() is a domain helper, not a syntax validator: the actual rule invokes Laravel's email validator before it. Domain checks lowercase the part after the first @. The configured allowlist is subtracted from loaded domains. Exact listed subdomains still match with include_subdomains off; turning it on adds dot-boundary matches against listed parents.

If callers use indisposable:mx or inspectMxRecords(), this local-only recipe is not equivalent. The inspected MX path checks resolved hostnames and their parents independently of the ordinary subdomain flag. Keep that dependency/behavior until separately migrated; do not silently drop it. An allowlisted child is not a universal bypass for another listed parent.

Put the rule in the existing request validator

  1. Use the app's normal bail, required, string and email rules before the local closure or app-owned ValidationRule. Match the previous application's email-validation mode; DNS syntax/deliverability options are separate policy. Do not pass arrays or malformed mailboxes to the matcher.
  2. Define canonical domains before loading data. A bounded initial policy accepts ASCII DNS domains, lowercases ASCII and rejects trailing dots, whitespace, empty labels and non-ASCII domains unless the app has a tested IDNA pipeline. This restriction is a deliberate difference from the raw helper. If internationalized domains are required, normalize email/list/allowlist with the same pinned IDNA policy.
  3. At boot load a trusted local bounded JSON array using JSON_THROW_ON_ERROR, validate/deduplicate normalized entries and remove exact allowlisted entries. Represent the effective list as array<string, true>. Store no request-specific email data in a singleton. A missing/corrupt initial list must fail readiness or explicitly disable signup, not silently permit every domain.
  4. Inside the validated rule, after domain extraction/normalization, use the effective set:
$blocked = isset($effective[$domain]);
if (!$blocked && $includeSubdomains) {
    foreach ($effective as $root => $_) {
        if (str_ends_with($domain, '.'.$root)) {
            $blocked = true;
            break;
        }
    }
}
if ($blocked) {
    $fail('validation.indisposable')->translate();
}

$domain and all effective-set keys must already be canonical ASCII DNS names. Bound entry count/length; for a large list, walk DNS-label parents with set membership instead of a full suffix scan. Provide the translation through the app's normal language files.

  1. Keep updates as a separate operational step. Download only from trusted configured HTTPS sources with limits/timeouts, validate the complete response, and atomically install the file on the same filesystem. Keep the previous snapshot on failure. Refresh long-lived workers/shared caches coherently; version cache keys by data generation and allowlist/subdomain policy, including tenant where relevant.
  2. Keep email ownership verification and signup rate limits. The rule adds abuse friction, not a guarantee about a person or mailbox. No HTTP/DNS request belongs in this local validation path.
  3. Only after auditing all callers, remove the package, provider/config aliases, scheduled disposable:update invocation and obsolete cache entries. Do not remove unrelated validation or email-verification code. Retain the dataset through an app-owned path; a vendor file disappears when Composer removes its package.

Trial checklist

Use an application fixture list containing blocked.test, child.blocked.test and mx-only.test. Test exact/mixed-case blocks, boundary nonmatches notblocked.test and blocked.test.attacker.test, plus other.blocked.test with subdomains off/on. Removing the root via allowlist must not remove a separately listed child. Removing only a child cannot bypass a remaining listed parent when subdomain matching is on.

  • Missing/non-string/malformed addresses fail the earlier rules; the closure cannot turn them into a pass.
  • Unsupported Unicode, trailing dots and invalid labels follow the explicit normalization policy.
  • Local validation performs no DNS/HTTP. Rules formerly using MX are detected rather than silently weakened.
  • Corrupt/missing/oversized snapshots fail readiness as specified; failed refresh keeps the last valid policy.
  • Sequential requests in a long-lived worker and tenant-specific policy caches do not leak allowlists or stale policy.

Run composer validate --strict, composer audit, the app's full test suite and configured static analysis. Record PHP/Laravel versions, dataset ref/checksum/license, accepted policy differences and actual outputs with the change.