Chio/Docs

HTTP Substrate

The HTTP substrate enables Chio to protect arbitrary HTTP APIs by evaluating requests against policy, signing receipts, and returning structured verdicts. It is the foundation that all HTTP-layer SDKs, middleware crates, and sidecar deployments consume.

When to use this page

Use this page when: you are building or auditing an HTTP-layer SDK, framework middleware, or sidecar deployment and need the typed ChioHttpRequest, HttpReceipt, verdict enum, default policy, and the deterministic HttpReceipt ChioReceipt mapping. Don't use this if: you want the agent-protocol wire format (see Wire Protocol) or the cross-surface capability and receipt contract (see Protocol Reference).

Source

This page normatively reflects spec/HTTP-SUBSTRATE.md in the chio repository. Status: Normative. Version 1.0. The keywords MUST, SHOULD, and MAY are normative per RFC 2119.


Overview

The HTTP substrate uses a sidecar evaluation model: a Chio kernel runs as a local process and exposes an HTTP API on localhost. Language-specific middleware (Express, Actix, Axum, etc.) intercepts incoming HTTP requests, constructs a ChioHttpRequest, sends it to the sidecar, and enforces the returned verdict.

The substrate defines:

  • A sidecar evaluation protocol (three HTTP endpoints)
  • A typed request model (ChioHttpRequest) for policy evaluation
  • A typed receipt model (HttpReceipt) for signed proof of evaluation
  • Supporting types for caller identity, authentication, sessions, and verdicts
  • A deterministic mapping from HttpReceipt to the core ChioReceipt type

Sidecar Evaluation Protocol

Transport

The sidecar MUST listen on 127.0.0.1:9090 by default. Implementations MAY override the sidecar URL via:

  • An explicit configuration value (sidecarUrl in SDK config, or equivalent)
  • The CHIO_SIDECAR_URL environment variable

If both are set, the explicit configuration value takes precedence. If neither is set, the default http://127.0.0.1:9090 MUST be used. All request and response bodies MUST use Content-Type: application/json.

Endpoints

EndpointMethodPurpose
/chio/evaluatePOSTEvaluate an HTTP request against policy
/chio/verifyPOSTVerify a receipt signature
/chio/healthGETSidecar health check

POST /chio/evaluate

Evaluates an HTTP request against the loaded policy and returns a signed receipt.

Request body: ChioHttpRequest.

Response body: EvaluateResponse.

FieldTypeRequiredDescription
verdictVerdictMUSTThe evaluation verdict
receiptHttpReceiptMUSTSigned receipt proving the evaluation
evidenceGuardEvidence[]MUSTPer-guard evidence collected during evaluation

Status codes:

  • 200 OK. Evaluation completed (regardless of verdict). The verdict field indicates whether the request was allowed or denied.
  • 400 Bad Request. The request body is malformed or missing required fields.
  • 500 Internal Server Error. The sidecar encountered an internal error during evaluation.

200 means evaluated, not allowed

Implementations MUST return 200 for both allow and deny verdicts. The HTTP status code reflects the health of the evaluation pipeline, not the policy outcome. The policy outcome is encoded in the verdict field.

POST /chio/verify

Verifies the Ed25519 signature on a previously issued HttpReceipt.

Request body: HttpReceipt.

Response body:

FieldTypeRequiredDescription
validbooleanMUSTWhether the receipt signature is valid

A receipt with a valid signature but an expired timestamp is still valid: true from the verification endpoint's perspective. Temporal validity is the caller's responsibility.

GET /chio/health

FieldTypeRequiredDescription
statusstringMUSTOne of "healthy", "degraded", or "unhealthy"
versionstringMUSTSidecar version string

Status codes: 200 OK if healthy or degraded; 503 Service Unavailable if unhealthy.

Timeout and Failure Behavior

SDKs MUST implement a configurable timeout for sidecar calls. The default timeout SHOULD be 5000 milliseconds.

Fail-closed by default

When the sidecar is unreachable or times out, SDKs MUST default to fail-closed behavior (deny the request). SDKs MAY expose a configuration option to override this to fail-open, but fail-closed MUST be the default.

ChioHttpRequest

The protocol-agnostic HTTP request that Chio evaluates. This is the shared input type for all HTTP substrate adapters (reverse proxy, framework middleware, and sidecar alike).

FieldTypeRequiredDefaultDescription
request_idstringMUSTUnique request identifier. UUIDv7 recommended.
methodHttpMethodMUSTHTTP method of the request
route_patternstringMUSTMatched route pattern (e.g., "/pets/{petId}")
pathstringMUSTActual request path (e.g., "/pets/42")
querymap<string, string>MAY{}Query parameters
headersmap<string, string>MAY{}Selected headers. Adapters MUST NOT include raw auth credential headers.
callerCallerIdentityMUSTExtracted caller identity
body_hashstring or nullMAYnullSHA-256 hex hash of the request body. null for bodyless requests (GET, HEAD, OPTIONS).
body_lengthintegerMAY0Content-Length of the request body in bytes
session_idstring or nullMAYnullSession ID this request belongs to
capability_idstring or nullMAYnullCapability token ID presented with this request
timestampintegerMUSTUnix timestamp (seconds) when the request was received

