Search by

enfiladeguide / web-bot-auth

Enfiladeguide

Sign HTTP requests as a Web Bot Auth agent (RFC 9421, Ed25519) and publish the signed key directory. Needs only ext-sodium.

Package info

github.com/Enfiladeguide/web-bot-auth-php

pkg:composer/enfiladeguide/web-bot-auth

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-12-02 20:27 UTC

This package is auto-updated.

Last update: 2026-12-02 20:53:41 UTC


README

Sign your PHP crawler's HTTP requests and publish its signed key directory, following Web Bot Auth (IETF draft draft-ietf-webbotauth-httpsig-protocol, built on RFC 9421 HTTP Message Signatures, Ed25519). Below, "the draft" and "-01" mean draft-ietf-webbotauth-httpsig-protocol-01 of 29 October 2026.

A site that sees your bot can check the signature against the key you publish, instead of trusting a User-Agent string anyone can copy.

  • Needs only ext-sodium. No HTTP client, no other dependency; it produces header values and you attach them with whatever client you use.
  • Follows -01: Signature-Agent as a dictionary member whose value is the URL of the key set.
  • Signs the directory response too (draft, appendix B), one signature per key, so the key set cannot be re-served under another host.
  • Can narrow a signature to one method, path and query. The draft asks agents that want a narrower signature to cover more than the minimum.
  • Request signing and the directory come from the signer that EnfiladeBot has run in production since September 2026, with its origin as the Signature-Agent value. The full URL that -01 asks for and the examples below use, narrower signatures, several keys and PEM keys are covered by the checks below, not by production use.

If your crawler is built on Guzzle, olipayne/guzzle-web-bot-auth-middleware signs Guzzle requests directly. This library is independent of the HTTP client and also covers the directory side.

Install

composer require enfiladeguide/web-bot-auth

PHP 8.2 or newer with ext-sodium. Without Composer, require the autoload.php of a checkout instead.

1. Create a key

vendor/bin/web-bot-auth-generate-key /etc/mybot/signing-key bot.example

Writes the base64 Ed25519 seed to the file (mode 0600, refuses to overwrite, never prints the seed) and prints the public JWK and the keyid. Keep the file out of the web root and out of version control.

KeyPair::fromFile() refuses a key file that group or others can read, so the file must belong to the user PHP runs as. Both the directory and the signer need the key. If the web server and the crawler run as different users, give each its own copy of the file, owned by that user, or pass checkPermissions: false and grant access your own way.

A key you already have works too: KeyPair::fromFile() also reads an unencrypted PKCS #8 PEM file, as openssl genpkey -algorithm ed25519 writes it.

2. Publish the directory

Serve this at https://bot.example/.well-known/http-message-signatures-directory (see examples/serve-directory.php):

use Enfiladeguide\WebBotAuth\{Directory, KeyPair};

$directory = new Directory(KeyPair::fromFile('/etc/mybot/signing-key'), ['bot.example']);

try {
    $response = $directory->respond($_SERVER['HTTP_HOST'] ?? '');   // a signed JWK Set
} catch (UnexpectedValueException) {
    http_response_code(404);                                  // a host it is not published under
    return;
}
foreach ($response->headerLines() as $line) {
    header($line);                                            // Content-Type, Content-Digest, Signature-Input, Signature
}
echo $response->body;                                         // exactly these bytes

The list passed to Directory is the hosts the directory is published under. The signature covers the host of the request, so the library signs only for hosts on that list; it will not sign for whatever Host header a client sends.

Content-Digest is computed over the body bytes. Do not let the web server compress, re-encode or append to the body. Compression is the usual way this breaks: nginx, for example, compresses only text/html unless gzip_types says otherwise, so this media type is left alone by default, but check your own configuration. Compare the Content-Digest you send with the digest of what a client actually receives.

A verifier takes the key set only from a 200 answer and does not follow redirects (draft, section 5.5), so serve it at the exact URL you sign with: no redirect to www, to a trailing slash or to another host. Keep bot protection off this one path, or verifiers cannot fetch the key that would identify them to you. A Cache-Control: max-age spares you repeated fetches; keep it shorter than the lifetime of the response signature (a day by default, the second argument of respond()).

