Wisp is in pre-release, self-hosted since GitHub suspended us. Install it, or see the changelog.

Wisp

No-JS and Tor Onion Sites

An onion service is a site that Tor Browser reaches at a .onion address, with no exit node and no TLS certificate. Tor encrypts the whole path. Visitors often run Tor Browser at its Safest level, which turns JavaScript off. They accept no third-party requests, external fonts or trackers. A Wisp app already works with JavaScript off (Pages and forms without JavaScript). This page covers what changes on an onion.

Turn it on

WISP_ONION=on HOST=127.0.0.1 WISP_SECRET=... ./my-app

WISP_ONION is on by itself when ORIGIN or SITE_URL is a .onion address, so SITE_URL=http://abcdefgh....onion is enough. WISP_ONION=off turns it off. Wisp reads it once at start. A request to a .onion Host always gets the cookie rules below. The ticket and address rules follow the switch. With on, every request gets them. With off, no request gets them. With auto and no .onion address in ORIGIN or SITE_URL, a request gets them when two things hold. Its Host is a .onion name. It comes from the machine itself or its network. So one process can serve a clearnet site and its onion twin. On AWS Lambda, auto gives them to no request: the peer comes from the event, and 127.0.0.1 is only its fallback. cx.is_onion() says which one a handler is answering.

This page assumes that the server speaks plain HTTP. An onion service needs no TLS, so do not set WISP_TLS_CERT for it. When the server has TLS or ORIGIN starts with https://, every request counts as HTTPS for cookies and OAuth. ORIGIN alone does not do this for a request to an onion Host. A named proxy that says x-forwarded-proto: http stops the HSTS header. Cookies and OAuth do not change. The scheme of an absolute link that the app builds from Host (in dev and on the onion twin) follows that header too. With ORIGIN set, the origin check passes an Origin equal to ORIGIN, and a .onion Origin that names its own Host (not on the edge). Origin: null and no Origin follow the same rules as without ORIGIN. With TLS and no ORIGIN, the origin check rejects an http:// origin, with or without an x-forwarded-proto header. With WISP_HSTS=on, the server sends HSTS to a request for an onion Host in two cases. A named proxy sends an x-forwarded-proto other than http, or no named proxy sends it and the server has TLS. An onion site (WISP_ONION=on) never sends it.

WhatOn an onion site
referrer-policyno-referrer, on pages and error pages, unless the app sets its own. No page tells another site where its visitor came from
strict-transport-securitynever, even with WISP_HSTS=on, because a browser ignores it over plain http. On any other site Wisp leaves it out when a named proxy says x-forwarded-proto: http. It also leaves it out for a .onion Host when the server has no TLS and no named proxy sends x-forwarded-proto
content-security-policyimg-src 'self' data: (no https: images), object-src 'none', and script-src 'none' for an app with no browser code (no <script>, no .js in src/lib, no custom elements, no inline script, no service worker). Its pages then do not even name wisp.js, which only improves forms and links that work whole without it. wisp::csp(..) still replaces any directive
daterounded down to the minute, because the exact second of a server's clock can identify the machine on the clearnet. A response with a max-age under a minute may look stale to a cache
Cookiesno Secure (the browser sees plain http), and SameSite=None is Lax. Tor Browser treats a .onion address as a potentially trustworthy origin. It changed how it handles secure cookies there (Tor blog, issue 21537). Wisp still sends no Secure. The answer is plain http. Wisp did not check which other clients, such as curl with torsocks, refuse a Secure cookie there. The Tor docs warn that a site that serves both http and https can leak secure cookies over its http onion (Tor docs)
x-forwarded-*, WISP_CLIENT_IP_HEADERignored. Tor adds none, so a header that claims a client address is the visitor's own. The startup log says so when you set the variable
Sitemap, feed, robots.txt, canonical and hreflanghttp://abcdefgh....onion/..., built from the .onion Host when SITE_URL is unset. Redirects, href and action in your templates are already relative
Static exporteach page carries <meta name="referrer"> and a <meta http-equiv="Content-Security-Policy">, and _headers (every export writes it) has the same as headers, for a host that adds none

