Skip to main content

Injection

Kilimanjaro applies four independent guards against query-layer injection in request order. A request blocked by any layer never reaches the next. Each layer operates without trust assumptions about the previous one — the platform does not assume that a prior layer's check was performed or succeeded.

Caller → [Layer 1: SDK] → HTTP → [Layer 2: Edge] → [Layer 3: Origin] → [Layer 4: DB / RLS]

A request that passes all four layers produces no rejection log entry. Requests blocked at any layer produce a rejection log entry tagged with the layer that fired.

CallerLayer 1: SDKno SQL assemblyLayer 2: EdgeAST rulesetLayer 3: Originre-parse payloadLayer 4: DBRLS in Postgresblocked, flaggedblockedRLS-blockedRejection logK9O_INJECTION_DETECTED (400)Audit loglayer: db
Four guards act in request order; Edge and Origin rejections land in the rejection log, while DB-layer RLS blocks are access-control events recorded in the audit log.

1. Layer 1 — SDK​

The SDK is the first guard, and it works by construction rather than by inspection. The query builder never assembles SQL text: filters, limits and cursors travel as separate request parameters, and the SDK never concatenates a caller-supplied value into a query string. A value that is meant as data cannot become part of a statement at the source.

Anything that does reach the gateway carrying an injection pattern is caught at the next layers, and rejected with the wire error code K9O_INJECTION_DETECTED (HTTP 400). SDKs surface it as a KError whose code is K9O_INJECTION_DETECTED.

2. Layer 2 — Edge​

The edge layer is a tree-sitter parser co-located with the API gateway. There is no third-party WAF dependency — the platform is self-hosted and the edge sidecar is the platform's own.

When an API request carries a query payload (raw SQL, JSON-policy filter expression, or full-text / vector search query), the edge sidecar parses the payload using the relevant grammar and traverses the resulting AST against an injection ruleset. Each rule carries a disposition:

DispositionEffect
blockedThe request is rejected with K9O_INJECTION_DETECTED (HTTP 400). A rejection log entry is written with layer: "edge".
flaggedThe request is allowed to proceed. A rejection log entry is written with disposition: "flagged" for forensic review.

The edge layer is bounded by a latency budget: parsing and rule evaluation must add less than 5ms at p99 for payloads under 64KB.

3. Layer 3 — Origin​

The origin layer re-parses the query payload using the authoritative parser (the edge sidecar may run a slightly different grammar version; the origin layer is the ground truth). It applies deeper inspection that the edge layer cannot do at its latency budget: multi-statement detection, nested function-call injection, schema-escape patterns (e.g., attempts to cross from your user-data schema into the project's system schema), stacked-query detection.

If a rule fires, the request is rejected with K9O_INJECTION_DETECTED (HTTP 400) and a rejection log entry is written with layer: "origin". The origin layer is the last software guard before the query reaches Postgres.

4. Layer 4 — DB / RLS​

The database layer is structural, not heuristic. Row-level security (RLS) policies compiled from the project's JSON policy apply as mandatory WHERE conditions on every query. These conditions cannot be bypassed by query-layer manipulation — they are enforced by Postgres.

The data-plane database credential has no SUPERUSER or BYPASSRLS attribute. RLS is always active for the credential the SDK uses.

OperationRLS-blocked behaviour
SELECTEmpty result set (200 OK with data: []). Intentional — prevents information leakage about the existence of records the caller cannot access.
INSERT / UPDATE / DELETEK9O_ACCESS_DENIED (HTTP 403).

DB-layer rejections write to the project's audit log (layer: "db") rather than the rejection log — they are access-control events, not injection-detection events, and belong in the auditable project record.

5. Rejection log​

Edge- and origin-layer rejections write to a system-managed rejection log. The schema:

FieldTypeNotes
timestampISO 8601Event time
layer"edge" | "origin"Which layer fired (DB-layer events write to the audit log instead)
projectIdstringThe project in whose context the request arrived
orgIdstringThe org that owns the project
requestIdstringCorrelation with the API access log
patternType"sql_injection" | "json_injection" | "header_injection" | "path_traversal"The class of pattern detected
rawPayloadstringThe payload fragment that triggered detection, truncated to 4 KB at a UTF-8 character boundary
ruleIdstringThe detection rule that fired
disposition"blocked" | "flagged""blocked" = request rejected; "flagged" = logged but allowed (heuristic match, low confidence)

Retention: 90 days hot (queryable from the Console), up to 7 years cold (downloadable via export). The 4 KB raw-payload truncation bounds storage cost while preserving the forensic fragment.

6. JSON injection​

The injection posture covers JSON payloads as well as SQL. A maliciously crafted JSON-policy fragment embedded in a request body could attempt to bypass access controls by injecting operator overrides or unsupported expressions into the policy evaluation engine.

The edge and origin layers parse JSON-policy expressions against the same grammar the policy engine uses. Patterns that introduce operator overrides, undeclared functions, or expressions that would alter the policy's authorisation outcome are caught with patternType: "json_injection".

7. Layered rejection behaviour​

ScenarioAPI responseLog destination
Injection pattern detected at edgeK9O_INJECTION_DETECTED (400)Rejection log, layer: "edge"
Pattern missed by edge; caught by originK9O_INJECTION_DETECTED (400)Rejection log, layer: "origin"
Patterns missed by layers 1–3; RLS blocks writeK9O_ACCESS_DENIED (403)Audit log, layer: "db"
Patterns missed by layers 1–3; RLS filters SELECTEmpty result set (200 OK, data: [])Audit log, layer: "db"
No injection; query proceedsNormal R-1 responseNo rejection entry

8. What this model defends against​

The four-layer posture targets query-layer injection — SQL, JSON-policy, and policy-filter expressions that attempt to alter the meaning of a request after it leaves the caller. The defence is layered: SDK at the source, edge at network ingress, origin at the application boundary, DB at the storage layer.

The model does not substitute for:

  • Application-layer authorization. RBAC and JSON policies are the access-control surface; the threat model assumes those are configured correctly. The four layers stop callers from breaking out of their granted access; they do not grant access.
  • Transport-layer guarantees. TLS, HSTS, and certificate management cover the wire — see Security §3.
  • Secret hygiene at the caller. The platform cannot defend against a leaked service_role key. Key rotation, KMS-managed storage, and short-TTL access tokens are the caller's responsibility — see Security §4.

The audit log carries forensic continuity across all four layers. Every blocked request is recoverable from the rejection log; every RLS-blocked write is recoverable from the audit log; every policy decision that altered an outcome is traceable to a requestId shared across both surfaces.