Security

Threat model and controls: credential handling, path-traversal defence, TLS posture, denial-of-service bounds, schema-reference traversal, and supply-chain gates.

What this crate defends against, how, and what it deliberately does not.

Threat model#

schemreg sits between your application and a schema registry. It handles two kinds of untrusted input:

  1. Message bytes off a Kafka topic — fully attacker-controlled if any producer is compromised or if the topic is multi-tenant.
  2. Registry responses — trusted less than they look; a compromised or misconfigured registry, or anything on the path to it, can return arbitrary bytes. Note that a registry response can also direct further requests: a schema's references list names other subjects to fetch, so the response is an input to a traversal, not just a value.

And one kind of caller-supplied input that is often attacker-influenced without anyone noticing: subject names, which are frequently derived from topic names, tenant identifiers, or request fields.


Credentials#

ControlBehaviour
In memoryzeroize::Zeroizing for username, password, and bearer token — wiped on drop
Derived materialThe intermediate user:pass string and its base64 encoding are also Zeroizing
Debug outputRenders basic(***) / bearer(***); never the value
tracing eventsNo credential is ever a field. Events carry URL, status, attempt, delay, error text
In URLsuser:pass@host is rejected at construction, authority-scoped so ?q=a@b still works
In headersOnly Authorization carries them; the User-Agent is a fixed schemreg/{version} string with nothing caller-derived in it
Over cleartextA hard Config error off-loopback. See below

The loopback exemption#

Basic/Bearer credentials over http:// are a hard error for any non-loopback host, and a warning for localhost, 127.0.0.0/8, and ::1.

This is the same "potentially trustworthy origin" rule browsers apply: loopback traffic never leaves the machine, so there is no network on which to intercept it — and http://localhost:8081 with basic auth is the standard docker-compose setup.

A private-range address like 10.0.0.5 is not exempt. It is still a real network with real switches.

What zeroization does not do#

Zeroizing guarantees the buffer is wiped on drop. It cannot prevent the OS paging it out beforehand. Mitigating that needs mlock, which is platform-specific and requires privileges — out of scope for a client library.


Path traversal#

The percent-encoder deliberately does not encode ., because com.example.Order-value is the most common real subject shape. That means a .. segment would survive encoding, and DELETE /subjects/.. could be collapsed by a proxy into DELETE /subjects — mass deletion instead of one subject.

Every operation that interpolates a subject into a URL therefore validates it first. A subject reaches a URL only after:

  • non-empty
  • ≤ 512 bytes
  • no . or .. segment under either / or \
  • no . or .. segment in its percent-decoded form

That last check is defence in depth. This crate encodes ..%2fadmin correctly, to the single literal segment ..%252fadmin — but a gateway that decodes the path twice recovers ../admin. Screening the decoded form removes the crate from that chain entirely.

Apicurio validates both the joined subject and each address component independently, because it splits on / before encoding — so ../secrets would otherwise become /groups/../artifacts/secrets and escape the group boundary that is Apicurio's whole multi-tenancy mechanism.

Every Apicurio operation routes through one artifact_id constructor that performs those checks, so a route added later cannot skip them by calling ArtifactId::from_subject directly.


TLS#

Stackrustls on aws-lc-rs — the provider the AWS SDK already links, so a build with every backend has exactly one. ring, openssl, openssl-sys and native-tls are banned in deny.toml
Key exchangethe hybrid post-quantum group X25519MLKEM768 is offered first; tests/tls.rs asserts it is what a TLS 1.3 server negotiates
Trustthe operating system's trust store via the platform verifier, including enterprise-installed roots and the OS's revocation checks
Private CAadd_root_certificate trusts it in addition to the OS store; trust_only_root_certificates trusts only the given roots. Setting both is a Config error
Client certificatesidentity(Identity::from_pem(..)) for mutual TLS
Protocol floorTLS 1.2 (the oldest rustls implements); require_tls13() refuses anything older
Refused handshakeSchemaRegError::Tls — is_tls_error() is true, is_retryable() is false: an untrusted certificate does not become trusted on the next attempt
Bypassnone. grep -rn "danger_accept_invalid" src/ returns nothing — not even feature-gated

Redirects are bounded to 3, and reqwest strips Authorization on cross-origin redirects, so credentials cannot follow a hostile Location.

use schemreg::{ConfluentSchemaRegistry, tls::{Certificate, Identity}};

