Http Security

policy

Embeds the Policy Engine to enforce identity checks and APL rules, exchange tokens, redact fields, track session taint, and emit audit events.

Praxis v0.8.0 14 min read
On this page

Embeds the Praxis Policy Engine in-process to enforce multi-source identity, APL route policy, RFC 8693 token exchange, field redaction, session taint, audit emission, and (under body_access: read_write) request / response body rewriting. Content scanning is a host plugin the engine dispatches, not a bundled one.

Requires Cargo feature: policy-engine.

Configuration Notes

Registered under the YAML filter name policy. The default build selects policy-builtins, which registers every Policy builtin plugin kind, including the experimental ratelimit/limitador. A narrower build names policy-engine or individual policy-* builtins plus one crypto backend; a policy naming a plugin kind the build did not compile in fails to load. --no-default-features leaves the filter out.

A single request can carry multiple identity sources — user JWT in Authorization, agent JWT in X-Agent-Token, workload JWT in X-Workload-Token, etc. Each registered identity plugin reads its own configured header and contributes to a typed Extensions context.

On the body phase, the filter consumes protocol classifier filter metadata (from the praxis-ai package) to dispatch the matching CMF hook chain. APL routes (declared in the policy document) gate the tool/prompt/resource call by role, attribute, or Cedar PDP decision. delegate(...) steps mint audience-scoped tokens (RFC 8693) that the allow path attaches as upstream headers.

Policies with llm: routes authorize the top-level request model through cmf.llm_input, without classifier metadata. Missing, unlisted, and ambiguous models fail closed by default.

OPA, CEL, and Cedar pre_invocation steps on llm: routes also read the parsed request body as llm.request (input.llm.request in OPA, context.llm.request in Cedar), so a rule can inspect tools, messages, or input. Only a request attributed to a model carries it: a JSON body with a usable top-level model, no JSON-RPC envelope, and no mcp.method metadata. Other requests carry none. CEL and Cedar deny when a rule reads it, and so does an OPA boolean or object decision, but an OPA deny set needs its own guard. On allow the upstream receives the original bytes. A body over llm.max_request_bytes receives HTTP 413 before any authorization rule runs. Policy judges the body as it reaches this filter, so order body-rewriting filters before policy. For rule syntax, engine types, and absent-value behavior, see Structured request input in the policy engine docs.

Chat Completions and Anthropic Messages requests also expose normalized llm.input.* facts for instructions, offered tools, tool choice, completion limits, sampling and stop sequences. Unsupported shapes, unknown fields and malformed values leave these facts absent; rules that require them should deny their absence. See the normalized LLM input example.

PPE 0.4.1 changes OPA and CEL args on tool: routes to native JSON. Before upgrading, review rules that read args: for example, a numeric ID in args.ids must be compared with 13, not "13". A schema-backed cedar-direct PDP must set structured_context: true or the policy fails to load. Its schema must also declare the optional args and llm context fields its actions can receive, or those requests are denied. See the PPE 0.4.1 changelog and args migration guidance.

PPE 0.5.0 tightens OAuth delegate(...) by default. A token-exchange response must name an access-token or JWT issued_token_type. When the step requests scopes, a granted scope that was neither requested nor listed in allowed_extra_scopes is refused; a step that requests none accepts the identity provider’s defaults. When the minted token is a JWT, its aud must contain the step’s audience, and on a token exchange its sub must match the caller. strict_response_validation: false turns these checks off. A JWT with an unsupported crit header is rejected, and an env secret provider with settings it does not use fails to load. CEL size() now counts code points rather than bytes, and exists() returns true when one element matches even if another errors, so some requests that were denied may now be allowed. See the PPE 0.5.0 changelog.

Every hook sees the downstream request as this filter first received it: method, path, raw query, the validated host lowercased without a port, the effective client address, and headers. Trusted reserved-prefix and context_headers updates remain visible to later hooks. The scheme is https only when the downstream connection is TLS; X-Forwarded-Proto is never trusted. Place policy before path_rewrite, url_rewrite and header-rewriting filters so the request it authorizes is the one the client sent. A DPoP issuer must set dpop.external_base_url, so a proof’s htu is never checked against the client-sent Host.

