Web Bot Auth

adk-auth (feature web-bot-auth) gives automated HTTP clients a verified identity. An agent signs each request with an HTTP Message Signature (RFC 9421) and names, in the Signature-Agent field, the origin that publishes its key. A site verifies the signature against that origin's key directory and learns who sent the request, where a User-Agent string such as GPTBot is only a claim.

The module implements the IETF Web Bot Auth working-group draft draft-ietf-webbotauth-httpsig-protocol-00 and the key directory of draft-meunier-http-message-signatures-directory-05, which the working-group draft absorbed, for Ed25519 keys.

PartType
Verify a requestHttpSignatureVerifier, VerifiedRequester
Sign an outgoing requestHttpSignatureSigner
Resolve and cache key directoriesKeyDirectorySource, HttpKeyDirectorySource, InMemoryKeyDirectorySource, DirectoryCachePolicy
Publish a directoryKeyDirectory, DirectoryResponse
KeysEd25519SigningKey, jwk_thumbprint
Signature base and structured fieldsRequestHead, SignatureInput, ComponentId, structured

Setup

[dependencies]
adk-auth = { version = "3.0.0", features = ["web-bot-auth"] }
http = "1"
reqwest = "0.13"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

Verify requests

use std::sync::Arc;

use adk_auth::web_bot_auth::{HttpKeyDirectorySource, HttpSignatureVerifier, WebBotAuthError};

fn verifier() -> Result<HttpSignatureVerifier, WebBotAuthError> {
    let directories = Arc::new(HttpKeyDirectorySource::new()?);
    Ok(HttpSignatureVerifier::builder(directories).build())
}

async fn identify<B>(verifier: &HttpSignatureVerifier, request: &http::Request<B>) -> String {
    match verifier.verify_request(request).await {
        Ok(Some(requester)) => requester.id,
        Ok(None) => "anonymous".to_string(),
        Err(error) if error.is_unverified() => format!("unverified: {error}"),
        Err(error) => format!("invalid: {error}"),
    }
}

verify_request reads an origin-form URI (/path?query) with the authority from Host or the URI, and https as the scheme unless the builder's default_scheme says otherwise.

OutcomeResultWhen
VerifiedOk(Some(VerifiedRequester))A signature tagged web-bot-auth verifies against a key its directory publishes
No identityOk(None)No Signature/Signature-Input, or no signature tagged web-bot-auth
UnverifiedErr(e) with e.is_unverified()The key material was not available: directory unreachable or malformed, key not published, fetch refused, or a Signature-Agent discovery type other than directory
InvalidErr(e) otherwiseA check failed: bad signature, expired, created in the future, missing component or parameter, test key, key outside its validity window

None of the failure outcomes grants an identity. A request carrying several Web Bot Auth signatures returns the first, in Signature-Input order, that verifies.

VerifiedRequester serialises with camelCase fields:

FieldValue
idwba:{directory origin}#{key thumbprint}
directoryOriginThe ASCII-serialised origin of the key directory, such as https://crawler.example
keyThumbprintThe signing key's JWK SHA-256 thumbprint (RFC 7638, RFC 8037), equal to keyid
created, expiresThe signature's validity window

What the verifier checks

CheckRule
Parameterscreated, expires and keyid present; alg, when present, is ed25519; expires not before created
Covered components@authority or @target-uri, and the signature's Signature-Agent member (its only one, or the one keyed to its label); plus each require_component
Freshnesscreated no later than now plus the skew; expires no earlier than now minus the skew; expires - created within max_signature_lifetime
Signature-AgentA String naming an http(s) origin with no path, query or fragment; dictionary form, or the legacy single String
KeySelected by its computed thumbprint, never by kid, from the directory of the covered Signature-Agent origin; nbf/exp include now; not the RFC 9421 test key
SignatureEd25519 over the RFC 9421 signature base recomputed from the request
Builder methodDefault
max_skew60 s
max_signature_lifetime24 h (None for no limit)
require_componentNone beyond the draft's minimum
default_schemehttps
allow_test_keysfalse
cache_policyDirectoryCachePolicy::default()
clockSystemClock

Sign outgoing requests

use std::sync::Arc;

use adk_auth::web_bot_auth::{Ed25519SigningKey, HttpSignatureSigner, WebBotAuthError};

async fn fetch_signed(url: &str) -> Result<String, Box<dyn std::error::Error>> {
    let jwk = std::env::var("CRAWLER_PRIVATE_JWK")?;
    let key = Arc::new(Ed25519SigningKey::from_jwk(&jwk)?);
    let signer = HttpSignatureSigner::builder(key, "https://crawler.example").build()?;

    let client = reqwest::Client::new();
    let mut request = client.get(url).build()?;
    signer.sign_reqwest(&mut request)?;
    Ok(client.execute(request).await?.text().await?)
}