let registry = ConfluentSchemaRegistry::builder()
    .url("https://registry.internal:8081")
    .add_root_certificate(Certificate::from_pem(&std::fs::read("ca.pem")?)?)
    .identity(Identity::from_pem(&std::fs::read("client.pem")?)?)  // cert chain + key
    .require_tls13()
    .build()?;

schemreg::tls re-exports reqwest's Certificate and Identity, so none of this needs a direct reqwest dependency.

FIPS#

aws-lc-rs has a FIPS 140-3 validated mode, but building it needs CMake and Go, so schemreg does not switch it on. An application that must run FIPS-validated crypto enables aws-lc-rs/fips in its own build and installs rustls::crypto::default_fips_provider() as the process default before building any client.

Every handshake option is tested against a real server#

tests/tls.rs runs an in-process rustls server with a CA generated per test: trust-only accepts its CA and rejects any other, an added root extends the OS store, a TLS 1.2-only server is accepted by default and refused under require_tls13, mutual TLS fails without the identity and succeeds with it, and a refused handshake is attempted exactly once even with retries enabled.


Denial of service#

VectorControl
Oversized response16 MiB, enforced from Content-Length before reading and again while streaming
Oversized request4 MiB cap on schema text, checked before the socket is touched
Decompression bombGlue ZLIB output capped at 128 MiB during decompression
Protobuf index explosionCount capped at 512 before any Vec::with_capacity sized from input
Varint overflowShift-width guard; out-of-domain and negative values rejected
Schema-reference chainAvro and JSON Schema dependency closures capped at 32 levels deep and 256 schemas; a visited set makes a reference cycle terminate instead of recursing
Unbounded cache growthEvery cache is bounded (default 1 000 entries) with FIFO eviction
Oversized subject512 bytes
Retry amplificationBounded attempts, capped delay, Retry-After honoured, jittered back-off
Connection exhaustionmax_concurrent_requests on both builders; coalescing collapses same-ID bursts
JSON Schema remote $refjsonschema is built without resolve-http, and the retriever this crate installs answers only from schemas already fetched via the registry's own references list — compilation cannot make outbound requests (no SSRF)

Schema-reference traversal#

Resolving a schema that uses the references mechanism means following a graph the registry controls. Three bounds keep that from becoming a denial-of-service against the client, and they apply identically to the Avro and the JSON Schema resolver:

  • a visited set keyed by (subject, version), so a cycle A → B → A terminates and a diamond is fetched once rather than once per path;
  • a depth cap of 32, which no real schema graph approaches;
  • a total cap of 256 resolved schemas.

Nothing in the Confluent API forbids a cycle, so this is a real shape a registry can be made to return, not a theoretical one.

For JSON Schema, bounding the traversal to the registry's own reference list is also what closes the SSRF path. A $ref is a URI, and a permissive resolver would fetch it. The retriever installed here has no network access: it answers from the fetched closure and from documents the caller supplied to dependencies, and errors on anything else.

Producer write permissions#

SchemaResolution::AutoRegister is the default and needs Subject:Write — a usability default, not a security one: a producer holding write credentials creates schema versions the moment its local schema drifts. LookupOnly needs only Subject:Read and turns that drift into a startup failure. Where the registry is a governance boundary, grant read-only credentials and set it.

Retry jitter#

Without jitter, every client that saw the same 503 retries at exactly 100 ms, 200 ms, 400 ms — reconverging into synchronised waves that hit the registry while it is recovering. Back-off uses equal jitter (temp/2 + random(0, temp/2)), which spreads clients out while keeping a meaningful minimum delay.

A server-supplied Retry-After is never jittered and never shortened — the server asked for at least that long — but it is clamped to max_backoff, so a hostile or mistaken Retry-After: 86400 cannot wedge the caller.


Supply chain#

GateStatus
cargo deny checkadvisories, licences, bans, sources — with all-features
cargo audit --deny warningsevery push and pull request
Licence policypermissive-only allow-list, every entry comment-justified
Duplicate versionsdenied, with justified skips naming the upstream cause
Wildcard versionsdenied
Yanked cratesdenied
Source registrycrates.io only; git and path dependencies rejected
Cargo.lockcommitted; the MSRV job builds --locked

With every backend optional, cargo deny on the default feature set scans almost nothing. [graph] all-features = true is what makes the gate real.


Reporting#

Open a private security advisory on the GitHub repository. Please do not file a public issue for anything that looks exploitable.