http.client_address is the TCP peer, without a port. When the peer is in trusted_proxies, it is the rightmost X-Forwarded-For hop outside those ranges instead, or the leftmost hop when every hop is trusted; hops left of the client are ignored; a malformed hop reached before it leaves no client address. RFC 7239 Forwarded is not supported. Only policy input changes: ip_acl and forwarded_headers still see the peer.

A policy with rate_limits: runs ratelimit.pre_identity once per request before the first identity resolution, on the HTTP coordinates (http, *) and the request as first received, and ratelimit.post_identity once after the last, on the final route and the resolved identity, before authorization and forwarding. Two policy filters in one chain each run both stages. A denial ends the request with its declared status (429, 400, 401 or 503), fixed text per code, and only the limit, remaining, retry_after_seconds and window_seconds details; a positive retry_after_seconds sets Retry-After. The plugin’s reason is never sent. On a classified JSON-RPC call the body is a JSON-RPC error carrying the request id, under the same status. Counters belong to each limiter instance: they are not shared between replicas and reset when the configuration reloads. Each IPv6 /64 is one address key, so pair a per-address limit with a coarser one.

Policy can read a credential from a query parameter (credential: { kind: query_param, name: ... }, with the read_query capability). The filter does not rewrite the URL, so the parameter reaches the upstream, and access logs, CDN logs and browser history outside Policy can record it. A policy that combines a query credential with delegate(...) fails to load. At request time, a delegated token is never forwarded while an inbound credential sits where the filter cannot strip it; that request receives HTTP 500 (policy.unstrippable_credential). A delegation none of whose tokens forms a valid upstream header receives HTTP 500 (policy.delegation_failed) rather than forwarding the inbound one.

The filter registers only the env secret provider. A secrets: block naming any other provider kind, including file, fails to load. Secret values are read when the filter is built, so a changed value takes effect on the next restart.

The configured policy receives the full parsed inference request. Treat policy documents and custom plugins as trusted: a rule or an explicit outbound call can disclose fields it reads. Review policy authorship and outbound endpoints before enabling structured request input.

On a policy with llm: routes, a bodyless request (a GET, HEAD, OPTIONS, TRACE or CONNECT with no body), such as GET /v1/models, runs the policy’s HTTP authorization, delegation and request assertions before it is admitted: a matching http: route, the global rules otherwise. It carries no inference request, so a global rule that reads llm.request denies it; keep such rules in llm: routes or global.defaults.llm. A policy with neither HTTP rules nor request assertions admits it on identity. A body with no usable model under llm.require_model: false runs the same HTTP admission after parsing and classification checks. MCP-only policies with require_protocol_metadata: false still admit unclassified requests on identity alone and warn when HTTP rules or request assertions exist. Classified non-entity MCP methods also retain their identity-only admission.

On a policy with llm: routes, any request body without mcp.method metadata that repeats a key within one JSON object, at any depth, including keys that differ only in case, receives HTTP 400 with violation code llm.duplicate_key before any authorization rule runs, since backends disagree on which copy wins. This covers bodies with no model and unclaimed JSON-RPC envelopes too. The response names neither the key nor any value. A body that is not valid JSON is not refused for being malformed: it carries no usable model, so it is handled like any other body without one.

A lone differently cased field such as Tools is not a duplicate. llm.request keeps the wire spelling, so a rule checking only tools will not see Tools. If an upstream accepts such aliases, cover them explicitly in policy or require canonical field spelling at its boundary.

The CMF prompt text that APL steps and scanners read is projected from system, Responses instructions, messages[].content, legacy prompt, and input. For Responses and embeddings input, only text counts: a string, string items, and input_text, text, output_text, reasoning_text, or summary_text parts. Message items contribute their content. Every other item type, including tool calls, tool outputs, and reasoning, contributes its arguments, input, output, text, content, and summary. File search result text, code interpreter code and output logs, and listed MCP tool description are also projected. Token-ID arrays, images, and files are skipped.

body_access: read_write enables the JSON-RPC re-serialization round-trip so APL field mutators (redact(), assign()) rewrite the upstream request body and the downstream response. It also enables cmf.llm_output for non-streaming inference responses. APL field mutators do not rewrite inference bodies.