fn new_key() -> Result<String, WebBotAuthError> {
    // Store the private JWK as a secret; it is the only copy of the key.
    Ok(Ed25519SigningKey::generate()?.to_private_jwk().to_string())
}

Each signature covers @authority, @method, @path, @query and the signer's Signature-Agent member, and carries created, keyid, alg="ed25519", expires, a random nonce and tag="web-bot-auth". sign_request signs an http::Request the same way.

Builder methodDefault
labelsig1
agent_memberThe label
components@authority, @method, @path, @query
lifetime5 minutes
nonceOn
clockSystemClock

The signer adds its member to an existing Signature-Agent dictionary and its signature to existing Signature-Input and Signature fields, so a second signer can cover the first signature's signature-input, signature and signature-agent members (draft §5.2.2).

Publish your key directory

use adk_auth::web_bot_auth::{DirectoryResponse, Ed25519SigningKey, KeyDirectory, WebBotAuthError};

/// The response for `/.well-known/http-message-signatures-directory` on crawler.example.
fn directory(key: &Ed25519SigningKey, now: i64) -> Result<DirectoryResponse, WebBotAuthError> {
    KeyDirectory::from_keys([key]).signed_response(&[key], "crawler.example", now, now + 7 * 24 * 60 * 60)
}

Serve response.body at /.well-known/http-message-signatures-directory with Content-Type: application/http-message-signatures-directory+json, a Cache-Control lifetime, and the Content-Digest, Signature-Input and Signature values. The signatures prove possession of each key over @authority;req and content-digest (draft Appendix B.1); the label is binding for one key and binding0, binding1, … for several. KeyDirectory::to_json alone gives the document without the proof.

To rotate, publish the new key beside the old one, sign with the new key, and remove the old key after the longest cache lifetime has passed.

Directory fetching

HttpKeyDirectorySource fetches the directory a request names, so it follows the draft's server-side request forgery guidance (§6.7):

LimitDefaultBuilder method
Schemehttps onlyegress_policy
AddressesPublic only: the URL's host and every resolved address are checked; no proxyegress_policy
RedirectsNot followed; any status other than 200 OK fails—
Media typeapplication/http-message-signatures-directory+json—
Timeout5 stimeout
Body size64 KiBmax_bytes
Keys64max_keys

EgressPolicy::allow_private_networks() (adk_core::egress) admits loopback, private addresses and plain http, never cloud metadata endpoints, for tests and in-cluster directories. Directory entries that are not Ed25519 keys, carry private material (d), have a use other than sig or an alg other than Ed25519 are skipped. nbf and exp are Unix seconds; values of 10^11 and above are read as milliseconds, which deployed directories publish.

Directory cache

DirectoryCachePolicy fieldDefaultMeaning
min_ttl60 sShortest caching; an unknown keyid refetches only once the entry is this old
max_ttl24 hLongest caching
default_ttl5 minLifetime when the response declares none
stale_if_error1 hHow long a stale directory keeps verifying while refreshes fail
negative_ttl30 sHow long a failed fetch is remembered
max_entries10,000Origins held at once; the oldest is evicted beyond it

The cache lifetime is Cache-Control: max-age (zero for no-store or no-cache), else Expires minus Date, less Age. A directory that resolves replaces the cached copy, so a removed key stops verifying; a failed fetch never evicts a cached copy (draft §6.10). Concurrent requests that miss the cache for one origin share a single fetch.

Interoperability

SourceResult
RFC 9421 Appendix B.2.6Signature base and Ed25519 signature reproduce byte for byte
Draft Appendix E.2.1The signer reproduces Signature-Agent, Signature-Input and Signature byte for byte; the verifier accepts them
Draft Appendix E.2.2The legacy single-String Signature-Agent verifies
Draft Appendix E.2.3signed_response reproduces the body, Content-Digest, Signature-Input and Signature byte for byte
RFC 8037 Appendix A.3jwk_thumbprint reproduces the thumbprint
The AWP 2.0 Web Bot Auth vectors (nine cases)Each case reaches its recorded verdict — valid, unsigned, or invalid for a changed path, an expired or future signature, an uncovered Signature-Agent — and each signature reproduces from its key; the files match the protocol repository's SHA256SUMS (adk-auth/tests/web_bot_auth_vectors.rs)
Cloudflare's research server (draft Appendix F)The verifier fetches its directory and verifies a request signed for it; the server accepts this module's signature in the legacy Signature-Agent form; its directory proof verifies over the base this module reconstructs

Note: the Cloudflare research server implements the earlier architecture draft and accepts only the legacy single-String Signature-Agent. HttpSignatureSigner sends the dictionary form, which draft-00 §5.2.1 requires of signers.

The live check is an ignored test: cargo nextest run -p adk-auth --features web-bot-auth --run-ignored only -E 'test(live_)'.

Standards