Developer Guides

Verify Transactional Email Webhook Signatures in Laravel

Verify ArawaMail outgoing webhook requests in Laravel: check the X-Webhook-Secret header with hash_equals, reply within 15 seconds, and deduplicate retries.

Published

Published by Arawa Mail.

Verify Transactional Email Webhook Signatures in Laravel

Verify ArawaMail outgoing webhook requests in Laravel by comparing the X-Webhook-Secret header (sent only when you set a secret on the notify URL) against your stored secret with hash_equals. Respond with a 2xx status within 15 seconds, then queue heavy work. Deduplicate on id or message_id because retries and rare duplicates can occur. Attachment download URLs expire after 24 hours.

Why webhook verification matters for transactional email

Incoming email webhooks let your application react to mail that lands in a mailbox — support tickets, order confirmations, or automated workflows. Without verification, anyone who discovers the endpoint URL can forge payloads and trigger actions. ArawaMail solves this with an optional shared secret sent as the X-Webhook-Secret header rather than a cryptographic HMAC over the body.

This approach is simpler than signature schemes used by some providers, but it still requires constant-time comparison and careful handling of the request. The rest of this guide shows the exact pattern for Laravel, grounded in the current ArawaMail outgoing webhooks documentation.

How ArawaMail outgoing webhooks work

When an email arrives in a mailbox, ArawaMail POSTs the full email as JSON to every notify URL whose filter matches. Key behaviors:

  • Optional secret is sent only as the X-Webhook-Secret header. It is stored encrypted and never shown again in the dashboard after you save it; you can only replace or remove it.
  • Up to 20 custom headers can be added (values encrypted).
  • Recipient filter supports full mailbox addresses or bare domains.
  • Your endpoint must return any 2xx status within 15 seconds. Any other status or a timeout counts as a failure. The docs say delivery is retried up to 3 attempts in total, waiting 30 seconds, 2 minutes and 5 minutes between attempts, and after the final failure the notification is dropped (the email itself stays in the mailbox).
  • Deliveries may occasionally arrive more than once; deduplicate on the email id or message_id.
  • Attachment URLs are signed and valid for 24 hours only.
  • Mail delivered to a mailbox's Spam folder does not trigger incoming-email webhooks.
  • Redirects are not followed, so register the final HTTPS destination URL.
  • Use Send test request in the notify URL's Details popup to send a sample payload (ID 0, example.test addresses, no attachments) and inspect the result in the request history.

See the official Outgoing Webhooks guide for the complete payload schema and filtering rules. For a broader introduction to webhooks on the platform, also read our published post Transactional email webhooks in Laravel and Next.js.

How we analyzed this

We cross-checked the current ArawaMail documentation (outgoing webhooks section), the official Laravel example in those docs, and standard PHP practices for constant-time secret comparison. No HMAC-over-body signature is documented for ArawaMail; claims about other providers are limited to widely known patterns (HMAC-SHA256, Svix-style) that do not apply here.

Laravel middleware for secret verification

Place verification in middleware so every route that receives webhooks is protected. Use the raw header and hash_equals:

// app/Http/Middleware/VerifyArawaWebhook.php
namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class VerifyArawaWebhook
{
    public function handle(Request $request, Closure $next): Response
    {
        $secret = config('services.arawamail.webhook_secret');
        $header = (string) $request->header('X-Webhook-Secret');

        if (! $secret || ! hash_equals($secret, $header)) {
            abort(401, 'Invalid webhook secret');
        }

        return $next($request);
    }
}

Register the middleware and apply it to the route. The official docs show a compact route closure that does the same check inline; either style is fine as long as the comparison is constant-time.

Fast acknowledgment and queued processing

Return a 2xx response immediately, then dispatch a job. This stays inside the 15-second window even if later steps (downloading attachments, updating a CRM, etc.) take longer.

Route::post('/webhooks/arawa-incoming', function (Request $request) {
    $email = $request->json()->all();

    // Deduplicate
    $id = $email['id'] ?? $email['message_id'] ?? null;
    if ($id && ProcessedWebhook::where('external_id', $id)->exists()) {
        return response()->noContent();
    }

    ProcessIncomingEmail::dispatch($email);

    if ($id) {
        ProcessedWebhook::create(['external_id' => $id]);
    }

    return response()->noContent(); // 204
})->middleware(VerifyArawaWebhook::class);

Download attachments promptly if you need them permanently; the signed URLs expire after 24 hours.

Replay protection and other schemes

ArawaMail does not currently document a timestamp or nonce in the webhook payload for replay windows. Rely on deduplication by id/message_id and the short retry schedule. If you later integrate providers that do send HMAC signatures (common pattern: t=timestamp,v1=signature), always compute the HMAC over the raw body ($request->getContent()) and enforce a small timestamp tolerance (e.g., 5 minutes) before accepting the request.

Related guides

This post focuses on verification and security patterns. For basic webhook setup and payload structure, see Transactional email webhooks in Laravel and Next.js. For sending mail itself, see Send email in Laravel. Domain and DNS topics live under the DNS & Deliverability guides.

FAQ

Does ArawaMail use HMAC signatures on the body?

No. Current documentation describes an optional shared secret sent in the X-Webhook-Secret header. Compare it with hash_equals. Do not implement body HMAC unless the product adds that capability.

How long do attachment URLs last?

24 hours. Fetch and store files immediately if you need them beyond that window.

What status codes count as success?

Any 2xx. Respond within 15 seconds; any other status or a timeout counts as a failure and is retried (up to 3 attempts in total, per the docs).

Can I filter which mailboxes trigger a webhook?

Yes. Filters accept full mailbox addresses or bare domains. An empty filter notifies on every incoming email in the workspace.

Simple, transparent plans

Start free. Grow when your email does.

Get one domain, API access and 3,000 transactional emails every month at no cost.

Compare plans