Building an AI Agent or Crawler? Sign Its Requests With Web Bot Auth (Python)
If you build anything that fetches web pages for an LLM, whether a research agent, a RAG ingester, a price monitor or a "summarize this URL" feature, you've probably hit the wall: 403s, CAPTCHAs, and "Just a moment…" pages that appear even on sites that would happily let you in if they knew who you

If you build anything that fetches web pages for an LLM, whether a research agent, a RAG ingester, a price monitor or a "summarize this URL" feature, you've probably hit the wall: 403s, CAPTCHAs, and "Just a moment…" pages that appear even on sites that would happily let you in if they knew who you were.
The bot-protection layer can't tell your agent from the thousands of scrapers that use the same Python HTTP client. A user-agent string doesn't help, because anyone can copy it. IP allowlists don't work for agents running on serverless or rotating infrastructure.
Web Bot Auth is the fix the industry is converging on. You sign every request with a private key, and you publish the public key at a well-known URL on a domain you control. Google signs some of its Google-Agent traffic this way, and Cloudflare and AWS verify these signatures at the edge. The previous post built the verifying side. This one builds the signing side.
Signature-Agent: sig1 = "https://bot.example.com" Signature-Input: sig1 = ( "@authority" "signature-agent" ); created =...; expires =...; keyid = "<thumbprint>"; alg = "ed25519"; nonce = "..."; tag = "web-bot-auth" Signature: sig1 =: < base64 signature >: Enter fullscreen mode Exit fullscreen mode Covering @authority ties the signature to the site you're calling, so it can't be replayed elsewhere. Covering signature-agent stops anyone from swapping in a different identity. expires keeps the replay window short.
# make_keys.py import base64, hashlib, json from pathlib import Path from cryptography. hazmat. primitives import serialization from cryptography. hazmat. primitives. asymmetric. ed25519 import Ed25519PrivateKey def b64url ( b: bytes ) -> str: return base64. urlsafe_b64encode ( b ). rstrip ( b "=" ). decode ( ) key = Ed25519PrivateKey. generate ( ) raw_pub = key. public_key ( ). public_bytes ( serialization. Encoding. Raw, serialization.
PublicFormat. Raw ) jwk = { "kty": "OKP", "crv": "Ed25519", "x": b64url ( raw_pub ) } # RFC 7638 thumbprint: SHA-256 of the required members, sorted, no whitespace thumb = b64url ( hashlib. sha256 ( json. dumps ( { "crv": jwk [ "crv" ], "kty": jwk [ "kty" ], "x": jwk [ "x" ] }, separators = ( ",", ":" ) ). encode ( ) ). digest ( ) ) Path ( "agent_key.pem" ). write_bytes ( key. private_bytes ( serialization. Encoding.
PEM, serialization. PrivateFormat. PKCS8, serialization.
NoEncryption ( ) ) ) wk = Path ( "public/.well-known" ) wk. mkdir ( parents = True, exist_ok = True ) ( wk / "http-message-signatures-directory" ). write_text ( json. dumps ( { "keys": [ jwk ] }, indent = 2 ) ) print ( "keyid:", thumb ) Enter fullscreen mode Exit fullscreen mode pip install cryptography requests python make_keys.py Enter fullscreen mode Exit fullscreen mode Keep agent_key.pem in your secrets manager, not in the repo. Deploy public/.well-known/http-message-signatures-directory to the domain your agent claims, and serve it with:
Content - Type: application / http - message - signatures - directory + json Cache-Control: max-age = 86400 Enter fullscreen mode Exit fullscreen mode The draft also asks that the directory response itself be signed (with tag="http-message-signatures-directory" ). Verifiers like Cloudflare's check that before registering you. The current draft has the exact components; it's the same signing function pointed at your own response.
# wba_sign.py import base64, hashlib, json, os, time from urllib. parse import urlsplit from cryptography. hazmat. primitives import serialization AGENT_ORIGIN = os. environ. get ( "AGENT_ORIGIN", "https://bot.example.com" ) LABEL = "sig1" TTL = 60 # seconds; keep it short with open ( os. environ. get ( "AGENT_KEY", "agent_key.pem" ), "rb" ) as f: _key = serialization. load_pem_private_key ( f. read ( ), password = None ) def _b64url ( b ): return base64. urlsafe_b64encode ( b ). rstrip ( b "=" ). decode ( ) _raw = _key. public_key ( ). public_bytes ( serialization. Encoding. Raw, serialization.
PublicFormat. Raw ) KEYID = _b64url ( hashlib. sha256 ( json. dumps ( { "crv": "Ed25519", "kty": "OKP", "x": _b64url ( _raw ) }, separators = ( ",", ":" ) ). encode ( ) ). digest ( ) ) def authority ( url: str ) -> str: parts = urlsplit ( url ) host = parts. hostname. lower ( ) default = { "http": 80, "https": 443 }. get ( parts. scheme ) return host if parts. port in ( None, default ) else f "{host}:{parts.port}" def sign_headers ( url: str ) -> dict: signature_agent = f '{LABEL}="{AGENT_ORIGIN}"' now = int ( time. time ( ) ) params = ( f '("@authority" "signature-agent")' f ';created={now};expires={now + TTL}' f ';keyid="{KEYID}";alg="ed25519"' f ';nonce="{_b64url(os.urandom(32))}"' f ';tag="web-bot-auth"' ) base = "\n". join ( [ f '"@authority": {authority(url)}', f '"signature-agent": {signature_agent}', f '"@signature-params": {params}', ] ) sig = base64. b64encode ( _key. sign ( base. encode ( ) ) ). decode ( ) return { "Signature-Agent": signature_agent, "Signature-Input": f "{LABEL}={params}", "Signature": f "{LABEL}=:{sig}:", } Enter fullscreen mode Exit fullscreen mode Using it with requests:
# fetch.py import requests from wba_sign import sign_headers UA = "ExampleResearchBot/1.0 (+https://bot.example.com/about)" def fetch ( url ): headers = { "User-Agent": UA, ** sign_headers ( url ) } # Sign per request: the signature is bound to the host and expires in 60s. # Disable redirects and re-sign for the new host if you follow one. r = requests. get ( url, headers = headers, timeout = 20, allow_redirects = False ) if r. is_redirect: return fetch ( requests. compat. urljoin ( url, r. headers [ "Location" ] ) ) return r print ( fetch ( "https://example.com/" ). status_code ) Enter fullscreen mode Exit fullscreen mode The redirect handling matters. If example.com redirects to www.example.com, the original signature covers the wrong @authority and fails. Re-sign on every hop.
Use the Node verifier from the previous post. Serve your key directory on one port and the verifier on another:
# terminal 1: serve the key directory as your "agent origin" cd public && python -m http.server 8000 # terminal 2: the Express app from the previous post, with # TRUSTED_AGENTS = new Set(["http://localhost:8000"]) node server.mjs Enter fullscreen mode Exit fullscreen mode # terminal 3 AGENT_ORIGIN = http://localhost:8000 python -c " import requests; from wba_sign import sign_headers u='http://localhost:3000/'; print(requests.get(u, headers=sign_headers(u)).text)" Enter fullscreen mode Exit fullscreen mode You should get hello, verified agent. Change one character of the signature, or wait 60 seconds and replay the same headers, and it should fall back to hello. If the round trip fails, the cause is almost always that the signature base doesn't match byte for byte.
Print both sides' base strings and diff them.
The signature is necessary, not sufficient. What gets a signed agent treated well:
This is all still draft-level: draft-ietf-webbotauth-httpsig-protocol was revised in September and October 2026, and a working-group use-case draft records that access control by bot identity is still contested. RFC 9421 itself is a finished standard, so the signing primitive won't change much. The header names and directory details could. Pin your implementation to a draft revision and recheck it every quarter.