Skip to the content.

WASM extensibility: custom admission gates

The proxy’s admission pipeline is rich but fixed — vulnerability/OSV scanning, VEX adjudication, license compliance, secret detection, signature/attestation verification, nameguard, the composite risk score, and the policy-as-code engine. Enterprises frequently need org-specific gate logic on top of these — custom naming rules, internal CMDB/inventory lookups, bespoke metadata checks — that does not belong in the proxy core and must not require forking it.

The extension subsystem (internal/extension) loads operator-supplied WebAssembly modules and runs them as an additional, late-stage admission gate. A module receives a serialized, read-only view of the request’s admission context and returns a structured verdict (allow / warn / block + reason + annotations). Modules run in a pure-Go WebAssembly interpreter (wazero — no cgo, no native codegen, air-gap friendly) under strict CPU/memory/time/fuel limits with no host filesystem or network access by default.

Like the policy and risk gates, an extension gate composes with the hard-coded gates: it can turn an otherwise-allowed artifact into a warn or block, but it is never consulted to re-admit something an earlier gate already refused.

Where it runs

The extension gate is the final admission stage, after the policy-as-code and risk-scoring gates:

nameguard → malfeed → sigverify → vulnscan → license → policyengine → riskscore → EXTENSIONS → serve

By the time a module runs, every other gate’s signals (and the composite risk score) are already populated, so a module sees the full picture.

Configuration

extensions:
  enabled: true                    # on by default, but inert until modules exist
  defaults:                        # limit defaults for modules that omit a bound
    timeoutMs:      250            # per-invocation wall-clock CPU/time budget
    memoryBytes:    67108864       # linear-memory cap (64 MiB), rounded to 64KiB pages
    fuel:           0              # function-call budget; 0 disables fuel metering
    maxOutputBytes: 65536          # cap on the verdict bytes read back
  modules:
    - name: org-naming-policy      # stable id (metrics label, audit, admin, selection)
      path: /etc/pullthrough/gates/naming.wasm
      failClosed: false            # see "Failure policy" below
      tenants: [payments]          # restrict to these teams; omit ⇒ all tenants
      limits:                      # per-module overrides of `defaults`
        timeoutMs: 100
        fuel: 5000000

Failure policy (fail-open vs fail-closed)

A module can fail to produce a verdict: it can time out, exhaust its fuel budget, trap, or return a malformed verdict; or it can fail to compile at startup. Each module’s failClosed setting resolves these terminal outcomes:

When several modules run, the most severe decision wins (block > warn > allow), so any module can block and any can warn.

Resource limits

Every invocation runs under three independent bounds:

Bound Config Mechanism Metric on breach
CPU / wall-clock time timeoutMs a context deadline that closes a runaway module mid-execution …_timeouts_total
Linear memory memoryBytes a hard page cap on the module’s memory (contained; surfaces as timeout/error)
Fuel (instructions) fuel a function-call meter that aborts deep recursion / call-count explosions deterministically, independent of wall-clock time …_fuel_exhausted_total

Fuel metering is off by default (fuel: 0) because it adds per-call overhead; enable it for an extra, time-independent bound against pathological recursion. The memory page cap and the time budget are always in force.

Note on the wazero backend. wazero is a pure-Go interpreter with no native instruction “fuel” register, so CPU is bounded by time and memory by a page cap. The fuel budget here meters guest function calls (via wazero’s function-listener facility), which catches recursion/call-count explosions that a tight in-function loop would not — that case is caught by the wall-clock timeout instead. The two budgets are complementary.

Metrics

Per module, labeled by module (and decision for verdicts):

Every block/warn is also recorded in the tamper-evident audit log (policy_decision event, reason extension:<module>) and emitted as a notification (extension event type, severity high for block / medium for warn). The admin UI Extensions tab shows per-module load state, limits, and counters, with a reload button.

Response headers

On the served (or blocked) response the gate sets:

A block returns 403 with a JSON body (code: "extension") carrying the module, reason, annotations, and per-module breakdown.


The host ABI (v1)

The wire contract between the host and a module is small, explicit, and versioned (ABIVersion = 1). A module compiled against a future ABI is refused at load rather than misbehaving per-call.

Required exports

A module must export a linear memory named memory and:

(func (export "pt_abi_version") (result i32))        ;; returns the ABI version it implements
(func (export "pt_alloc") (param i32) (result i32))  ;; allocate N bytes, return offset (0 on failure)
(func (export "pt_eval")  (param i32 i32) (result i64));; evaluate input at [ptr,ptr+len), return packed result

It may export:

