SECURITY ARCHITECTURE

Defense-in-depth for secrets, webhooks, and multi-tenant workloads.

KestrelMQ sits in the critical path between your internal events and external network endpoints. Every credential, signature, outbound socket connection, and tenant query is hardened by default in both Managed Cloud and MIT Self-Hosted deployments.

AES-256-GCM VaultHMAC-SHA256 SignaturesDNS + Socket IP PinningRFC 9700 Token Rotation

1. AES-256-GCM secret encryption & credential hygiene

External provider credentials (custom webhook headers and signing overrides, Mailgun API keys, Telegram Bot tokens) and inbound gateway verification secrets never touch PostgreSQL in plaintext. Before persistence, CryptoService.encryptDetached seals each JSON payload using authenticated AES-256-GCM keyed by a 256-bit ENCRYPTION_MASTER_KEY, generating a fresh cryptographically random 96-bit (12-byte) IV and 128-bit (16-byte) GCM authentication tag stored in detached columns.

Worker-Only Unsealing

Ciphertexts are decrypted strictly in isolated BullMQ worker memory for a single dispatch and are never returned by GET /v1/integrations.

SHA-256 & Argon2id

Workspace kmq_live_ API keys are shown once and persisted solely as SHA-256 digests. Operator passwords use Argon2id with dummy verification against timing enumeration.

Recursive Masking

Audit snapshots and error logs recursively scrub authorization, secret, token, apiKey, privateKey, and response PII before disk writes.

delivery_attempts[0].request_snapshot
{
  "event": "order.paid",
  "headers": {
    "content-type": "application/json",
    "authorization": "[REDACTED]",
    "x-api-key": "[REDACTED]",
    "x-kestrelmq-timestamp": "1764363092",
    "x-kestrelmq-signature": "v1=9c4e2b8f01d7a63e54b109c8a72f6d41e80b3c529a14f7d603e8b2c1a490f512"
  },
  "payload": {
    "orderId": "ord_9001",
    "customerEmail": "ops@acme.io",
    "privateKey": "[REDACTED]",
    "clientSecret": "[REDACTED]"
  }
}

2. HMAC-SHA256 webhook signatures (outbound & inbound)

Every outbound HTTP webhook dispatched by KestrelMQ is signed with a per-workspace whsec_ secret (rotatable via POST /v1/workspaces/:id/rotate-secret or overridden per integration). The worker computes HMAC-SHA256("${timestamp}.${rawBody}", secret) over the exact UTF-8 byte sequence transmitted on the wire, binding the payload to a Unix epoch timestamp to defeat replay and tampering attacks.

Outbound Webhook Headers · Protected Envelope300s replay window recommended
Content-Type: application/json
User-Agent: KestrelMQ-Webhook/1.0
X-KestrelMQ-Timestamp: 1764363092
X-KestrelMQ-Signature: v1=9c4e2b8f01d7a63e54b109c8a72f6d41e80b3c529a14f7d603e8b2c1a490f512

Custom integration headers cannot overwrite X-KestrelMQ-Signature or X-KestrelMQ-Timestamp. On the ingress path, Inbound Gateways verify Stripe, Shopify, GitHub, and custom HMAC signatures using crypto.timingSafeEqual against the raw unparsed HTTP body buffer before any event enters PostgreSQL or BullMQ.

3. DNS-level SSRF protection with socket IP pinning

Because operators and API callers supply destination URLs (via integration endpoints, targetOverride, or recipient.webhookUrl), naive URL string checks are vulnerable to DNS aliases and short-TTL DNS rebinding (TOCTOU) attacks. KestrelMQ enforces a two-stage network guard on outbound webhook dispatches and live connectivity probes:

  1. Pre-flight DNS resolution & CIDR policy check: Every A and AAAA record returned for the target hostname is normalized (including IPv4-mapped IPv6 forms) and checked against reserved, private, loopback, and cloud metadata subnets. If any resolved address falls inside a denied range, the dispatch is aborted before opening a socket.
  2. Socket-level IP pinning: Instead of allowing the HTTP client to perform a second unvalidated OS DNS lookup during connection setup, the transport agent pins the TCP/TLS socket directly to the pre-validated IP address while preserving the original hostname for TLS SNI certificate verification and the HTTP Host header. Outbound requests enforce a strict 10s execution timeout.
BLOCKED CIDR RANGESCLASSIFICATION
127.0.0.0/8, ::1/128Loopback
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16RFC 1918 Private
169.254.0.0/16, fe80::/10Link-Local & Cloud IMDS
100.64.0.0/10, fc00::/7CGNAT & Unique Local
0.0.0.0/8, ::ffff:0:0/96, 224.0.0.0/4Unspecified, Mapped & Multicast

4. Multi-tenant workspace isolation & RBAC

Every domain entity in PostgreSQL — events, schemas, templates, integrations, routing rules, inbound sources, deliveries, and attempt logs — is strictly partitioned by workspace_id. Tenant context is resolved exclusively from cryptographic authentication material at the NestJS guard boundary:

API Key Data-Plane Scope

/v1/events · /mcp

ApiKeyGuard resolves workspaceId directly from the SHA-256 hash of the presented kmq_live_ key — never from request bodies or MCP tool parameters, making cross-workspace prompt injection or IDOR impossible.

RBAC & RFC 9700 Sessions

OWNERADMINVIEWER

Control-plane endpoints verify workspace_members role hierarchy alongside domain-separated JWTs. Refresh tokens rotate atomically via a Redis Lua script; replaying a rotated jti immediately revokes the entire session family.

Per-workspace Redis sliding-window rate limits (ratelimit:workspace:{workspaceId}) isolate noisy-neighbor bursts before database writes, and a daily maintenance worker automatically purges expired delivery_attempts rows according to workspace retention policy (7 days on Free, 30 days on Pro, or operator-defined on Self-Hosted).

5. Responsible vulnerability disclosure

We welcome coordinated security research across the KestrelMQ core engine, @kestrelmq/sdk, MCP server, control-plane dashboard, and Managed Cloud infrastructure. Please do not report undisclosed security vulnerabilities in public GitHub issues.

ACKNOWLEDGMENT SLAWithin 48 hoursInitial confirmation of receipt
TRIAGE & SEVERITYWithin 5 business daysReproduction & remediation timeline
SAFE HARBORGood-faith researchTest against your own workspaces only
Report a vulnerabilityEmail security@kestrelmq.dev with reproduction steps and affected versions, or open a private GitHub Security Advisory.
RELATED TRUST & LEGAL PAGES