{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "adscan.webhook_event/1",
  "title": "ADscan webhook event",
  "description": "The body of every webhook delivery. Signed with HMAC-SHA256 over the exact body bytes (header X-ADscan-Signature-256: sha256=<hex>). event_id is deterministic per fact and is repeated in the Idempotency-Key header: deduplicate on it. A field added within major 1 is optional, so a reader of an earlier 1.x keeps working. No payload ever carries a password, hash, key or ticket.",
  "type": "object",
  "required": ["schema", "schema_version", "event_id", "event", "occurred_at", "workspace", "data"],
  "properties": {
    "schema": {"const": "adscan.webhook_event/1"},
    "schema_version": {"type": "string", "pattern": "^1\\.[0-9]+$"},
    "event_id": {"type": "string", "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"},
    "event": {
      "enum": [
        "scan.started",
        "scan.completed",
        "scan.failed",
        "scan.cancelled",
        "finding.new",
        "finding.new_critical",
        "finding.remediated",
        "finding.reopened",
        "finding.status_changed",
        "attack_path.new",
        "attack_path.remediated",
        "assessment.regression",
        "domain.newly_compromised",
        "credential.new",
        "report.generated",
        "report.failed",
        "schedule.triggered",
        "test.ping"
      ]
    },
    "occurred_at": {"type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"},
    "workspace": {
      "type": "object",
      "required": ["id", "name"],
      "properties": {
        "id": {"type": ["string", "null"]},
        "name": {"type": "string"}
      }
    },
    "data": {
      "type": "object",
      "description": "Event-specific fields. Which keys appear depends on the event.",
      "properties": {
        "scan": {"oneOf": [{"$ref": "#/$defs/scan"}, {"type": "null"}]},
        "previous_scan": {"$ref": "#/$defs/scan_ref"},
        "baseline": {"type": "boolean", "description": "True on the workspace's first assessment: every open item is reported as new."},
        "reopened": {"type": "boolean"},
        "finding": {"$ref": "#/$defs/finding"},
        "previous_status": {"type": ["string", "null"]},
        "changed_by": {"type": "string"},
        "attack_path": {"$ref": "#/$defs/route"},
        "domain": {"type": "string"},
        "routes": {"type": "array", "items": {"$ref": "#/$defs/route"}},
        "domains_newly_compromised": {"type": "array", "items": {"type": "string"}},
        "new_routes_executed_end_to_end": {"type": "array", "items": {"$ref": "#/$defs/route"}},
        "routes_now_succeeding": {"type": "array", "items": {"$ref": "#/$defs/route"}},
        "counts": {
          "type": "object",
          "properties": {
            "domains_newly_compromised": {"type": "integer", "minimum": 0},
            "new_routes_executed_end_to_end": {"type": "integer", "minimum": 0},
            "routes_now_succeeding": {"type": "integer", "minimum": 0}
          }
        },
        "url": {"type": "string"},
        "credential_record": {"$ref": "#/$defs/credential_record"},
        "report": {"$ref": "#/$defs/report"},
        "schedule": {
          "type": "object",
          "required": ["id", "name"],
          "properties": {"id": {"type": "string"}, "name": {"type": "string"}}
        },
        "status_detail": {"type": "string", "description": "scan.cancelled: cancelled or stopped (resumable)."},
        "message": {"type": "string"},
        "webhook_name": {"type": "string"}
      }
    }
  },
  "$defs": {
    "scan_ref": {
      "type": "object",
      "required": ["id"],
      "properties": {
        "id": {"type": "string"},
        "completed_at": {"type": ["string", "null"]}
      }
    },
    "scan": {
      "type": "object",
      "required": ["id", "status", "url"],
      "properties": {
        "id": {"type": "string"},
        "name": {"type": ["string", "null"]},
        "status": {"type": ["string", "null"]},
        "scan_type": {"type": ["string", "null"]},
        "pentest_type": {"type": ["string", "null"]},
        "started_at": {"type": ["string", "null"]},
        "completed_at": {"type": ["string", "null"]},
        "url": {"type": ["string", "null"]}
      }
    },
    "finding": {
      "type": "object",
      "required": ["id", "title", "domain", "status", "url"],
      "properties": {
        "id": {"type": "string"},
        "finding_key": {"type": ["string", "null"]},
        "title": {"type": "string"},
        "domain": {"type": "string"},
        "severity": {"type": ["string", "null"]},
        "status": {"type": ["string", "null"]},
        "url": {"type": "string"}
      }
    },
    "route": {
      "type": "object",
      "required": ["id", "title", "domain", "evidence", "executed_end_to_end", "url"],
      "properties": {
        "id": {"type": "string"},
        "title": {"type": "string"},
        "domain": {"type": "string"},
        "execution_status": {"type": ["string", "null"]},
        "evidence": {"type": "string"},
        "executed_end_to_end": {"type": "boolean"},
        "url": {"type": "string"}
      }
    },
    "credential_record": {
      "type": "object",
      "description": "Which account and how. The secret, its hash and its masked preview are never sent.",
      "required": ["id", "principal", "domain", "change"],
      "properties": {
        "id": {"type": "string"},
        "principal": {"type": "string"},
        "domain": {"type": "string"},
        "kind": {"type": ["string", "null"]},
        "obtained_by": {"type": ["string", "null"]},
        "change": {"enum": ["new", "rotated"]}
      }
    },
    "report": {
      "type": "object",
      "required": ["id", "kind", "status", "url"],
      "properties": {
        "id": {"type": "string"},
        "kind": {"enum": ["deliverable_kit", "progress_report"]},
        "status": {"type": "string"},
        "version": {"type": ["integer", "null"]},
        "url": {"type": "string"}
      }
    }
  }
}