(func (export "pt_free") (param i32))                ;; release a pt_alloc'd buffer (best-effort)

Call sequence (per invocation)

  1. The host calls pt_alloc(len) to get an offset, writes the host input JSON there, and calls pt_eval(ptr, len).
  2. pt_eval returns a packed i64: the high 32 bits are the offset of the verdict JSON in linear memory, the low 32 bits are its length. Returning 0 signals an internal module error.
  3. The host reads and parses the verdict, then best-effort calls pt_free.

The host instantiates a fresh module instance per invocation, so a module carries no state between requests — every pull sees clean linear memory.

Host input document

{
  "abiVersion": 1,
  "module": "org-naming-policy",
  "signals": {
    "tenant": "payments",
    "artifact": { "ecosystem": "npm", "backend": "npm-public",
                  "name": "@acme/widgets", "version": "1.2.3", "digest": "sha256:…" },
    "vuln":      { "scanned": true, "criticalCount": 0, "maxSeverity": "high", "...": "..." },
    "license":   { "evaluated": true, "code": "ok", "...": "..." },
    "signature": { "checked": true, "verified": true, "...": "..." },
    "secret":    { "scanned": true, "findingCount": 0 },
    "nameguard": { "scanned": true, "typosquat": false },
    "provenance":{ "found": true, "confidence": "attested" }
  },
  "risk": { "score": 42, "band": "medium", "action": "off" }
}

signals is the proxy’s canonical admission document (the same structure the policy-as-code engine evaluates — see internal/policyengine.Input). Optional sections are present only when the corresponding gate ran. risk is present when the risk engine ran upstream.

Verdict document

{
  "decision": "block",
  "reason": "internal-namespace package served from a non-org backend",
  "annotations": { "rule": "dependency-confusion", "backend": "npm-public" }
}

decision must be allow, warn, or block. The host enforces bounds on the verdict: reason ≤ 2 KiB, ≤ 32 annotations, annotation keys ≤ 128 bytes and values ≤ 1 KiB, and the whole verdict ≤ maxOutputBytes. A verdict that violates the ABI is treated as a module error (resolved by the fail policy).

Writing a module

Go (no extra toolchain — uses the standard Go ≥ 1.24 compiler)

The reference sample lives at internal/extension/testdata/src/sample_gate/ and demonstrates a dependency-confusion guard, a risk-band escalation, and typosquat awareness. The key shape:

package main

import (
    "encoding/json"
    "unsafe"
)

var pinned = map[uint32][]byte{} // keep allocations alive across the host's writes/reads

//go:wasmexport pt_abi_version
func ptABIVersion() int32 { return 1 }

//go:wasmexport pt_alloc
func ptAlloc(n int32) int32 {
    b := make([]byte, n)
    p := uint32(uintptr(unsafe.Pointer(&b[0])))
    pinned[p] = b
    return int32(p)
}

//go:wasmexport pt_free
func ptFree(p int32) { delete(pinned, uint32(p)) }

//go:wasmexport pt_eval
func ptEval(ptr, n int32) int64 {
    var doc struct {
        Signals struct {
            Artifact struct{ Name, Backend string } `json:"artifact"`
        } `json:"signals"`
    }
    _ = json.Unmarshal(pinned[uint32(ptr)][:n], &doc)
    out := []byte(`{"decision":"allow"}`)
    // ... decide, then return the packed (offset<<32 | len) of the verdict bytes.
    p := ptAlloc(int32(len(out)))
    copy(pinned[uint32(p)], out)
    return (int64(uint32(p)) << 32) | int64(uint32(len(out)))
}

func main() {}

Build it (Go ≥ 1.24, which supports //go:wasmexport and the wasip1 reactor build mode):

GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o naming.wasm .

The repo’s make extension-fixtures (or internal/extension/testdata/build.sh) rebuilds the bundled Go fixtures.

Rust / other languages

Any language that compiles to a WebAssembly module exporting the ABI works. A zero-import (e.g. wasm32-unknown-unknown) module needs no WASI at all; the host instantiates a sealed WASI surface (no preopens, no stdio, no sockets) only so language runtimes that import it can initialize. Implement pt_abi_version/pt_alloc/pt_eval (and optionally pt_free), export memory, and follow the call sequence above.


Threat model

Extension modules are operator-supplied but treated as untrusted code. The design assumes a module may be buggy, malicious, or adversarially crafted (including by an attacker who compromised the build pipeline that produced it), and contains the blast radius accordingly.

Isolation

Resource exhaustion

Failure containment

Input integrity

Residual risk / operator responsibilities