Replacing a key

Publish the new key next to the old one, wait, switch the signer, then drop the old key (draft, section 5.5.2):

$directory = new Directory([$newKey, $oldKey], ['bot.example']);   // one signature per key

Verifiers cache the directory. Wait at least your max-age between publishing the new key and signing with it, so that no cache still holds the old set alone. Drop the old key once the last signatures made with it have expired. Removing a key is how you retire it; verifiers stop accepting it when their cached copy runs out. The draft defines no revocation.

3. Sign requests

use Enfiladeguide\WebBotAuth\{KeyPair, Signer};

$signer = new Signer(
    KeyPair::fromFile('/etc/mybot/signing-key'),
    'https://bot.example/.well-known/http-message-signatures-directory',   // the Signature-Agent value, see below
);

$headers = $signer->headerLines('https://museum.example/visit');
// ['Signature-Agent: sig1="…"', 'Signature-Input: sig1=(…)', 'Signature: sig1=:…:']

Add those lines to the request to exactly that URL, together with your User-Agent. Create a new signature for every request: each carries a fresh nonce. Sign requests that go over https: over plain http anyone on the path can read a signature and reuse it until it expires.

The Signature-Agent value is the URL of your key set. The draft treats that URL as your identifier: keep it stable, and use a different one for a different bot.

Redirects: sign every hop

The signature covers the host (and a non-default port) of one request. If your client follows a redirect to another host by itself, it sends the first host's signature there, and it fails. Follow redirects yourself and call headers() for each URL actually requested. examples/fetch.php shows it with PHP streams.

What the signature covers

By default: the request authority and the Signature-Agent member, with created, expires, keyid, alg, nonce and tag="web-bot-auth". That is the minimum the draft requires, and what EnfiladeBot sends. Such a signature is valid for any method, path and body sent to that host until it expires, so whoever sees one request can reuse it against the same host. The default lifetime is 300 seconds; the draft recommends at most 24 hours.

The draft asks for more. Section 5.2: "Agents that want to narrow the scope of their signature SHOULD also cover the following components", and, of the minimum, in the preamble to its test vectors: "Deployments should cover more and expire sooner." Ask for it:

$signer = new Signer(
    KeyPair::fromFile('/etc/mybot/signing-key'),
    'https://bot.example/.well-known/http-message-signatures-directory',
    lifetime: 60,
    cover: [Signer::METHOD, Signer::PATH, Signer::QUERY],
);

$headers = $signer->headerLines('https://museum.example/visit?lang=en', 'GET');
// Signature-Input: sig1=("@method" "@authority" "@path" "@query" "signature-agent";key="sig1");created=…

Now the signature is good for that one request line only. The price is that the URL you sign must be the URL your client sends, byte for byte: percent-encode it first, and resolve . and .. segments yourself (curl, for one, rewrites them unless told not to). The library refuses a covered path or query that holds anything but RFC 3986 characters and complete %XX escapes (so ?a[]=1 must be written ?a%5B%5D=1), and a path with dot segments. That catches the rewrites clients are known to make, not every one a client could make: check with the client you use. A proxy between you and the verifier that rewrites the path breaks the signature as well.

For the query the draft lists @target-uri and @query-param. This library covers the whole query string with @query of RFC 9421 instead, which does not depend on the scheme and host a verifier behind a proxy reconstructs. Not covered: the body (Content-Digest), @query-param, @target-uri.

alg is sent although the draft does not require it, and the nonce is 64 random bytes: the published web-bot-auth 0.2.0 package rejects a signature without alg, and a nonce of any other length.

Which Signature-Agent value?

You pass the value; the library sends it as a dictionary member (Signature-Agent: sig1="…", covered as "signature-agent";key="sig1"). Use the full URL of the key set unless a verifier you depend on needs something else:

