Skip to content
Docs›The schema›How detection works
Detection · 9-kind taxonomy · cite-backed

How detection works

Your own coding-agent model reads each handler and proposes a structured controlHint; the LLM-free CLI compiles it into an enforced x-security control — but only after it verifies the finding cites a real file:line in your code.

Scope
The x-security schema expresses 17+ policy categories; the plugin's detection layer currently proposes controls in 9 of them. The rest you write by hand and the CLI still compiles.
Every rule cites file:line
A finding without an exact, byte-matching cite is dropped, not patched. The CLI re-reads the cited file and substring-matches cite.quote against the line range. There is no ?? "unknown" default, no regex backfill, no synthesized citation. An unverifiable finding becomes reviewRequired; it never becomes a rule.
/ 01section

Three passes

Each pass narrows the problem: find the routes, classify the shape, emit the policy. Anything the model can't justify drops to reviewRequired; it is never a silent best-effort.

1. Inventory + context map

The agent works on any HTTP handler it can read, framework-agnostic by default. Routes and handlers are resolved structurally, with a parallel ripgrep backstop that catches anything the structural pass missed; under-matching is the failure mode we measure. The same inventory is available deterministically via xsecurity routes.

2. Profile classification

Six profiles drive the defaults: auth-endpoint, standard-crud, file-upload, webhook-receiver, public-read-only, admin-panel. Ambiguous routes drop to reviewRequired. The agent never guesses. The agent emits only deltas from the profile base, keeping output short and review fast.

3. Per-route findings

For each route, the agent reads the handler body, model, validator, middleware, and response sites, then proposes controlHint findings validated against the v0.8 schema, or returns reviewRequired with reasons. Every finding cites file:line with a verbatim quote.

/ 02section

The 9-kind control taxonomy

Every detected control is one of these nine controlHint.kind values. The model supplies the kind plus its required fields; the compiler enforces the per-kind required set and drops an incomplete descriptor rather than fabricating a default.

FieldTypeDefaultDescription
injectionGuardsink—A body/query field flows into a sink (sql · nosql · os-command · xpath · ldap · code-eval · xss · deserialization · ai-prompt). Carries the guarded param.
authenticationgate—A sensitive route with no auth gate. Requires the caller to prove identity before the handler runs.
authorizationrule—Object/function-level access (BOLA/BFLA). Requires param + principalRef and is location-aware; see below.
denyUnknownFieldsshape—Mass-assignment / BOPLA guard: reject request bodies carrying keys the route never declared.
rateLimitthrottle—An unthrottled credential/abuse surface. Throttles per identifier over a window.
paramConstrainttightness—Structural perimeter tightness: paramType, pattern, min/max, min/maxLength on a declared field.
contentTypeallowlist—Restrict accepted request content types to an allowlist (e.g. application/json only).
responseShapeegress—Constrain the response body shape on the way out; guards over-exposed or hijackable responses.
domainAllowlistegress—SSRF / open-redirect: restrict outbound hosts a proxy/fetch route may reach to an allowlist.
/ 03section

Location-aware authorization

Object-level authorization (BOLA) only works if the policy knows where the object identifier lives in the request. A controlHint of kind authorization carries a location (one of path, query, body, or header) that the model cites and the compiler turns into request.<segment>.<param>.

FieldTypeDefaultDescription
paramstring—The request field carrying the object identifier (REQUIRED to emit).
principalRefstring—The caller-identity reference compared against the resource owner, e.g. jwt.sub (REQUIRED).
operatorenumequalsHow the resource value is compared to the principal.
locationenumpathpath · query · body · header. Defaults to path (the /resource/:id case).
Why location matters
Defaulting silently to path made query-, body-, and header-keyed ownership inexpressible, a real gap in common API patterns. Making location first-class is what lets the agent express ownership checks wherever the identifier actually lives. How much of an ownership check each gateway can enforce varies. See the gateway matrix for per-target support.
/ 04section

The verification gates

Every candidate finding passes through deterministic gates before it reaches disk as a policy. Any single failure drops it to reviewRequired. Each gate is a real x-security verb you can run by hand.

FieldTypeDefaultDescription
schemastructuralv0.8Validates against the published x-security schema. Strict: unknown fields are an error. (xsecurity verify-finding)
evidencesemantic—Every finding must cite a source file:line with a byte-matching quote. No evidence → dropped. (xsecurity verify-finding)
tightnesssemantic—Rejects loose constraints that look like protection but aren't. (xsecurity verify-finding)
consistencysemantic—Whole-route gate: composes findings and checks cross-control consistency. (xsecurity verify-route)
groundingstructural—Reconciles mount prefixes and grounds agent-claimed routes against the deterministic extractor. (xsecurity reconcile-inventory)
auditstructural—Re-validates every stored policy control and proves citation coverage; exit 2 if any control lacks a byte-matching cite. (xsecurity audit)
fidelitysemantic—Flags fields the chosen gateway cannot enforce; --strict-fidelity fails on them. (xsecurity report)
/ 05section

Deterministic, diffable output

The compile step is deterministic: same input, byte-identical output. That holds for both the policy files xsecurity compile writes and the gateway config xsecurity generate emits — so you can commit generated artifacts to git, diff them like ordinary source, and review the blast radius of a spec change with xsecurity diff.

/ 06section

Proof: how findings earn trust

Detection accuracy is the product, so every finding has to prove itself rather than be taken on faith.

Every rule cites your code

Every emitted control cites the exact file:line of the route it protects. A finding without a citation is treated as a model failure and dropped; it never reaches disk as a rule. You can verify any rule in one click.

Deterministic gate, no silent defaults

A bundled, LLM-free verifier checks every control the model emits against the real route inventory. Anything it cannot pin to your code is flagged reviewRequired for a human instead of being written as a loose rule. Loose protection that looks tight is the worst outcome.

Honest framing
We report "100% of emitted rules cite your code"; we never report "100% secure". Recall scales with the model reading your code; a scan is a verified starting point, not a clean bill of health. What the system knowingly can't do is on known limitations.
License
The x-security schema is Apache-2.0. Fork it, embed it, contribute fields back. See github.com/ZeeshanSultan/x-security.