Skip to content

Watermarking and Attribution

Evan Newman edited this page Nov 30, 2026 · 1 revision

Watermarking and attribution

MirageGate's attribution engine (internal/watermark/watermark.go) embeds compact, unforgeable HMAC-SHA256 breadcrumbs into every labyrinth artifact so that when an autonomous agent hands off a discovered URL, API key, or JWT to a human operator—minutes, hours, or days later from a different IP address or toolchain—MirageGate proves cryptographic provenance immediately.


Key hierarchy and 24-byte wire format

From a single master secret K_master (MinSecretBytes = 16, >= 32 random bytes recommended via MIRAGEGATE_SECRET), MirageGate derives four domain-separated subkeys using HMAC-SHA256:

K_breadcrumb = HMAC-SHA256(K_master, "miragegate:v1:breadcrumb")
K_labyrinth  = HMAC-SHA256(K_master, "miragegate:v1:labyrinth")
K_jwt        = HMAC-SHA256(K_master, "miragegate:v1:honey-jwt")
K_session    = HMAC-SHA256(K_master, "miragegate:v1:session-id")
  • Session ID (uint64): First 8 bytes (big-endian) of HMAC-SHA256(K_session, len32(ip)||ip||len32(ua)||ua), formatted as 16 lowercase hex characters.
  • 24-byte binary breadcrumb envelope (encoded as 32-character base64.RawURLEncoding, ProtocolVersion = 1):
Byte offset Size Field Description
0 1 B Version Protocol version (0x01)
1 1 B Kind 1=shadow_route, 2=api_key, 3=honey_jwt, 4=tenant_scope, 5=cursor
2..9 8 B SessionID Big-endian uint64 origin session identifier
10..13 4 B IssuedAt Big-endian uint32 Unix timestamp (seconds)
14 1 B Depth Labyrinth depth (0..255) at minting time
15 1 B Flags TriggerFlags bitmask (canary_route, tampered_jwt, graphql_introspection, waf_shunt, idor_velocity, breadcrumb_reuse)
16..23 8 B MAC Truncated HMAC-SHA256(K_breadcrumb, buf[0:16])[:8], verified in constant time (hmac.Equal, 2^-64 forgery bound)

Five format-preserving breadcrumb surfaces

Kind (id) Wire surface format Where InspectRequest extracts it
shadow_route (1) <prefix>-<32-char-token> (e.g. /v2-internal/ops-<tok>, /v2-internal/auth/exchange-<tok>, /v2-internal/vault/export-<tok>) r.URL.Path (supports optional extensions like .json)
api_key (2) <api_key_prefix><32-char-token> (default mg_live_<tok>) Authorization, X-API-Key, ?api_key=, ?token=
honey_jwt (3) RFC 7519 HS256 JWT signed with K_jwt; carries iss, aud, sub (svc-staging-exporter), role, scope, iat, exp (+4h), and jti: <32-char-token> Authorization: Bearer ..., ?token= (verifies HS256 signature, iss/aud, AND inner jti MAC with Kind == KindHoneyJWT)
tenant_scope (4) org_<32-char-token> X-Tenant-Scope, ?scope=
cursor (5) cur_<32-char-token> ?cursor=, ?page_token=

Anti-DoS bounds: InspectRequest caps artifact scanning at 2048 bytes (4096 for raw query), at most 4 values per header/query parameter, and 16 MAC verifications per VerifyAny call.


Stateful & stateless handoff attribution (internal/session/store.go)

When a valid breadcrumb arrives at Stage 1, CheckAndRecordHandoff evaluates provenance:

  1. Stateful match (origin session in memory):
    • Compares presenting (clientIP, userAgent) against the origin session's (OriginIP, OriginUA).
    • If neither changed, the same attacker is simply continuing its labyrinth session (no false handoff alert).
    • If IP diverged (ip_divergence(...)) and/or User-Agent diverged (user_agent_divergence(...)), MirageGate computes exact time_to_handoff_sec = now - breadcrumb.IssuedAt, increments sess.HandoffCount, stores a critical HandoffAlert (mg-handoff-XXXX), and invokes all OnHandoffAlert hooks.
  2. Stateless match (cross-node, post-restart, or TTL-expired session):
    • Because the 24-byte envelope embeds SessionID, IssuedAt, Depth, and Flags directly under K_breadcrumb, verification still succeeds with zero database lookups, emitting a critical HandoffAlert with stateless_verified: true, origin_ip: "unknown (stateless/prior-node)", and divergence_reasons: ["stateless_cross_node_or_post_restart_reuse"].

Offline verification is always available via CLI or Admin Console:

MIRAGEGATE_SECRET="<your-secret>" ./bin/miragegate inspect --json "<artifact>"

ECS v8.11.0 SIEM alert format (internal/report/ecs.go)

ECSWriter appends one JSON line per HandoffAlert (0600 file perms, 0750 parent directories):

{
  "@timestamp": "2026-11-28T17:18:42Z",
  "ecs": { "version": "8.11.0" },
  "event": {
    "id": "mg-handoff-0001",
    "kind": "alert",
    "category": ["intrusion_detection", "authentication"],
    "type": ["indicator", "access"],
    "action": "handoff_attribution",
    "severity": 95,
    "risk_score": 95,
    "module": "miragegate",
    "dataset": "miragegate.handoff"
  },
  "source": { "ip": "198.51.100.77" },
  "user_agent": { "original": "curl/8.7.1" },
  "http": { "request": { "method": "GET" } },
  "url": { "path": "/v2-internal/vault/export-..." },
  "related": { "ip": ["198.51.100.77", "203.0.113.42"] },
  "message": "...",
  "miragegate": {
    "alert_id": "mg-handoff-0001",
    "severity": "critical",
    "origin_session_hex": "...",
    "origin_ip": "203.0.113.42",
    "origin_ua": "...",
    "origin_trigger": "canary_route",
    "origin_turns": 36,
    "breadcrumb_kind": "honey_jwt",
    "breadcrumb_source": "header:Authorization",
    "breadcrumb_depth": 3,
    "time_to_handoff_sec": 1122.0,
    "divergence_reasons": ["ip_divergence(...)", "user_agent_divergence(...)"],
    "stateless_verified": true,
    "verification_algorithm": "HMAC-SHA256"
  }
}

Security boundaries and operational hardening

  • Strictly defensive: Inbound L7 proxy only—no outbound probing, hack-back, client-side code execution, or prompt-injection payloads.
  • Secret management: Supply >= 32 random bytes via MIRAGEGATE_SECRET (crypto.secret_env) in production. If omitted in serve, an ephemeral 32-byte key is generated (breaking post-restart stateless verification). Rotating MIRAGEGATE_SECRET invalidates prior breadcrumbs (multi-key rings are not yet implemented).
  • TLS termination: miragegate serve speaks plain HTTP; terminate TLS at an edge proxy/CDN and list its CIDRs in server.trusted_proxies so X-Forwarded-For, X-Real-IP, bypass_header, and waf_shunt_header cannot be spoofed.
  • Admin Console isolation: Unauthenticated; bind strictly to loopback (127.0.0.1:8081) or place behind authenticated private networking. All console routes enforce loopback Host header validation (localhost, 127.0.0.1, ::1), strict CSP, and pure DOM rendering (zero innerHTML).