Wisp sends no Server, X-Powered-By or Via header. It sets no cookie unless your code does. It loads nothing from another site, because the built-in error page and styles are inline and local. Keep your own fonts on your origin too. Use src/fonts.txt with a local file, or Open_Sans google ..., which downloads once at build and serves from your origin. Do not use cdn lines or URLs. The policy of an onion site ignores the origins that the build found. Do the same for images and scripts. CSP refuses the rest. With scripts = false, the build also checks this (No Script at All).

Paths That Show a Wisp App

A visitor can ask for these paths. Each one shows that the site runs Wisp. Wisp itself sends no Server, X-Powered-By or Via header on any of them.

PathWhat it returns
/_wisp/health200 with the body ok, to anyone. 503 with stopping once the server stops. Behind Tor every client is local, so a rule for local clients does not help.
/_app/wisp.jsThe browser runtime, as JavaScript. With scripts = false the path still answers. Only the pages stop naming it.
/_app/live.jsThe live runtime, as JavaScript.
/_app/c/queue.jsThe queue script, as JavaScript.
/_wisp/metricsOnly with METRICS_KEY set. A request without the right Authorization: Bearer header gets 401 and www-authenticate: Bearer. With no METRICS_KEY, the app answers (usually 404).
/_wisp/live/<table>The event stream of a table. It answers GET and HEAD when the table exists.
/_wisp/docs, /_wisp/openapi.json, /_wisp/client.tsOnly with WISP_API_DOCS=on (on by default in wisp dev) and an app that has an OpenAPI spec. The API docs, the OpenAPI spec and the TypeScript client. A request-only edge build has no /_wisp/docs.

wisp dev also answers other /_wisp/ paths, /_app/wisp-dev.js, /_app/wisp-ui.css and /_app/wisp-dialog.css. A debug build in wisp dev also answers /_app/wisp-devtools.js. A release build answers none of them. Sources: internal() in crates/wisp/src/http/files.rs, answer() in crates/wisp/src/health.rs, serve() in crates/wisp/src/obs.rs and the WISP_API_DOCS switch in crates/wisp/src/env.rs.

Wisp has no setting to hide /_wisp/health. The before hook does not run for /_wisp/ paths.

No Script at All

An onion app with no browser code already names no script. To make that a promise on any site, clearnet too, put this in Cargo.toml:

[package.metadata.wisp]
scripts = false

No page then names wisp.js, baked pages included, and the policy is script-src 'none'. Forms post and redirect. Errors come back with the text that the visitor typed. Links page and search. The build stops and names each thing that needs a script. These are on:, {:state}, <script>, an island, a .js file in src/lib, a custom element and a service worker. wisp dev keeps its own reload script.

The build also refuses what the browser loads from another host. The lint onion-fetch is an error with scripts = false. It reads these:

  • src, srcset, poster and <object data> of a tag, and <link href> for a stylesheet, preload, icon, manifest, preconnect or dns-prefetch.
  • CSS url() and @import, in a .css file, a <style> block and a style attribute.
  • A line of src/fonts.txt with cdn or a URL on another host.

It reads the shell, the templates, the Markdown pages, fonts.txt and the CSS in src and static. A URL names another host when it starts with //, or with http: or https: in any case. The lint does not find these:

  • A relative URL, a data: URL, and a URL that starts with a hole (${base}/a.png).
  • A plain <a href>, a comment, and the code of a Markdown page.