Content Hash Computation

The content hash that binds a request to its receipt is computed as the SHA-256 hex digest of the canonical JSON (RFC 8785) of the following binding object:

json
{
  "body_hash": "<body_hash or null>",
  "method": "<HTTP method>",
  "path": "<actual path>",
  "query": { "<sorted query params>" },
  "route_pattern": "<route pattern>"
}

CallerIdentity

The identity of the caller as extracted from the HTTP request.

FieldTypeRequiredDefaultDescription
subjectstringMUSTStable identifier for the caller
auth_methodAuthMethodMUSTHow the caller authenticated
verifiedbooleanMUSTfalseWhether this identity has been cryptographically verified
tenantstring or nullMAYnullTenant or organization the caller belongs to
agent_idstring or nullMAYnullAgent identifier when the caller is an AI agent

Identity hash: the caller_identity_hash in receipts is the SHA-256 hex digest of the canonical JSON representation of the full CallerIdentity object. The same identity MUST always produce the same hash.

AuthMethod

A tagged union representing how the caller authenticated. The discriminator field is method. Variant names use snake_case.

VariantTag valueFieldsDescription
Bearer"bearer"token_hash: stringBearer token (JWT or opaque). Implementations MUST NOT store or transmit raw tokens.
ApiKey"api_key"key_name, key_hashAPI key. SHA-256 hex hash of the key value.
Cookie"cookie"cookie_name, cookie_hashSession cookie. SHA-256 hex hash of the cookie value.
MtlsCertificate"mtls_certificate"subject_dn, fingerprintmTLS client certificate. SHA-256 fingerprint.
Anonymous"anonymous"(none)No authentication was presented.
json
{ "method": "bearer", "token_hash": "a1b2c3d4e5f6..." }

SessionContext

Per-session context carried through the Chio HTTP pipeline. A session groups related requests from the same caller over a bounded time window.

FieldTypeRequiredDefaultDescription
session_idstringMUSTUnique session identifier
callerCallerIdentityMUSTAuthenticated caller for this session
created_atintegerMUSTUnix timestamp (seconds) when the session was created
expires_atinteger or nullMAYnullUnix timestamp (seconds) when the session expires
request_countintegerMAY0Number of requests evaluated in this session
bytes_readintegerMAY0Cumulative bytes read by this session
bytes_writtenintegerMAY0Cumulative bytes written by this session
delegation_depthintegerMAY0Current delegation depth. 0 means direct caller.
metadataobject or nullMAYnullExtensibility metadata

Verdict

Internally tagged with "verdict" as the tag key and snake_case variant names.

VariantTag valueFieldsDescription
Allow"allow"(none)Request is allowed. Proceed to upstream.
Deny"deny"reason, guard, http_statusRequest is denied. Default http_status is 403.
Cancel"cancel"reasonEvaluation was cancelled (e.g., timeout, circuit breaker).
Incomplete"incomplete"reasonEvaluation did not reach a terminal state.

Fail-closed semantics

When the verdict is cancel or incomplete, middleware MUST treat the request as denied. Only an explicit allow verdict permits forwarding to the upstream API.

When deserializing a deny verdict without an explicit http_status field, implementations MUST default to 403.


HttpMethod

Serialized as uppercase strings.

ValueSafeRequires Capability
"GET"YesNo
"HEAD"YesNo
"OPTIONS"YesNo
"POST"NoYes
"PUT"NoYes
"PATCH"NoYes
"DELETE"NoYes

Safe methods (GET, HEAD, OPTIONS) are considered side-effect-free by default and receive session-scoped allow verdicts. Unsafe methods (POST, PUT, PATCH, DELETE) require an explicit capability grant.

GuardEvidence

FieldTypeRequiredDescription
guard_namestringMUSTName of the guard
verdictbooleanMUSTWhether the guard passed (true) or denied (false)
detailsstring or nullMAYHuman-readable details about the guard's decision

HttpReceipt

A signed receipt proving that an HTTP request was evaluated by the Chio kernel. The receipt binds the request identity, route, method, verdict, and guard evidence under an Ed25519 signature from the kernel.

FieldTypeRequiredDefaultSignedDescription
idstringMUSTYesUnique receipt ID. UUIDv7 recommended.
request_idstringMUSTYesUnique request ID this receipt covers
route_patternstringMUSTYesMatched route pattern
methodHttpMethodMUSTYesHTTP method of the evaluated request
caller_identity_hashstringMUSTYesSHA-256 hex hash of the caller identity
session_idstring or nullMAYnullYesSession ID the request belonged to
verdictVerdictMUSTYesThe kernel's verdict
evidenceGuardEvidence[]MAY[]YesPer-guard evidence collected during evaluation
response_statusintegerMUSTYesHTTP status Chio associated with the evaluation outcome at receipt-signing time.
timestampintegerMUSTYesUnix timestamp (seconds) when the receipt was created
content_hashstringMUSTYesSHA-256 hex hash binding the request content to this receipt
policy_hashstringMUSTYesSHA-256 hex hash of the policy that was applied
capability_idstring or nullMAYnullYesCapability ID that was exercised, if any
metadataobject or nullMAYnullYesExtensibility metadata
kernel_keystringMUSTYesKernel's Ed25519 public key (64-character hex)
signaturestringMUSTNoEd25519 signature over canonical JSON of the body fields (128-character hex)

