
A catch URL is public. Anyone who learns it can post to it, and the signature on each request is the only thing that separates a provider’s event from a flood someone aimed at your broker. That makes the edge the first place untrusted bytes meet shared resources: a body buffer, an HMAC computation, a tenant’s quota, the store’s write path. Each one costs something, and a forged request should spend as little of them as it can.
The critical review tracks this under G7, Trust boundary: untrusted input reaches shared and unbounded resources. Its ingress fix is an ordering rule. Every check that can decide a request is refused goes before the next expensive step, and the expensive steps that remain are charged only to requests that have earned them.
This is the first of ten posts that each take one Ankusa component apart; the launch post has the overview.
The cheapest refusal comes first
The edge is Ankusa.Edge.Router, a Plug.Router under Bandit. Every POST on the listener reaches one pipeline, and the order of its steps is the design. A request leaves at the first step that can decide it, and the status code says which step that was.
With routes.enabled: true (it is off by default), the route guard runs before the pipeline. It answers 404 for a path or method that no route serves, and 403 or 404 when the client address is on the deny list, depending on routes.ip_denied_status. It fails closed: with no route snapshot loaded, nothing is admitted.
The pipeline then runs in this order (packages/ankusa/lib/ankusa/edge/router.ex):
config = Ankusa.config(instance)
max = config.max_body_bytes
declared = declared_length(conn)
with {:ok, route} <- resolve(conn, instance),
:ok <- check_content_length(conn, instance, declared, max),
{:ok, source, tenant_id} <- lookup(conn, instance, route, conn.assigns[:ankusa_route]),
{:ok, cap} <- tenant_cap(conn, instance, tenant_id, declared, max),
:ok <- pre_read(conn, instance, source, declared),
:ok <- check_headers(conn, instance),
{:ok, body, conn} <- read_body(conn, instance, config, cap),
{:ok, conn} <- charge_read(conn, instance, source, declared, body) do
respond(
conn,
Ingest.ingest(instance, source, tenant_id, raw_request(conn, source, body))
)
else
{:refused, %Plug.Conn{} = conn} -> conn
end
end
The resolver maps the URL to a route, and an unknown route answers 404 unknown_source. A declared Content-Length over max_body_bytes answers 413 before the source is looked up. The lookup answers 503 store_unavailable when the source store cannot answer, never 404. The tenant’s own body cap is checked against the declared length, so a tenant with a smaller max_body_bytes is refused at its own limit.
Then comes the pre-read rate limit, which is the step that matters most for a flood. pre_read/4 charges three buckets in order: the client address, the node as a whole, and the source’s body bytes per second (packages/ankusa/lib/ankusa/edge/rate_limiter.ex):
def pre_read(instance, %Plug.Conn{} = conn, source_id, declared) do
with :ok <- scoped(hit_ip(instance, conn), :ip),
:ok <- scoped(hit_node(instance), :node) do
scoped(hit_source_bytes(instance, source_id, declared || 0), :source)
end
end
Each bucket answers 429 with its own reason, ip_rate_limited, node_rate_limited or source_rate_limited, and a Retry-After. The per-IP bucket hashes the client address into 2^20 buckets with a salt chosen at boot. The per-IP and node buckets are off until you configure them. The source byte bucket is on by default at 100 MB/s, and the configuration reference describes it as CPU protection rather than a quota.
Only after those steps does the edge check headers and read the body. A header that carries a byte outside visible ASCII, space and tab answers 400 invalid_header. The check runs over the name and the value of every header (packages/ankusa/lib/ankusa/edge/ingest.ex):
def check_headers([]), do: :ok
def check_headers([{name, value} | rest]) do
cond do
not name_bytes?(name) -> {:invalid_header, nil}
not value_bytes?(value) -> {:invalid_header, name}
true -> check_headers(rest)
end
end
Reading the body is the first step that spends the request’s own bytes. It answers 413 payload_too_large when the body is over the cap, 408 request_timeout when it takes longer than listener.request_deadline_ms (30 seconds by default), and 400 body_read_failed when the read fails. A chunked or undeclared body has no size to charge before it is read, so it is charged against the source’s byte bucket at this point.
Refusals are counted on ankusa_ingest_refused_total{instance,reason} and never create a per-source series, so an unauthenticated caller cannot grow /metrics, and an operator can still see which check is doing the refusing.


The whole request path
The diagrams above show the refusals. The full path from the socket to the store is shorter than it looks. The router hands the request to the resolver, which decides the source and the tenant. Ankusa.Edge.Ingest then builds the envelope, verifies it, reads the dedupe key, charges the tenant and claims the key, and applies the stored-header policy just before the commit. Only then does the hook go to the batcher, which hands it to the store and answers once the write is durable.