body_access: read_write also enables response-phase tool:, prompt:, and resource: rules, including attribute-only post_invocation rules. Under read_only, these rules are skipped and a warning is emitted. A response-only route adds no request-phase route rule; identity checks and global policy still apply. When tool response hooks are configured, a nonempty classified tools/call response that is malformed or contains neither a result nor a valid JSON-RPC error produces a filter error instead of silently skipping inspection. The pipeline’s failure_mode controls that error; valid JSON-RPC error responses continue unchanged.

result.<field> projection for prompt: and resource: routes remains blocked on policy #75; host-side content projection is tracked in Praxis #1330. A result: field pipeline on either entity, including an inherited one, is rejected at load so its controls cannot be silently skipped.

Policies with MCP entity routes cannot declare authorization: on an http: route. Use global for shared authorization; route-scoped authentication: remains supported.

Response-body hooks run on a small dedicated runtime while the worker waits, for at most twice the engine’s per-plugin timeout (engine_settings.plugin_timeout, so 60 seconds by default). A hook that does not finish in time is aborted and the response fails under the filter’s failure_mode: closed truncates the response, open passes the body through unfiltered.

Outbound policy calls share the proxy’s sub-request limits and circuit breaker, use HTTP/1.1, and keep a separate 1 MiB response ceiling. Calls made by response-body hooks use their own pool on the dispatch runtime, with the same connection limit but no circuit breaker. TLS uses the platform trust store; cluster private CAs and client certificates do not apply. A private destination requires trusted_private_endpoints for a specific host, or allow_private_idp to relax every callout.

An endpoint URL may name an IP address over http, but not over https: an IP carries no SNI, and Pingora peers skip certificate verification entirely when SNI is empty. Use a hostname for https.

Praxis filter configs are flat: the filter’s typed fields sit directly under the - filter: entry alongside the structural keys (name, conditions), not nested under a config: wrapper. See examples/configs/security/policy.yaml for a runnable example.

The referenced YAML is the policy document — plugins, routes, and identity-source declarations. The filter loads it once at construction and rejects misconfigured policy at server startup (fail-fast rather than at first request).

Configuration

