Skip to content

Bot protection on Varnish Cache

Include centinel.vcl ahead of your own VCL. Centinel checks each protected request, then hands it to your vcl_recv, directors and cache policy.

How it fits into Varnish

Execution model
centinel.vcl, included after your backends, plus libvmod_centinel to decode block pages and append Set-Cookie.
Requirements
Varnish Cache 6.0 LTS or Varnish Enterprise 6 with matching varnish-dev headers. Distro Varnish 6.5 and 7.x are not supported.
Validator connection
A validator backend on 127.0.0.1:8443 behind a local TLS proxy, because open-source Varnish has no backend TLS.
Timeouts and failure mode
3 s connect, 5 s first byte and 2 s between bytes. Errors and timeouts fail open to your origin.

How a request moves through Varnish

The validator is an ordinary backend fetch, and the decision comes back in x-centinel-* headers, so VCL never parses JSON.

  1. vcl_recv

    Static paths bypass. GET, HEAD, POST, PUT, PATCH, DELETE and OPTIONS are checked; PURGE, BAN and ESI fragments go straight to your VCL. Bodies up to 1 MB are buffered.

  2. Validator fetch

    The request goes through the TLS proxy with X-API-Key. Cookie headers other than _centinel, and Authorization, are never sent to the validator.

  3. Decision

    Allow continues into your vcl_recv. Block returns 403 with the page from centinel.b64decode(). Redirect returns the interstitial through synth.

  4. Cache hits

    Cache hits are still checked, so a bot cannot read a cached page. Each allowed request costs one internal restart and then follows your cache policy.

Minimal configuration and a live check

Declare the validator timeouts and include centinel.vcl

default.vcl
vcl 4.1;

# Your first backend stays Varnish's default
backend origin { .host = "127.0.0.1"; .port = "8080"; }

backend validator {
  .host = "127.0.0.1";
  .port = "8443";
  .max_connections = 200;
  .connect_timeout = 3s;
  .first_byte_timeout = 5s;
  .between_bytes_timeout = 2s;
}

include "centinel.vcl";

Declare your origin before the include so it remains the default backend, and keep the three validator timeouts (Varnish defaults first_byte_timeout to 60 s). Extend your existing sub vcl_recv rules below the include.

Watch the validator hop

Verify
varnishlog -g request -q 'ReqURL eq "/validate"'
curl -s -o /dev/null -w '%{http_code}\n' -A 'python-requests/2.31' http://localhost/

varnishlog should record a /validate backend fetch on the request; curl returns 403 once blocking is enabled or 200 with a logged event in log-only mode. If no /validate fetch appears, check validator backend health and keep the four -p header buffer flags.

Deployment options

  • Reuse nginx or HAProxy as the TLS proxy

    Add a TLS-originating proxy on 127.0.0.1:8443 to an nginx or HAProxy you already run, with SNI, certificate checks and connection reuse.

    Varnish install guide (opens in a new tab)
  • ghostunnel sidecar

    Run ghostunnel client on 127.0.0.1:8443 toward validator.centinelanalytica.com:443 when no proxy runs on the host. Varnish Enterprise can use a native TLS backend instead.

    TLS proxy options (opens in a new tab)

What to know before deploying

  • Rebuild the VMOD after every Varnish upgrade

    The VMOD uses a strict ABI. On Debian 12 and Ubuntu 24.04, pin the 6.0 LTS repository, or apt installs Varnish 7 and the build fails.

  • Raise the header limits for block pages

    Pages arrive in x-centinel-response-html-b64. With the default limits, a page over about 23k fails the fetch and the request is allowed. Keep the four -p values from the guide.

  • List your proxies in centinel_trusted_proxy

    Varnish takes the client IP from the TCP connection. Add your TLS terminator or load balancer so the validator scores the visitor's IP from X-Forwarded-For.

  • Add the browser script yourself

    Pure VCL cannot change a response body, so this connector does not inject the script. Add the script tag to your HTML.

  • Your backends, directors and cache policy
  • Cached objects and TTLs
  • The Cookie and Authorization headers your origin receives
  • PURGE, BAN and ESI fragment requests

Varnish integration questions

Walk through your Varnish setup

Bring one route bots are hitting. We will map the right connector, timeouts, and log-only rollout for your Varnish stack.