CasWAF
Rules

Web Bot Auth rules

Web Bot Auth lets an agent or a crawler sign each request with HTTP Message Signatures (RFC 9421). The Signature-Agent header names the agent's directory of public keys, at /.well-known/http-message-signatures-directory, and Signature-Input and Signature carry the signature. Unlike a User-Agent string or an IP range, a signature can't be copied to another host or replayed after it expires.

A Web Bot Auth rule verifies the signature and matches on the result.

What CasWAF checks

CasWAF looks at the signatures with tag="web-bot-auth" and verifies each until one passes:

  • the signature has created, expires and keyid, is not expired, and was not created in the future, allowing 60 seconds of clock difference
  • it covers @authority and the Signature-Agent header, so it is only good for this host and this directory
  • the algorithm is Ed25519
  • the directory named in Signature-Agent has a key whose JWK thumbprint is the keyid, and the signature matches

The result is one of:

ResultMeaning
verifiedA signature passed all the checks
invalidThe request carries a Web Bot Auth signature, but it is malformed, expired, for another host, or doesn't match, or the directory can't be fetched
unsignedNo Web Bot Auth signature

Operators

OperatorValueMatches when
isverified, invalid or unsignedthe result is the value
is notverified, invalid or unsignedthe result is anything else
is inhosts, separated by commasthe result is verified, and the host of Signature-Agent is in the list
is not inhosts, separated by commasthe request isn't verified with a key from one of these hosts

A host in the list is the host of the directory, such as id.casdoor.com, compared without case. *.example.com matches every subdomain of example.com. A rule matches when any of its expressions matches.

The directory

CasWAF fetches the directory over HTTPS or HTTP, follows at most 3 redirects, gives up after 5 seconds, and reads at most 1 MB. It keeps the Ed25519 keys of a directory for an hour, and remembers a failed fetch for 5 minutes. It doesn't send the fetch through a proxy.

CasWAF doesn't fetch directories on loopback, private or link-local addresses, so that a signed request can't make it call your internal services. To verify agents whose directory is on your own network, add to conf/app.conf:

webBotAuthAllowIntranet = true

Examples

Let verified agents through. Type Web Bot Auth, operator is in, value id.casdoor.com, action Allow. Put it before the User-Agent and rate limiting rules that block bots.

Block forged signatures. Type Web Bot Auth, operator is, value invalid, action Block.

Only signed agents on an API for agents. A compound rule of a URL Path rule for ^/agent-api/ and a Web Bot Auth rule is not verified, action Block, status code 401.

Casdoor keeps the keys of agents, publishes the directory and signs requests for them.

Edit on GitHub

On this page