The lint does not scan these. Each can load a file from another host or send the visitor away. Check them by hand:

  • A <base href> to another host. Every relative URL on the page then loads from that host.
  • A <meta http-equiv="refresh">.
  • A static/*.html file, a static/*.svg file and any other .svg file. Under static/, the lint reads only .css files.
  • A URL that uses character references, for example &#104;ttp://.
  • image-set() in CSS.
  • A Tailwind class such as bg-[url(...)] in a template.
  • The props of a component call, such as <Card src="https://...">.
  • The content/ folder and the files of an extended layer.
  • A template that wisp dev swaps in. The build lints it, but the swap does not.

To fix a finding of onion-fetch, write a path, and put the file in static/.

A form that posts to another host is a navigation, not a fetch. The lint onion-form warns about it, because the visitor leaves the onion. To change a level, set onion-fetch, onion-form or the group onion in [package.metadata.wisp.lint] (Lint levels).

examples/nojs is such an app. Its tests run every page and form with no script, also in a real browser with Browser::scripts(false). They check that no header, page or stylesheet names another site.

With Tor on the same machine

wisp deploy init tor

writes deploy/tor/torrc, the lines below for /etc/tor/torrc, and deploy/tor/my-app.env, the environment file below with WISP_ONION=on. It prints the steps. No container is needed. --force replaces the files. On Unix the env file has mode 0600 from its first write, because it holds WISP_SECRET. The command refuses a file that is a symbolic link.

Tor connects to your app on the loopback address. Bind to it so nothing on the network can bypass Tor:

# /etc/tor/torrc
HiddenServiceDir /var/lib/tor/my-app/
HiddenServicePort 80 127.0.0.1:3000
sudo systemctl reload tor
sudo cat /var/lib/tor/my-app/hostname

Run the app as a service as in Host on a VPS (wisp service install --user my-app --port 3000), with this environment file:

# /etc/my-app.env
HOST=127.0.0.1
PORT=3000
WISP_ONION=on
WISP_SECRET=<32 or more random characters>
SITE_URL=http://abcdefgh....onion

The hostname file is the address and hs_ed25519_secret_key beside it is the identity. Back them up and never publish the key. If you lose the key, you lose the address.

The torrc file also lists the options of the Tor DoS page as comments. Remove the # of a line to turn it on:

  • HiddenServiceEnableIntroDoSDefense 1 limits the introduction requests at the introduction points.
  • HiddenServiceMaxStreams N limits the streams of each rendezvous circuit (65535 at most). Replace N first. With HiddenServiceMaxStreamsCloseCircuit 1, tor tears down a circuit that goes over N.
  • HiddenServicePoWDefensesEnabled 1 makes a flood of clients pay in computation. C Tor 0.4.8.1-alpha and later has it by default. tor --list-modules shows pow: yes when your tor has it. The client puzzle needs a tor built with --enable-gpl. Tor does the work, and Wisp has no proof-of-work code.

A private site lists its readers' public keys under authorized_clients/.

Over a Unix socket

wisp deploy init tor --unix

The Tor docs call a Unix socket good practice, because it keeps the onion service from leaking to a local network (Tor docs). The default stays a local port. With --unix, torrc has HiddenServicePort 80 unix:/run/my-app/app.sock, and deploy/tor/my-app.env has WISP_LISTEN=unix:/run/my-app/app.sock in place of HOST and PORT (WISP_LISTEN). The command also writes deploy/tor/my-app-unix.conf, a systemd drop-in:

[Service]
RuntimeDirectory=my-app
RuntimeDirectoryMode=0750
Group=debian-tor
UMask=0007

Tor needs write permission on the socket file (unix(7)). systemd makes /run/my-app for the app and gives it to the user and group of the unit (systemd.exec). debian-tor is the group of Tor on Debian. Copy the file to /etc/systemd/system/my-app.service.d/unix.conf before wisp service install --name my-app --user my-app. The unit then runs in the group of Tor, and the files that the app writes have no access for other users.

The tor options above do not change. Two things differ from a port:

  • Every peer of a Unix socket reads as 0.0.0.0. Wisp counts that address as local, so a request with a .onion Host is still an onion request, and RATE_LIMIT and cx.limit still count by ticket.
  • A WebSocket upgrade does not work on a Unix socket. After the 101, the server logs WebSockets need a TCP listener, not WISP_LISTEN=unix: and closes the connection. An app with a WebSocket route needs the default port.

In Docker

wisp deploy init docker --onion
WISP_SECRET=... docker compose up -d
docker compose exec tor cat /var/lib/tor/hidden_service/hostname

This writes the usual Dockerfile (with WISP_ONION=on), a docker-compose.yml with the app and a Tor service, tor.Dockerfile and torrc. It publishes no port to the host, so only Tor reaches the app. Keep the tor-keys volume (the address) and the data volume (your saved tables). The command keeps existing files unless you pass --force. It refuses a file that is a symbolic link.

As Static Files

A site with no forms can be plain files behind any web server.

SITE_URL=http://abcdefgh....onion wisp build --static --out dist

Serve dist/ from nginx or Caddy on 127.0.0.1:8080 and point HiddenServicePort 80 127.0.0.1:8080 at it. A static host adds none of the headers that a running app adds. The pages carry the referrer and CSP as <meta> tags, and dist/_headers lists the headers to copy into the server's config.

server {
    listen 127.0.0.1:8080;
    root /srv/site/dist;
    server_tokens off;
    add_header Content-Security-Policy "default-src 'self'; script-src 'none'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'" always;
    add_header Referrer-Policy "no-referrer" always;
    add_header X-Content-Type-Options "nosniff" always;
}

nginx and Caddy date every answer to the second, and their Server header is the first thing a scanner reads. A running Wisp app is the safer choice.

No Client Address

Tor gives your app no client address. cx.client_ip() is the TCP peer: the Tor daemon, so 127.0.0.1 when it runs on the same host. It is the same for everyone. A rate limit keyed by it is one shared bucket, and one visitor can empty it for all. RATE_LIMIT and cx.limit count by cx.visitor() instead. Behind Tor, this is a signed ticket cookie that each visitor carries. The whole site's allowance sits on top, because tickets cost nothing to make (Security). For a key of your own, limit by what the request is for:

static LOGINS: RateLimit = RateLimit::per_minute(30);

#[action]
fn login(name: String) -> Result {
    LOGINS.check("login")?; // all visitors share it: a ceiling, not a fairness rule
    ...
}

Or limit by account (LOGINS.check(&name)?), which stops password guessing against one account from anywhere. Tor can also pass a circuit identifier with HiddenServiceExportCircuitID haproxy, which needs the PROXY protocol. Wisp does not read it, because that would add work to every connection. To count each circuit on its own, put HAProxy in front and let it set X-Forwarded-For, as Runtime and build shows. This needs WISP_ONION=off. With on, or with an onion ORIGIN or SITE_URL, Wisp ignores WISP_CLIENT_IP_HEADER and logs that it does. With auto, a client address that differs from the peer ends the onion rules for that request.

Forms Without Referer or Origin

Tor Browser strips Referer, and a page with no-referrer makes the browser send Origin: null with its own form posts. Wisp's form check accepts Origin: null with Sec-Fetch-Site: same-origin, which a page on another site cannot fake. It also accepts it when the request has no Sec-Fetch-Site and carries the valid token of a <form guard>. The token case works on native only. A POST with a foreign Origin, or null with any other case, is still a 403.

The Clearnet Twin

A site at https://example.com that also has an onion can tell Tor Browser. Tor Browser then offers the visitor the onion address of the current page:

WISP_ONION_LOCATION=abcdefgh....onion ./my-app

Every successful GET or HEAD answer then carries onion-location: http://abcdefgh....onion/the/same/path?query. Tor Browser acts on it over https only. For one route, cx.onion_location("abcdefgh....onion") in before or a page does the same. A request that came over the onion gets none. A value that is not an onion address stops the server at start (WISP_ONION_LOCATION). For cx.onion_location, Wisp drops the value and logs it. The twin's sitemap and canonical links stay on the onion when its own Host is the one named here, and never take a Host an attacker picks.

More

Pages and forms without JavaScript, Environment variables, Serve extras, Host on a VPS, Docker.

Is This Page Useful?

View This Page's Source

Type to search every docs page and heading.