Form Example Where it comes from
URL of the key set, as a dictionary member sig1="https://bot.example/.well-known/http-message-signatures-directory" -01, section 5.5: a verifier "fetches that URL directly and interprets the response as a JWK Set". Its changelog: "Make every Signature-Agent value a direct JWK Set URI."
Origin, as a dictionary member sig1="https://bot.example" Earlier drafts, where the value named an origin and the verifier added /.well-known/http-message-signatures-directory. The test vectors printed in -01 still carry an origin; the editors' copy has since changed them to the full URL. EnfiladeBot still sends this. A verifier that follows -01 to the letter fetches the home page instead of the key set.
Bare quoted origin, no label "https://bot.example" The earliest drafts, and what Cloudflare's and Fingerprint's documentation still describe. Draft -01, section 5.2.1: a verifier may accept it, but "Signers MUST send the dictionary form". Not produced by this library.

What was checked

With this library as the signer, on 2 December 2026. In each run a script fetched a two-key directory from examples/serve-directory.php and verified requests signed with either key. Those scripts are not part of this repository; what each run covered is set out here so that it can be repeated.

  • Cloudflare's TypeScript packages, sources of cloudflare/web-bot-auth at commit 6762be2 (2 Dec 2026): requests verify in both dictionary forms, with the minimum and with method, path and query covered, and are rejected for another path, query, method or host. The directory passes the checks that repository's example verifier makes, which we transcribed rather than running the worker itself: media type, kid equal to the thumbprint, Content-Digest, and the response signature of the key in question. Given an origin, that verifier tries the well-known path first.
  • The published packages web-bot-auth 0.2.0 and http-message-sig 0.3.0 (31 Aug 2026): the same requests and the same directory checks pass with the full URL as the Signature-Agent value. The origin form was not run against them: they predate -01 and read the value differently.
  • samesame 1.0.0 (Go): verifies the origin form over TLS with the directory response signature required, with the minimum and with method, path and query covered, with either key; rejects replay, expiry, a changed byte, another host, path, query or method. It rejects the full URL ("is not an origin (has a path)"): it implements the earlier draft.
  • Cloudflare's network: EnfiladeBot sends the origin form with the minimum coverage and has been a Cloudflare Verified Bot since 24 Oct 2026. In our logs Cloudflare passed its signed requests and refused requests with the same User-Agent that carried no signature; once those were signed too, they passed. It was not a controlled test (the unsigned client also differed in redirect handling and Accept-Encoding). Cloudflare's documentation (it cites draft-meunier-web-bot-auth-architecture-02) describes only the bare quoted form and lists a dictionary member as a failure. We did not test the full URL or the wider coverage against Cloudflare's network.
  • Fingerprint: documentation read, nothing tested. It describes the bare quoted form only, which this library does not send.

Check what the verifiers you care about accept. The draft is a work in progress and has changed between revisions: pin a version of this library and read the draft's changelog when you upgrade.

Tests

php tests/run.php

No dependencies. The suite reproduces byte for byte, with the public test key of RFC 9421 appendix B.1.4:

  • the Ed25519 request vector of the draft (appendix E), as published in -01 and as in the editors' copy of 2 Dec 2026;
  • the signed directory response of the draft;
  • the Ed25519 signature of RFC 9421 appendix B.2.6, which covers a method and a path. This one goes through the signing core with the values of the RFC; no published vector exercises the way Signer derives a method, a path and a query from a URL, so that is tested against a second construction of the signature base and against the verifiers above.

The rest covers authority normalisation, narrower signatures, two-key directories, key files, input validation, the key utility and the redirect handling of the example.

Safety notes

  • The key signs your identity. Anyone who has the seed can sign as you.
  • A signature proves control of a key published by the host in Signature-Agent. It does not prove the bot is well behaved. The site decides what to do with it.
  • Identifiers let sites correlate your requests across origins. That is the point of the protocol; do not reuse one key for a crawler and for agents acting for individual users (the draft asks for distinct Signature-Agent URLs).

License

MIT, see LICENSE.