Python: Web Bot Auth profile
Application profiles are not part of the core DNSid protocol — they are optional application-layer integrations built on top of it.
WebBotAuthProfile
Section titled “WebBotAuthProfile”from dnsid import WebBotAuthProfileJWT bot bearer authentication using DNSid-issued JWTs.
The legacy class name is retained for compatibility. This is not RFC 9421 Web Bot Auth; use WBAHttpSigner and WBAHttpVerifier for that profile.
Implements the Agent Identity Assertion (AIA) pattern for HTTP bot auth:
- Signs outbound requests with
Authorization: Bearer <dnsid-jwt> - Verifies inbound requests by validating the Bearer token
An application profile layered on top of DNSid identity verification. Application profiles are not part of the core DNSid protocol and are not required for DNSid conformance.
WebBotAuthProfile constructor
Section titled “WebBotAuthProfile constructor”WebBotAuthProfile(resolver: IdentityResolver, key_provider: KeyProvider | None, domain: str, bot: BotIdentity | None = None, config: BotAuthConfig | None = None) -> NoneInitialize the profile for a local bot identity.
Arguments:
resolver(IdentityResolver): Any object satisfying the IdentityResolver protocol.key_provider(KeyProvider | None): Key management implementation for the local bot identity, or None for a verification-only profile.domain(str): FQDN of the local bot identity, or "" when verification-only.bot(BotIdentity | None): Bot metadata to include in signed JWTs. — defaultNoneconfig(BotAuthConfig | None): Optional freshness/verification overrides. — defaultNone
from_identity_manager
Section titled “from_identity_manager”WebBotAuthProfile.from_identity_manager(manager: object, bot: BotIdentity | None = None, config: BotAuthConfig | None = None) -> WebBotAuthProfileConstruct from a fully-initialised IdentityManager.
Reads domain and key_provider from the manager.
create_bot_token
Section titled “create_bot_token”WebBotAuthProfile.create_bot_token(target_url: str, *, expiry: datetime.timedelta | None = None, additional_claims: dict[str, Any] | None = None) -> strCreate a signed JWT for bot authentication.
The JWT includes:
iss/sub: the bot’s DNSid domainaud: the target URL origin (scheme + host)bot: bot identity metadataiat,exp,jti: standard temporal claims
Arguments:
target_url(str): The URL being requested. The audience is derived from its origin.expiry(datetime.timedelta | None): Token lifetime. Default 5 minutes. — defaultNoneadditional_claims(dict[str, Any] | None): Extra claims to include in the JWT payload. — defaultNone
Returns:
str— The signed JWT in compact serialization.
Raises:
ArgumentError: If the profile is verification-only,target_urlis not a valid URL, the requested expiry exceeds the configured maximum lifetime, oradditional_claimswould override a reserved claim.
sign_bot_request
Section titled “sign_bot_request”WebBotAuthProfile.sign_bot_request(request: httpx.Request, *, expiry: datetime.timedelta | None = None, additional_claims: dict[str, Any] | None = None) -> httpx.RequestSign an outbound httpx.Request with a bot auth JWT.
Adds an Authorization: Bearer <jwt> header to the request and
sets a User-Agent header incorporating the bot identity.
Arguments:
request(httpx.Request): The httpx.Request to sign.expiry(datetime.timedelta | None): Token lifetime override. — defaultNoneadditional_claims(dict[str, Any] | None): Extra claims for the JWT. — defaultNone
Returns:
httpx.Request— A new httpx.Request with the Authorization header set.
Raises:
ArgumentError: If Authorization is already present, or token creation rejects the URL, expiry, or claims. The original request is unchanged.
create_signed_bot_client
Section titled “create_signed_bot_client”WebBotAuthProfile.create_signed_bot_client(*, expiry: datetime.timedelta | None = None, additional_claims: dict[str, Any] | None = None, base_headers: dict[str, str] | None = None) -> httpx.ClientReturn an httpx.Client that automatically signs every request with bot auth.
Every outbound request gets an Authorization: Bearer <dnsid-jwt> header.
Arguments:
expiry(datetime.timedelta | None): Token lifetime override applied to every request. — defaultNoneadditional_claims(dict[str, Any] | None): Extra claims added to every JWT. — defaultNonebase_headers(dict[str, str] | None): Default headers applied to every request. — defaultNone
Returns:
httpx.Client— An httpx.Client that signs each request before sending it.
verify_bot_request
Section titled “verify_bot_request”WebBotAuthProfile.verify_bot_request(*, headers: dict[str, str], expected_audience: str, peer_cert: TLSCertificate | None = None) -> VerifiedBotRequestVerify an inbound bot request by validating its Authorization Bearer JWT.
Resolves the JWT issuer’s DNSid identity and verifies the signature.
Arguments:
headers(dict[str, str]): The HTTP request headers (case-insensitive lookup for Authorization).expected_audience(str): Required trusted origin of the server receiving the request; the JWTaudclaim must match this value.peer_cert(TLSCertificate | None): Certificate from the current peer connection. Required when the issuer’s DNSid record carriesfl=mtls. — defaultNone
Returns:
VerifiedBotRequest— A VerifiedBotRequest with the verified domain and bot metadata.
Raises:
VerificationError: If the token is missing, malformed, expired, or signature-invalid, or a claim fails validation; also propagated from issuer identity verification. Carries a VerificationCode.
BotAuthConfig
Section titled “BotAuthConfig”from dnsid import BotAuthConfigConfiguration for JWT bot bearer authentication.
Attributes:
max_lifetime(datetime.timedelta): Maximum acceptable JWT lifetime. Default 15 minutes.clock_skew(datetime.timedelta): Allowed clock skew tolerance. Default 60 seconds.require_bot_claim(bool): If True, verification rejects JWTs without abotclaim.
BotIdentity
Section titled “BotIdentity”from dnsid import BotIdentityMetadata describing the bot/agent for inclusion in the JWT bot claim.
Attributes:
name(str): Human-readable bot name (e.g. “AcmeSearchBot”).version(str): Bot version string (e.g. “1.2.3”).purpose(str): Short machine-readable purpose tag. Common values: “search-indexing”, “data-collection”, “monitoring”, “ai-training”, “summarization”.operator_url(str): URL with more info about the bot and its operator (like robots.txt contact info). Should be an HTTPS URL.
VerifiedBotRequest
Section titled “VerifiedBotRequest”from dnsid import VerifiedBotRequestResult of successful bot request verification.
Attributes:
domain(str): The verified DNSid domain of the bot.bot(BotIdentity | None): Bot identity metadata extracted from the JWTbotclaim, or None.verified_domain(VerifiedDomain): The full VerifiedDomain result from DNSid resolution.claims(dict[str, Any]): The decoded JWT claims.
WBAHttpSigner
Section titled “WBAHttpSigner”from dnsid import WBAHttpSignerSign outbound requests as Web Bot Auth HTTP Message Signatures.
Web Bot Auth is an application profile layered on top of DNSid identity; application profiles are not part of the core DNSid protocol and are not required for DNSid conformance.
WBAHttpSigner constructor
Section titled “WBAHttpSigner constructor”WBAHttpSigner(key_provider: KeyProvider, domain: str, *, config: WebBotAuthConfig | None = None, signature_agent: str | None = None, ku_url: str = '', label: str = DEFAULT_LABEL, expires_in_seconds: int | float | None = None) -> NoneInitialize the signer for a local DNSid identity.
Arguments:
key_provider(KeyProvider): Provides the Ed25519 signing key. WBA signing requires Ed25519; other key types raise ArgumentError at signing time.domain(str): The DNSid FQDN, used to derive the default directory URL.config(WebBotAuthConfig | None): OptionalWebBotAuthConfig, copied and validated at construction. — defaultNonesignature_agent(str | None): Back-compat override for the directory URL placed in Signature-Agent. — defaultNoneku_url(str): Known local operational JWKS URL; rejects matching directory URLs. — default''label(str): Signature label and Signature-Agent dictionary member name (profile default:sig1). — defaultDEFAULT_LABELexpires_in_seconds(int | float | None): Back-compat override for the request signature TTL. — defaultNone
Raises:
ArgumentError: If the discovery URI is invalid, contains credentials, is not HTTPS, or the TTL is not an integer from 1 through 300.
WBAHttpSigner.sign(req: HttpRequest, variant: WBAVariant = WBAVariant.ACTIVE, options: WebBotAuthSigningOptions | None = None) -> HttpRequestSign req in place and return it.
REVOKED signs normally — revocation is a directory-state concern
checked by the verifier, not a property of the signature bytes.
Arguments:
req(HttpRequest): The request to sign; headers (and, forTAMPERED, the body) are modified in place.variant(WBAVariant): Signing variant to produce.NO_SIGreturns req unmodified; other variants produce deliberately broken signatures for verifier testing. — defaultWBAVariant.ACTIVEoptions(WebBotAuthSigningOptions | None): Optional per-request overrides. — defaultNone
Returns:
HttpRequest— The same request, with Signature-Input, Signature, and Signature-Agent set.
Raises:
ArgumentError: If the TTL is invalid, Signature-Agent is disabled, the key is not Ed25519, or an additional component is unsupported. Also raised if the signing key changes during signing. Nested signing is not supported because signature fields are replaced.
WBAHttpVerifier
Section titled “WBAHttpVerifier”from dnsid import WBAHttpVerifierVerify DNSid WBA requests and their signed directories.
Construction needs no local identity or signing key. The default transport validates Web PKI and pins connections to public DNS addresses. An injected transport is trusted infrastructure and MUST enforce the same constraints, on every connection, reject redirects, and honor remaining_seconds(). Injected transports must preserve uncoded response bytes and fields, without transparent decompression. Directories are fetched unconditionally with Cache-Control: no-cache on every invocation; injected caches must revalidate and must never serve stale evidence. Visible Date/Age and max-age bound the operation, including DNSid refresh and replay checks. Fresh zero-freshness responses can serve their acquiring invocation. No local cache is maintained. A verified key mismatch permits one DNSid refresh per domain per five seconds; concurrent retries are suppressed, failures consume the allowance, and at most 1024 active/cooldown domains are retained. No stale-key fallback is allowed. The default secure transport and its connection pool are reused until close(). Call close() after all verification operations finish. Injected transports remain caller-owned and must support concurrent use when the verifier is shared. The caller manages their initialization and closure.
Requests are buffered: hosts must enforce the 8 MiB body and 64 KiB header limits while reading. Directory reads are limited to 1 MiB, 32 keys, JSON depth 16, and 16 signatures. Redirects are rejected. Responses with any Content-Encoding field are rejected before reading. The complete operation has a default 30-second cooperative deadline.
WBAHttpVerifier constructor
Section titled “WBAHttpVerifier constructor”WBAHttpVerifier(resolver: RefreshingIdentityResolver, *, config: WebBotAuthConfig | None = None, transport: httpx.BaseTransport | None = None) -> NoneSet the resolver and transport; copy and validate the configuration.
WBAHttpVerifier.close() -> NoneRelease the owned connection pool; never close an injected transport.
Call only after in-flight verifications finish. Repeated calls are safe; verification after closure raises RuntimeError.
verify_web_bot_auth_signed_request
Section titled “verify_web_bot_auth_signed_request”WBAHttpVerifier.verify_web_bot_auth_signed_request(req: HttpRequest, opts: WebBotAuthVerificationOptions | None = None) -> VerifiedDomainReturn the signer only after request, directory, and DNSid checks succeed.
Arguments:
req(HttpRequest): Buffered application request, including exact supplied content.opts(WebBotAuthVerificationOptions | None): Trusted discovery, application peer, deadline, and replay policy. — defaultNone
Returns:
VerifiedDomain— Verified DNSid signer identity, not application authorization.
Raises:
ArgumentError: On malformed required-component policy or invalid deadline.VerificationError: On invalid evidence, discovery, acceptance, or replay.RuntimeError: If the verifier has been closed.
WebBotAuthVerificationOptions
Section titled “WebBotAuthVerificationOptions”from dnsid import WebBotAuthVerificationOptionsTrusted per-invocation WBA policy.
Without signer_domain, discovery can identify the signer only when
allow_signature_agent_domain is explicitly enabled. Discovery must remain
on that signer’s host; redirects and delegation are not supported.
discovery_uri, when supplied, constrains the signed discovery URL; it
cannot replace the required covered Signature-Agent member.
required_components adds application coverage requirements, defaulting
to none. Equality compares component names and parameter values. Malformed
policy raises ArgumentError; missing coverage rejects before discovery.
replay_policy(domain, keyid, nonce, retain_until) must atomically record
an unused tuple through the supplied Unix timestamp and return True, or
return False for reuse. Exceptions fail closed. Blocking callbacks and
injected resolvers must honor the shared verification budget.
WBAVariant
Section titled “WBAVariant”from dnsid import WBAVariantSigning variants the test driver toggles (§7).
Members:
ACTIVE='active'REVOKED='revoked'KEY_MISMATCH='key-mismatch'NO_SIG='no-sig'TAMPERED='tampered'EXPIRED='expired'
WBADirectoryResponse
Section titled “WBADirectoryResponse”from dnsid import WBADirectoryResponseA signed HTTP Message Signatures Directory response.
WebBotAuthConfig
Section titled “WebBotAuthConfig”from dnsid import WebBotAuthConfigWBA profile configuration (design doc 10 §Profile Configuration).
TTLs require integral seconds from 1 through 300. Clock skew must be finite and non-negative. Boolean and non-numeric duration values are rejected. Signature-Agent is mandatory; its compatibility flag cannot disable it. Signature-Agent advertises the direct HTTPS URL of the signed key directory.
WebBotAuthSigningOptions
Section titled “WebBotAuthSigningOptions”from dnsid import WebBotAuthSigningOptionsPer-request overrides for CreateWebBotAuthSignedRequest.
serve_http_message_signatures_directory
Section titled “serve_http_message_signatures_directory”from dnsid import serve_http_message_signatures_directoryserve_http_message_signatures_directory(req: HttpRequest, key_provider: KeyProvider, config: WebBotAuthConfig | None = None) -> WBADirectoryResponseReturn the active public signing key as a signed WBA directory response.
The body is a JWKS object served with the
application/http-message-signatures-directory+json media type and one
HTTP Message Signature over "@authority";req, content-type,
cache-control, and content-digest with
tag="http-message-signatures-directory". Signatures are backdated by
min(5, ttl - 1) seconds without extending their lifetime. Cache-Control caps
freshness at remaining validity and requires revalidation; disable CDN stale
serving, stale-while-revalidate, and stale-if-error for this endpoint.
Arguments:
req(HttpRequest): The inbound directory request; its authority is covered by the response signature.key_provider(KeyProvider): Provides the Ed25519 signing key to publish and sign with.config(WebBotAuthConfig | None): OptionalWebBotAuthConfig; controls the directory signature TTL. — defaultNone
Returns:
WBADirectoryResponse— A WBADirectoryResponse with status, headers, and JWKS body.
Raises:
ArgumentError: If the key is not Ed25519, changes during signing, or the signature expires during signing.