The batcher and the group commit are the subject of the second post in the series, so this one stops at the hand-off. What matters here is which steps run before the body and which after it. The body is the expensive thing to hold, and the edge makes every decision it can before reading it.
The body stays byte for byte
Once a request passes the edge, the hook is stored with the bytes the provider sent. build_envelope keeps the raw body, and nothing in the envelope re-encodes it. A provider’s signature covers the exact bytes, so a stored hook has to keep them intact for verification to mean anything later. When the body is a view into a larger buffer, the code copies it into a standalone binary only when the view would keep the whole buffer alive in memory. Otherwise the bytes are not copied at all.
Headers are a different question. A provider sends credentials in headers, and a stored hook should not carry them to every sink and every archive. The stored-header policy decides which headers survive. Its default drops authorization, proxy-authorization, cookie, set-cookie, x-api-key and x-auth-token and keeps the rest. The hash list is empty by default. A header can be listed under hash instead of drop, in which case it is kept with its value replaced by sha256: and the hex digest of the value, so two requests can still be told apart without holding the secret.
@default_drop ~w(authorization proxy-authorization cookie set-cookie x-api-key x-auth-token)
@doc "The instance default: the credential-bearing headers dropped, nothing hashed."
@spec default() :: policy()
def default, do: %{drop: @default_drop, hash: []}
The policy runs after verification. Verification and the dedupe key read the complete header list, because a signature or a key may cover a header the policy would later remove. What is stored, archived and forwarded is the list the policy leaves. A source can override the instance policy key by key, so it can add a header to its drop list without restating the defaults. The stored headers section of the configuration reference lists the override rules.
Five verifiers
Verification is where the edge decides a hook is authentic. Ankusa ships five verifier modules behind one behaviour, and each source names exactly one: Ankusa.Verifier.None, Hmac, Asymmetric, Token and ClientCert. The verifier behaviour documents the shared failure reasons, among them :missing_signature, :malformed_signature, :no_match and :timestamp_out_of_tolerance.
None accepts everything. It exists for providers that sign nothing and for internal sources you trust by network position, and it should be chosen on purpose.
Hmac covers most providers. It has presets for GitHub (X-Hub-Signature-256, sha256=, hex), Shopify (base64), Slack (a timestamp header and a v0= scheme), Stripe (v1 over the timestamp and the body) and the Standard Webhooks shape. A custom scheme is a template. Every candidate signature in the header is compared against the expected MAC for every configured secret, using a constant-time comparison. A secret list lets you rotate: list the new key and the old one, and both are accepted until the old one is removed.
def verify(%Envelope{} = env, opts) do
with {:ok, scheme, template} <- resolve_scheme(opts),
:ok <- Verifier.check_tolerance(opts),
{:ok, candidates, sig_ts} <- Template.candidates(env, scheme),
{:ok, ts} <- Template.timestamp(env, scheme, sig_ts, opts),
{:ok, signed} <- Template.signed_iodata(env, template, ts),
{:ok, keys} <- secret_keys(opts, scheme) do
matched? =
Enum.any?(keys, fn key ->
expected = encode(mac(scheme.hash, key, signed), scheme.encoding)
Enum.any?(candidates, &Verifier.secure_compare(&1, expected))
end)
The timestamp check bounds replay. The default tolerance is 300 seconds, and the validator refuses anything outside 0 to 3600 seconds, so a source cannot be configured to accept a day-old signature (packages/ankusa/lib/ankusa/verifier.ex):
def check_tolerance(opts) do
case opts[:tolerance] do
nil -> :ok
t when is_integer(t) and t >= 0 and t <= @max_tolerance_seconds -> :ok
_ -> {:error, :bad_tolerance}
end
end
The HMAC verifier also accepts hash: :sha1 in an inline scheme, for providers that still sign with SHA-1. That choice is weak. Ankusa logs a warning at boot when a source uses it, and it counts each such verification on ankusa_verifier_weak_hash_total{instance,source_id,scheme}, so the choice shows on a dashboard rather than staying buried in a config file.
Asymmetric verifies Ed25519 and RSA signatures against a public key, so the node checks what the provider signed without holding a secret the provider signed with. The Standard Webhooks asymmetric preset uses it. Token checks a shared secret presented as a bearer token, a basic-auth login (user:password), a named header or a query parameter. It accepts a secret list with the same rotation rule as HMAC. The query-parameter location is the weakest option, and the module says so, because a URL is logged by every proxy on the way.
ClientCert checks mutual TLS. A source can pin certificates by the SHA-256 of their DER encoding, or match subjects such as a DNS name, an email, a URI, an IP or a common name. It only works when the listener verifies peers. A source that asks for it while the listener does not will refuse to boot, rather than run unauthenticated.
When verification fails
A failed check has three possible outcomes, chosen per source with on_verify_failure. The default is reject, which answers 401 verification_failed with nothing stored. A request the sender could not prove is turned away with nothing kept from it.
quarantine answers 202 with quarantined. The hook is written to the quarantine pen with the stored-header policy already applied, so the credentials it carried are not kept there either. It is held, not delivered. How the pen is released and replayed is the fifth post’s subject, so this one stops at the pen.
accept_flag is the middle path. The hook is accepted and marked flagged: true. A flagged hook gets no dedupe key, because a forged request must not claim a real event’s key and suppress the real delivery later.

