Introducing a new way to review your PRs.

Read the announcement

techarohq / anubis

Weighs the soul of incoming HTTP requests to stop AI crawlers

View on GitHub

19 documents · Updated Nov 23, 2026

docs / challenge-ui-delivery

Challenge UI and asset delivery

Challenge UI delivery turns a server-issued challenge into a complete browser page. The server selects a challenge method, renders its page fragment inside a shared shell, and supplies the data, text, and asset URLs that the browser needs to solve the challenge and continue to the protected request. See also client challenge runtime and WASM proof of work.

Challenge page composition

The challenge page has two layers. A method-specific template supplies the user task, while the shared web shell supplies the document head, title, style, footer, challenge metadata, and common service links. The request path, challenge record, policy rule, and optional OpenGraph tags enter this composition before the response is sent with a challenge status and no-store caching.

Challenge method templates

Each registered challenge method returns a page component for the same outer shell. The main families are:

  • Script-backed proof pages: WASM methods and the fast or slow proof-of-work methods show status, progress, failure text, and a script entry point.
  • Preact page: The small Preact method renders an initial app container and passes its challenge data to an embedded client app.
  • Refresh page: The meta-refresh method uses a timed browser refresh instead of client computation.

This common contract lets the request handler add extensions and shared metadata without knowing how a method presents or validates its work. The browser-visible page still has a useful loading state when the client code has not started.

References: lib/http.go• L315-395 lib/…/interface.go• L92-101 lib/…/wasm.templ• L9-27 lib/…/proofofwork.templ• L9-27 lib/…/preact.templ• L8-27 lib/…/metarefresh.templ• L10-20

Shared page shell

The shared shell defines the browser contract around every challenge fragment. It sets the document language, loads the common stylesheet, marks the page as unsuitable for search indexing, writes challenge and runtime values as JSON data, and shows the common footer and optional honeypot or imprint links.

The shell also owns the common loading layout. Client code finds stable elements such as title, status, image, and progress, then changes them as work starts, completes, or fails. A method template must preserve the elements needed by its client runtime.

References: web/index.templ• L12-92 web/index.go• L16-27 web/index_test.go• L15-80

Browser data and hydration

Hydration is the hand-off from server-rendered HTML to browser code. Here it means that the server writes challenge state and shared runtime values into JSON script elements, and client code reads those values before it starts work. The page can therefore show text and an image before JavaScript runs, while the client receives the exact challenge ID, random data, rule, redirect context, version, and base path that the server selected.

Challenge state transfer

The shell exposes the challenge and its rule as anubis_challenge. It also exposes the version, base prefix, and public URL. The Preact page uses a separate preact_info payload because that page has its own small client flow. These payloads are the boundary between server rendering and browser behavior; changing a field requires matching changes in the reader and in the page that emits it.

The main challenge runtime reads the shared payload, selects the configured algorithm, reports progress, waits for configured extensions, and redirects to the pass endpoint with the result. The Preact runtime reads its page payload, computes its result, and redirects in the same general way.

References: web/index.templ• L61-64 web/…/main.ts• L150-180 lib/…/preact.templ• L15-23 lib/…/app.tsx• L15-21 lib/…/app.tsx• L30-69

Script load recovery

Script-backed pages include a small inline watchdog after the main module tag. The watchdog retries a failed module load with bounded jittered backoff. If retries fail, it replaces the loading state with a visible error state. The main module marks the page as booted, so a retry or duplicate load does not run the challenge twice.

This recovery path depends on the page keeping the main script, error message, status, and progress elements together. The page test checks that methods which use the shared main module provide those markers.

References: lib/…/bootstrap.go• L15-27 lib/…/bootstrap.mjs• L28-38 web/…/main.ts• L6-16 lib/challenge_page_test.go• L15-73

Localization

Localization gives the server and browser a common language for the challenge page. The server loads bundled message files and selects a language from Accept-Language, with base-language matching and English fallback. A forced language can replace request negotiation.

The selected language becomes the HTML lang value. Browser code uses that value to fetch the matching static JSON catalog, then falls back to English or to message keys if the catalog cannot load. This split keeps the first page usable before the client catalog arrives while allowing status and error messages to change in the browser.

Translation catalogs

The localization package embeds the source catalogs for server rendering. The web asset build copies those catalogs into the static web tree so browser code can fetch them at the same base-prefixed path as the other assets. The manifest describes supported languages and is metadata rather than a translation catalog.

The explanation block is a controlled exception to plain text. It escapes translated content and restores only safe Wikipedia links, so translators can include the intended reference without turning translated text into arbitrary page markup.

References: lib/…/localization.go• L15-16 lib/…/localization.go• L33-65 lib/…/localization.go• L82-111 web/index.templ• L14-22 web/…/main.ts• L27-82 lib/…/explanation.go• L10-20 lib/…/explanation.templ• L5-14 web/build.sh• L38-40

OpenGraph metadata

OpenGraph metadata lets a challenge response carry link-preview information for the protected target when the feature is enabled. Before the method page is wrapped, the server asks the OpenGraph cache for tags using the request URL and host. The fetch keeps the public host available to name-based target sites even when a separate target host selects the connection. The shared shell emits each returned tag as a meta property; the page remains noindex,nofollow.