FieldTypeRequiredDescription
body_accessread_only | read_writenoBody-access tier. ReadOnly (default) lets APL inspect request and response bodies for routing / policy decisions but discards any mutations. ReadWrite enables the CMF → JSON-RPC re-serialization round-trip so APL field mutators (e.g. args.ssn: redact(!perm.view_ssn)) rewrite the upstream body and response. Pay the round-trip cost only when needed.
config_pathstringyesFilesystem path to the policy document.
init_timeout_secsintegernoMaximum time, in seconds, to wait for PolicyEngine::initialize at filter construction. Identity plugins fetch JWKS over HTTPS during init; a reachable-but-unresponsive identity provider would otherwise hang startup or hot-reload indefinitely. On expiry, filter construction returns an error and the server fails fast. 30s is generous for legitimate cold-cache JWKS fetches over the public internet, while short enough that misbehavior is noticed during the deploy.
max_buffer_bytesintegernoMaximum request or response body size in ReadWrite mode. Also used as the default inference request limit.
allow_private_idpboolnoPermit every policy endpoint a private or loopback address. By default, private DNS answers are skipped and calls with no public answer are rejected, so a private destination needs one of two opt-ins: trusted_private_endpoints to relax a specific host to the RFC 1918 and unique-local ranges, or this flag to relax every callout globally. Proxy upstreams use cluster trusted_private_endpoints or allow_private_upstreams.
trusted_private_endpointsstring[]noHosts the policy engine may reach at a private address. Narrower than allow_private_idp. Only a callout whose host matches an entry reaches a non-public address, and only the RFC 1918 and unique-local (fc00::/7) ranges an in-cluster endpoint resolves to. A listed host still cannot reach loopback, link-local (including cloud metadata), the unspecified address, or any other reserved range. Every unlisted callout stays public-only. Matched on the URL host, case-insensitive, port excluded. An IPv6 address is a bracketed literal such as [fc00::1]. Shared address space (100.64.0.0/10) is deliberately not relaxable, so a pinned endpoint on a cluster that assigns pod addresses there, such as EKS with the VPC CNI secondary-CIDR pattern, is not reachable by a pin. Relaxing that range would need a separate per-host opt-in, off by default.
trusted_proxiesstring[]noCIDR ranges of proxies trusted to report the client in X-Forwarded-For. Empty by default, so http.client_address is the TCP peer. When the peer is in a listed range, the field lines are joined and walked right to left, and the first hop outside every range is the client; when every hop is trusted, the leftmost is. Hops left of the client are ignored; a malformed hop reached before it leaves the request with no client address. Ports are dropped. RFC 7239 Forwarded is not read. This changes only what the policy engine sees; IP ACLs and upstream headers still use the TCP peer.
require_protocol_metadataboolnoFail-closed policy gate for misconfigured chains. When true (default), on_request_body rejects any request that reaches it without mcp.method filter-metadata. The metadata is set by the protocol classifier filter (available in the praxis-ai package), so its absence means either (a) the protocol classifier filter is missing from the chain, or (b) it is ordered AFTER policy instead of before. Either is a misconfiguration that would silently bypass CMF/APL policy. Set to false only when intentionally fronting non-classified traffic through the policy filter for identity-only enforcement (legacy behavior). Only applies to policies with MCP entity routes. Inference routes use their own gates instead. JSON-RPC methods that legitimately carry no entity (e.g. tools/list, initialize, prompts/list) still pass; require_protocol_metadata only rejects when the metadata is missing entirely.
llmLlmOptionsnoInference authorization options.
llm.max_request_bytesintegernoMaximum buffered inference request size, in bytes. Requests over this limit receive HTTP 413.
llm.promote_paramsstring[]noTop-level scalar fields promoted to custom.llm.<name>. A configured list replaces the defaults.
llm.providerstringnoOperator-supplied provider recorded on llm.provider.
llm.require_modelboolnoDeny a request whose body carries no usable top-level model. Enabled by default. When disabled, an accepted unclassified request without a model runs HTTP authorization, delegation and assertions. Parsing and MCP classification checks still apply.
llm.require_routeboolnoDeny a model no llm: route selects. Enabled by default. Disable only to admit unlisted models.
context_headersobject<agent.conversation_id | agent.turn | agent.agent_id | agent.parent_agent_id | agent.input | framework.framework | framework.framework_version | framework.node_id | framework.graph_id, string>noMaps extension field names to HTTP header names for populating host-supplied agent.* and framework.* context slots. The accepted keys are agent.conversation_id, agent.turn, agent.agent_id, agent.parent_agent_id, agent.input, framework.framework, framework.framework_version, framework.node_id, and framework.graph_id. Only headers with a reserved prefix (x-praxis-*, x-ext-agent-*, or x-ext-protocol-*) are accepted — this guarantees the value was set by a trusted gateway filter, not spoofed by the client (Praxis ingress strips reserved-prefix headers from client requests with a 400 reject). agent.session_id keeps its dedicated X-Session-Id handling and must not appear in this map. An absent or empty header leaves the extension field unset. A slot with no populated fields is left None on Extensions.
context_metaContextMetaConfignoStatic operator-supplied metadata for the meta extension slot. These values are per-deployment (not per-request) and populate meta.tags, meta.scope, and meta.properties on every request processed by this filter instance. Important: the PPE uses meta.scope for route resolution. Setting it here can change which policy route a request resolves to, not just what the audit record says.
context_meta.tagsstring[]noOperational tags; the only source of meta.tags in rules. A route’s own meta.tags are not merged in, and these do not join groups: bundles.
context_meta.scopestringnoHost-defined grouping (virtual server ID, namespace, etc.). Caution: PPE scores route resolution on meta.scope, so setting it here changes which policy route a request resolves to, not just what the audit record says.
context_meta.propertiesobject<string, string>noArbitrary key-value metadata, available as meta.properties.<key> in APL predicates.

Example

filter: policy
config_path: /etc/praxis/policy.yaml
body_access: read_write       # optional; default read_only
require_protocol_metadata: true    # optional; default true
init_timeout_secs: 30         # optional; default 30
max_buffer_bytes: 10485760
llm:
  require_model: true
  require_route: true
  provider: openai