Dynamic Tags in Pages (tag_proxyauth)
This page explains ProxyAuth's {{ username }}/{{ csrf_token }}/{{ proxyauth_version }}/{{ proxyauth_id }} tag substitution — a general-purpose mechanism, gated per route by tag_proxyauth: true, that applies to static files, proxied backend responses, and the shared error/logout page alike. {{ error }} (error pages only) has its own, older mechanism that predates tag_proxyauth and works independently of it. {{ csrf_token }} is a special case covered in its own row below: it needs CSRF itself enabled (tag_csrf_token) everywhere, on top of whatever else gates it. This page covers all four tags together since they share one substitution pass wherever tag_proxyauth is on.
The four tags
| Tag | Resolves to | Available when |
|---|---|---|
{{ username }} |
The signed-in visitor's username, from a valid session_token cookie or Authorization: Bearer token — checked independently of whether the current route actually requires login, so a public page can still greet an already-logged-in visitor. Left as the literal tag text if nobody's signed in. |
tag_proxyauth: true |
{{ csrf_token }} |
A freshly generated, signed CSRF token — the same one /auth submissions are checked against. Left untouched (not blanked) whenever CSRF itself is off (see below), regardless of tag_proxyauth. |
Static files and proxied responses: tag_proxyauth: true and tag_csrf_token resolving to enabled (its own vhost override, or the global csrf_token). Error pages: session_cookie + tag_csrf_token both on — its own older mechanism, independent of tag_proxyauth there — see Error Pages: How Templating & Injection Work. |
{{ proxyauth_version }} |
The running build's version (CARGO_PKG_VERSION). |
tag_proxyauth: true |
{{ proxyauth_id }} |
The running build's instance ID. | tag_proxyauth: true |
Both a spaced ({{ username }}) and unspaced ({{username}}) form are recognized for every tag.
A tag with no available value — {{ username }} on a page nobody's signed into — is left exactly as-is in the output, unreplaced. This is deliberate: silently substituting an empty string would look like a blank-rendering bug, whereas the literal tag text is an honest, debuggable signal that the value just wasn't available for this particular request.
<p>Signed in as {{ username }}</p>
<footer>ProxyAuth {{ proxyauth_version }} (build {{ proxyauth_id }})</footer>
<form method="POST" action="/auth">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
</form>
tag_proxyauth: why it's opt-in
- prefix: "/"
static: "/var/www/app/"
static_index: "login.html"
tag_proxyauth: true
Off by default, and — unlike most per-route settings — not inherited-then-defaulted-on anywhere: a route or vhosts: group has to explicitly set tag_proxyauth: true for any of this to run. Substitution means reading the whole response body as text and scanning it, on every matching request; a route that doesn't use any of these tags shouldn't pay that cost for nothing. Turn it on for exactly the routes whose content actually uses them — typically your login page, and any other page that shows {{ username }} or the build info.
Only text/html responses are scanned — anything else (images, JSON, binary downloads) is left untouched even with tag_proxyauth: true, since these tags only make sense inside HTML.
Where substitution applies
| Response type | Applies when |
|---|---|
Static files (static/static_index) |
The matched route has tag_proxyauth: true. Both single-file and directory-index modes. |
| Proxied backend responses | The matched route has tag_proxyauth: true. Runs after CSRF injection (if that's also on), so both can apply to the same response. |
The shared error/logout page (render_error_page) |
Same tag_proxyauth: true check, on whichever route logout_redirect_url's path resolves to for the current vhost — see Error Pages: How Templating & Injection Work for that page's own flow. {{ error }} is available there regardless of tag_proxyauth (its own, older mechanism). {{ csrf_token }} there is also independent of tag_proxyauth specifically, but still needs tag_csrf_token (CSRF itself) enabled. {{ username }}/{{ proxyauth_version }}/{{ proxyauth_id }} need tag_proxyauth on. |
Admin endpoints (/adm/*) |
Never — these return JSON, not HTML pages. |
Practical example
The scenario this was built for: a login page served entirely as static files, no backend behind it at all.
vhosts:
- vhost: ["app.example.com"]
login_redirect_url: "/app"
routes:
- prefix: "/"
static: "/var/www/app/public/"
static_index: "login.html"
tag_proxyauth: true
- prefix: "/app"
static: "/var/www/app/secret/index.html"
required_login: true
login.html:
<!DOCTYPE html>
<html>
<body>
<p>{{ username }}</p>
<form method="POST" action="/auth">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<button type="submit">Sign in</button>
</form>
<footer>v{{ proxyauth_version }}</footer>
</body>
</html>
For a first-time, not-yet-signed-in visitor: {{ username }} is left as literal text (nobody to greet), {{ csrf_token }} is filled in with a real token so the login form actually works, {{ proxyauth_version }} resolves normally regardless of login state.
See also
- routes.yml Reference § Dynamic tags — the
tag_proxyauthfield itself. - Error Pages: How Templating & Injection Work —
{{ error }}/BEGIN_BLOCK_ERROR, and how this all fits into the login-failure flow specifically. - CSRF Protection — the token format
{{ csrf_token }}produces, and how it's validated on submission. - routes.yml Reference § Vhost login authorization —
allow_users/allow_groups/allow_roles/exclude_users, unrelated to tags but often configured on the same login-page vhost.
📖 Wiki Home · 💻 Source Code · 🐛 Report an Issue · 📜 License
Found an error or something outdated on this page? Open an issue or submit a PR against the wiki repository.