Configuration controls whether tags are fetched, whether the host is part of the cache choice, how long values live, and which override values apply. An override must include og:title when overrides are used. If tag lookup fails, the server logs the failure and continues to render the challenge page without those tags. Tests cover non-HTML responses, failed requests, size limits, and the distinction between the target host and the public host sent to the target site.

References: lib/http.go• L327-336 lib/http.go• L380-395 web/index.templ• L17-22 lib/…/opengraph.go• L15-50 lib/config.go• L156-166 internal/…/fetch.go• L21-53 internal/…/fetch_test.go• L17-195

Static asset bundling

Static delivery uses one embedded file system as the runtime source for browser assets. The web package embeds its static tree, and the server mounts that tree below the configured base prefix. Challenge pages build URLs with the same prefix and add the application version as a cache-busting query value.

The build steps turn TypeScript and TSX sources into browser modules. The main challenge bundle includes algorithm workers and browser support code. The Preact bundle is built into a file that the page embeds inline, while the shared bootstrap is embedded directly by its challenge-page package. WASM challenge setup reads the selected algorithm module from the embedded static tree so the server and browser use the same packaged asset set.

Asset URL contract

Every page asset must work with an empty base prefix and with a mounted prefix. The server registers the static route with that prefix and strips it before serving the embedded file. A broken prefix or missing generated file can leave a page in its loading state even when the HTML response is correct.

The common web build also creates compressed variants for the generated modules. The HTTP layer can then serve the static tree through its normal cache and compression path without requiring a separate asset service.

References: web/embed.go• L7-10 lib/config.go• L174-194 lib/http.go• L457-464 web/build.sh• L38-55 lib/…/build.sh• L41-49 lib/…/preact.go• L20-36 lib/…/wasm.go• L31-45

Delivery flow

The delivery flow connects policy evaluation to a browser page and then to the challenge runtime.

flowchart TD
    A[Request needs a challenge] --> B[Issue challenge record]
    B --> C[Select registered method]
    C --> D[Render method page fragment]
    D --> E[Add extensions and shared shell]
    E --> F[Add language and optional OpenGraph tags]
    F --> G[Serve HTML and embedded assets]
    G --> H[Browser reads JSON state]
    H --> I[Load translations and client bundle]
    I --> J[Compute or wait for challenge result]
    J --> K[Redirect to pass endpoint]

The server keeps the initial response meaningful without relying on client code. The browser then enriches that response with localization, progress, challenge work, and the final redirect. The resulting contract is shared by the standard runtime and the smaller method-specific pages.

References: lib/http.go• L315-395 web/index.templ• L12-72 web/…/main.ts• L90-110 lib/…/app.tsx• L24-86

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the JSON field names in web/index.templ and web/…/main.ts aligned. Keep the separate preact_info fields aligned with lib/…/app.tsx.
  • Keep anubis.BasePrefix in page URLs, static route mounting, browser locale fetches, and redirect URLs aligned.
  • When adding or renaming a browser translation key, update the embedded catalogs and the copied web/static/locales output.
  • When changing the shared challenge DOM, check the bootstrap watchdog markers and the selectors used by web/…/main.ts.
  • When changing a generated bundle source, regenerate the output consumed by the embedded or static asset path.
  • When changing OpenGraph behavior, keep cache lookup, required og:title validation, and shell meta emission consistent.
  • When changing OpenGraph target selection, keep the connection host and forwarded public host distinct so name-based target sites receive the host that the user requested.

Important failure modes

TriggerConsequenceGuard
Main challenge module cannot loadThe page can remain on “Loading...” without a visible errorInline bootstrap retries the module and then shows the script-load error
Static files are built without the configured base prefixImages, modules, WASM, or locale catalogs cannot loadPage URL tests cover prefixed and unprefixed links
Browser locale catalog is missing or invalidClient status text falls back to English or raw keysClient loading falls back to English and then an empty catalog
A required challenge DOM marker is removedProgress or load recovery cannot update the pageChallenge page tests require the method-specific marker set
OpenGraph lookup failsThe challenge page has no preview tagsLookup errors are logged and page rendering continues
OpenGraph fetch uses the target host as the public hostA name-based target site can return the wrong page or tagsThe fetch forwards the original public host separately and tests cover both host values

Key files

FileWhy to read it
lib/http.goConnects challenge issuance, method rendering, extensions, OpenGraph lookup, and the shared response.
web/index.templDefines the document shell, JSON data boundary, common DOM, and metadata output.
lib/…/interface.goDefines the page-method contract and the inputs available to each method.
lib/…/bootstrap.goProvides the shared script-load recovery component.
web/…/main.tsShows the standard browser startup, translation load, challenge work, and redirect flow.
lib/…/localization.goDefines language selection and server-side fallback behavior.
web/build.shShows how browser bundles and locale assets reach the embedded static tree.
lib/challenge/preact/preact.templShows server-to-browser hydration for the Preact challenge page.
lib/challenge/wasm/wasm.templShows the standard script-backed challenge page structure.
lib/…/opengraph.goDefines the OpenGraph configuration contract and validation rules.
internal/…/fetch.goDefines how OpenGraph pages are fetched while preserving the public host context.