Charging the tenant after the signature
Verification comes before the tenant’s quota is spent. In Ankusa.Edge.Ingest, an accepted hook goes to admit, and only a hook that verified cleanly is charged to its tenant’s rate limit. A request that fails verification, or that the pre-read buckets refuse, spends nothing of the tenant’s quota. The code comment says it directly: a forged flood never spends a tenant’s budget, so it can never lock a tenant out of it. A flagged or quarantined hook spends its source’s quarantine bucket instead, and past it the sender gets 429 quarantine_rate_limited, so a forged flood is not free either.
The quota is hooks per second and bytes per second, with a burst. Its value is resolved in a fixed order: a runtime override first, then the tenant’s own entry under rate_limits.tenants, then rate_limits.default. The first one found applies as a whole, and no limit anywhere means unlimited. Whether the quota is counted per node or across the fleet is a separate decision, and the ninth post covers how one limit can be shared by several nodes.
The split is deliberate. The pre-read buckets run on every request, before anyone knows whether it is real, so they are sized to protect the node. The tenant quota is the tenant’s budget, and only a request that proves it came from the provider should draw on it.

Collapsing provider retries
Providers retry. A receiver that answers slowly, or not at all, gets the same event again, and without help it stores and delivers it again. A source can set dedupe: to name the event’s key: a preset such as github or stripe, a header such as X-GitHub-Delivery, or a JSON path into the body. When a key repeats, the later request gets 201 with the original id and "duplicate": true, and nothing new is stored.
Keys are scoped to the tenant and the source, so two tenants behind one source never collapse each other’s events. The default window is 259 200 000 milliseconds, which is 72 hours. The dedupe index has its own ceilings, dedupe.max_entries and dedupe.max_entries_per_tenant, which default to 100 000 000 and 30 000 000 live keys. Past either one, a new key answers 503 dedupe_quota with Retry-After: 60, so a flood of unique keys cannot grow the index without limit.
Dedupe runs after verification for the same reason the quota does. A request that was never signed does not get to claim a key.
What each status means
The quickstart’s ingest table is the contract a sender sees. It is copied here from the ingest responses section.
| Status | Meaning |
|---|---|
201 | Accepted, durably so. A repeat on a source with dedupe: answers 201 with the original id and "duplicate": true, and stores nothing new. A hook that no sink of its source selects through a sink filter answers 201 with "filtered": true: received, and not stored. |
202 | Quarantined after a failed verification (on_verify_failure: quarantine). It is held, not accepted for delivery. |
400 | The body could not be read, or a header holds a byte outside visible ASCII, space and tab (invalid_header; no sink could carry it, so retrying is pointless). |
401 | Verification failed under on_verify_failure: reject. |
404 | Unknown source, or a source owned by another tenant. |
409 | dedupe_pending: another node is committing the same event key (fleet-scoped dedupe). Retry. |
413 | Body over max_body_bytes. |
429 | Over a rate limit, nothing stored: the tenant’s (rate_limited) or, for a hook that would be quarantined, its source’s quarantine bucket (quarantine_rate_limited). Retry after Retry-After. |
503 | No durable destination right now: overload, the store could not take the commit (store_unavailable), the intake log could not confirm (intake_unavailable, intake_pending), or a sink refused under wal.type: none. Also a full quarantine pen (quarantine_full, Retry-After: 60). Retry later. |
A full dedupe index adds one more 503, dedupe_quota, covered above.
What it does not do
The edge does not judge whether a payload is sensible. It checks the signature, the size and the rate. A request signed correctly with a valid secret is a real request as far as the edge is concerned, and it spends the tenant’s budget like any other. Rate limits and quotas are the defense against that, and they are only as strong as you configure them. The per-IP and node limits are off by default.
A leaked secret passes verification. Rotation with a secret list and quarantine for a failed signature are the tools for that, and the fifth post covers the pen. The edge cannot tell a provider’s real request from a copy made by someone holding the key.
The full request path, with the stages after the edge, is described in the architecture reference.