Signing

To produce a signed receipt:

  • Construct an HttpReceiptBody containing all fields from the table above except signature.
  • Serialize the body to canonical JSON (RFC 8785).
  • Sign the canonical bytes with the kernel's Ed25519 private key.
  • Attach the resulting signature to the receipt.

Verification

  • Extract the body (all fields except signature).
  • Serialize the body to canonical JSON (RFC 8785).
  • Verify the signature against the canonical bytes using the kernel_key embedded in the receipt.

Implementations SHOULD verify the receipt signature before treating receipt content as authoritative.

Cryptographic Representations

  • kernel_key: Ed25519 public key as 64-character lowercase hex (32 bytes). Pattern: ^[0-9a-f]{64}$.
  • signature: Ed25519 signature as 128-character lowercase hex (64 bytes). Pattern: ^[0-9a-f]{128}$.

HttpReceipt to ChioReceipt Mapping

The to_chio_receipt() conversion maps an HTTP-layer receipt into the core ChioReceipt type for unified storage and cross-surface querying.

Field Mapping

HttpReceipt fieldChioReceipt fieldTransformation
ididCopied directly
timestamptimestampCopied directly
capability_idcapability_idUnwrapped; defaults to empty string if null
(constant)tool_serverSet to "http"
method + route_patterntool_nameFormatted as "{method} {route_pattern}"
method, route_pattern, request_idaction.parametersJSON object
content_hashaction.parameter_hashCopied directly
verdictdecisionConverted via Verdict.to_decision()
content_hashcontent_hashRecomputed as SHA-256 of canonical JSON of ChioReceiptBody
policy_hashpolicy_hashCopied directly
evidenceevidenceCopied directly
metadatametadataCopied directly
kernel_keykernel_keyCopied directly
signaturesignatureCopied directly (see limitation below)

Verdict to Decision Mapping

Verdict variantDecision variant
allowallow
deny { reason, guard, http_status }deny { reason, guard } (http_status is dropped)
cancel { reason }cancelled { reason }
incomplete { reason }incomplete { reason }

Signature Limitation

Converted receipts and signature verification

The signature field is copied directly from the HttpReceipt to the ChioReceipt. It is not re-signed over the ChioReceiptBody. Consumers that verify ChioReceipt signatures from HTTP-origin receipts MUST be aware that standard ChioReceipt signature verification will fail for these converted receipts. The intended use is unified storage and querying.

In production deployments, the kernel SHOULD sign both HttpReceipt and ChioReceipt independently from the same evaluation, rather than relying on the conversion method.


Default Policy Semantics

The HTTP substrate defines default policy behavior based on HTTP method safety:

  • Safe methods (GET, HEAD, OPTIONS): Session-scoped allow.
  • Unsafe methods (POST, PUT, PATCH, DELETE): Deny by default. These methods require an explicit capability token presented in the X-Chio-Capability request header or via capability_id in the ChioHttpRequest.

When a route is not matched in the loaded policy, the evaluator MUST fall back to method-based default policy.


Error Handling

Sidecar Error Codes

SDKs MUST use the following error codes when communicating sidecar failures to callers:

CodeMeaning
chio_access_deniedThe request was denied by policy
chio_sidecar_unreachableThe sidecar process is not reachable
chio_evaluation_failedThe sidecar returned a non-200 status
chio_invalid_receiptReceipt verification failed
chio_timeoutThe sidecar did not respond within the timeout

Structured Error Response

When middleware denies a request, the response body SHOULD be a structured JSON object:

FieldTypeRequiredDescription
errorstringMUSTError code from the table above
messagestringMUSTHuman-readable error message
receipt_idstring or nullMAYReceipt ID for the denied evaluation
suggestionstring or nullMAYActionable suggestion for the caller

Schemas and Conformance

Versioned HTTP substrate schemas live under spec/schemas/chio-http/v1/. Schema files in that directory are the machine-readable contract for the HTTP substrate types. Implementations MUST serialize all HTTP substrate types in a form accepted by those schemas. Schema validation SHOULD be exercised against live Rust serialization, not handwritten examples alone.

FileDescribed type
http-receipt.schema.jsonHttpReceipt
chio-http-request.schema.jsonChioHttpRequest
caller-identity.schema.jsonCallerIdentity with AuthMethod
verdict.schema.jsonVerdict
evaluate-request.schema.jsonPOST /chio/evaluate request body
evaluate-response.schema.jsonPOST /chio/evaluate response body