Repository navigation
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.
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) ofHMAC-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) |
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.
When a valid breadcrumb arrives at Stage 1, CheckAndRecordHandoff evaluates provenance:
-
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 exacttime_to_handoff_sec = now - breadcrumb.IssuedAt, incrementssess.HandoffCount, stores a criticalHandoffAlert(mg-handoff-XXXX), and invokes allOnHandoffAlerthooks.
- Compares presenting
-
Stateless match (cross-node, post-restart, or TTL-expired session):
- Because the 24-byte envelope embeds
SessionID,IssuedAt,Depth, andFlagsdirectly underK_breadcrumb, verification still succeeds with zero database lookups, emitting a criticalHandoffAlertwithstateless_verified: true,origin_ip: "unknown (stateless/prior-node)", anddivergence_reasons: ["stateless_cross_node_or_post_restart_reuse"].
- Because the 24-byte envelope embeds
Offline verification is always available via CLI or Admin Console:
MIRAGEGATE_SECRET="<your-secret>" ./bin/miragegate inspect --json "<artifact>"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"
}
}- Strictly defensive: Inbound L7 proxy only—no outbound probing, hack-back, client-side code execution, or prompt-injection payloads.
-
Secret management: Supply
>= 32random bytes viaMIRAGEGATE_SECRET(crypto.secret_env) in production. If omitted inserve, an ephemeral 32-byte key is generated (breaking post-restart stateless verification). RotatingMIRAGEGATE_SECRETinvalidates prior breadcrumbs (multi-key rings are not yet implemented). -
TLS termination:
miragegate servespeaks plain HTTP; terminate TLS at an edge proxy/CDN and list its CIDRs inserver.trusted_proxiessoX-Forwarded-For,X-Real-IP,bypass_header, andwaf_shunt_headercannot 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 loopbackHostheader validation (localhost,127.0.0.1,::1), strict CSP, and pure DOM rendering (zeroinnerHTML).