Public Access

Securely expose Suwu to the public internet using a reverse proxy, wildcard host validation, password authentication, and zero-trust identity providers.

Overview

Suwu is designed for local and LAN use by default. To expose it publicly, you need four layers of defense:

  1. Bind to localhost only — the server never directly faces the internet
  2. Wildcard host validation — reject requests for unexpected hostnames
  3. Password authentication — require credentials before granting access
  4. Zero-trust access — let Cloudflare (or your proxy) handle TLS and identity

Step 1 — Server Configuration

Edit ~/.suwu/suwu.env on your server:

# Bind to localhost only — the server never touches the public internet directly.
HOST=127.0.0.1

# Allow only your domain. Supports wildcards:
#   *.mydomain.com  — matches any subdomain
#   mydomain.*      — matches any TLD
#   *               — matches everything (not recommended for public use)
EXTRA_HOSTS=*.mydomain.com

# Require a password for all API access.
AUTH_PASS=<sha256-hex-of-your-password>

# Cloudflare handles public HTTPS termination; use plain HTTP locally.
SERVER_MODE=http
HTTP_PORT=8180

Generate the password hash:

# Install shasum if needed, then:
echo -n "your-secret-password" | shasum -a 256 | awk '{print $1}'
Security note

HOST=127.0.0.1 ensures Suwu only listens on the loopback interface. Even if someone bypasses your reverse proxy, they cannot reach the server directly — there is no port exposed to the outside.

Step 2 — Reverse Proxy

You have two options depending on your TLS setup:

When using Cloudflare, TLS is terminated at the edge. Set SERVER_MODE=http in ~/.suwu/suwu.env and let Cloudflare handle certificates.

Option B — Your own certificates

If you prefer to manage TLS yourself (e.g., nginx with Let's Encrypt), use SERVER_MODE=https and provide valid certificates issued to your public-facing domain:

# In ~/.suwu/suwu.env
TLS_CERT_FILE=/etc/letsencrypt/live/mydomain.com/fullchain.pem
TLS_KEY_FILE=/etc/letsencrypt/live/mydomain.com/privkey.pem

Then configure your reverse proxy to forward to https://127.0.0.1:8181.

Step 3 — Cloudflare Zero Trust Tunnel

A Cloudflare Tunnel connects your server to Cloudflare's edge without opening any inbound ports. This is the most secure approach — your server's port 8181 is never exposed to the public internet.

Install cloudflared

# Debian / Ubuntu
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg
echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared any main" | sudo tee /etc/apt/sources.list.d/cloudflared.list
sudo apt update && sudo apt install cloudflared

# Or install the binary directly
curl -fsSL https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/local/bin/cloudflared
chmod +x /usr/local/bin/cloudflared

Authenticate and create a tunnel

# Log in to your Cloudflare account (opens browser)
cloudflared tunnel login

# Create a named tunnel
cloudflared tunnel create suwu

# Note the tunnel ID from the output

Configure the tunnel

Create ~/.cloudflared/config.yml:

tunnel: <tunnel-id>
credentials-file: /root/.cloudflared/<tunnel-id>.json

ingress:
  - hostname: terminal.mydomain.com
    service: http://127.0.0.1:8181
    originRequest:
      noTLSVerify: true
  - service: http_status:404
Why noTLSVerify: true?

When SERVER_MODE=http, the Suwu server runs plain HTTP on localhost at http://127.0.0.1:8180, so there's no TLS to verify on the origin side. Cloudflare still enforces HTTPS for all visitors.

Route DNS and run

# Route your subdomain to the tunnel
cloudflared tunnel route dns suwu terminal.mydomain.com

# Run the tunnel (or use systemd service below)
cloudflared tunnel run suwu

Run as a systemd service

# Install the service
sudo cloudflared service install

# Enable and start
sudo systemctl enable cloudflared
sudo systemctl start cloudflared

Step 4 — Access Protection

At this point, anyone who knows terminal.mydomain.com can reach your Suwu server — but they still need the password. For stronger access control, use Cloudflare's identity features.

Option A — One Time PIN (simplest)

Cloudflare sends a PIN to the visitor's email address. No identity provider setup required.

  1. Go to Cloudflare Zero Trust Dashboard → Access → Applications
  2. Click Create an application
  3. Choose Self-hosted
  4. Set the application domain: terminal.mydomain.com
  5. Under Policy, create a policy with action Allow
  6. Add a One-time PIN criterion (email domain)
  7. Save

Now when someone visits https://terminal.mydomain.com, Cloudflare challenges them with a PIN sent to their email before they ever reach your server.

Option B — Identity Provider (stronger)

Connect a social or enterprise identity provider for SSO. This is ideal for personal or team use.

Google Login example

  1. Go to Cloudflare Zero Trust Dashboard → Settings → Authentication
  2. Click Add new under Login methods
  3. Choose Google
  4. Follow the OAuth consent screen setup (requires a Google Cloud project with OAuth credentials)
  5. Once connected, go to Access → Applications → Create an application
  6. Choose Self-hosted, set domain to terminal.mydomain.com
  7. Create a policy: Allow → Emails ending in @yourcompany.com (or any Gmail)
  8. Save

Visitors are now redirected to Google login before accessing your terminal.

Double protection

With both Cloudflare access policies and Suwu's AUTH_PASS, an attacker must bypass two independent authentication layers: Cloudflare's identity check and the Suwu password. This is defense in depth.

Cloudflare Access works by cookie. Two kinds of requests can never present CF_Authorization, and behind Access they fail in ways that look like a Suwu bug:

  • PWA install assets. The browser fetches the manifest, the service worker and the home-screen icon before anyone signs in — including on a phone that has never authenticated.
  • Extension tiles. An extension page runs in a sandboxed iframe with an opaque origin (see docs/EXTENSION_API_PLAN.md). Every subresource it loads — its module scripts and CSS under /gqjs/static/<id>/ — and every fetch() it makes to its own API under /gqjs/api/<id>/ is cross-origin with credentials: same-origin, so no cookies are sent. That is deliberate: the sandbox exists so extension code cannot touch Suwu's origin.

Access answers those requests with 302 to https://<team>.cloudflareaccess.com/cdn-cgi/access/login/…. For a navigation that is survivable (the frame even shows the login page), but for a module script or a fetch it is fatal: the extension page's CSP allows only https://<your-host>/gqjs/static/<id>/, CSP checks the redirect target too, and the request is blocked. DevTools then shows the tell-tale pair:

GET https://terminal.mydomain.com/gqjs/static/hn-top-stories/app-…js   302   (blocked:csp)

The tile renders (its HTML navigation did carry the cookie) but never loads data.

Create the bypass application

Zero Trust Dashboard → Access → Applications → Add an application → Self-hosted. Give it a name, then add these paths as its application domains — one entry each, no wildcard needed:

terminal.mydomain.com/manifest.webmanifest
terminal.mydomain.com/sw.js
terminal.mydomain.com/logo.svg
terminal.mydomain.com/icons
terminal.mydomain.com/apple-touch-icon.png
terminal.mydomain.com/gqjs/static
terminal.mydomain.com/gqjs/api

Add one policy: action Bypass, include Everyone (this bypasses Access for those paths only, nothing else). Save, then allow about 30 seconds for the edge to apply it.

Why this is not a hole

/gqjs/static/<id>/* is public by design: it is client-shipped extension source, and a relative ES-module import cannot carry a token — never put secrets there. /gqjs/api/<id>/* is authorised by Suwu itself with a per-extension scoped token that can only reach that one extension's routes; the session token is rejected there. Everything else — the app shell, /api/*, /ws, /gqjs/ext/* (the extension render navigation, which does carry the cookie) — stays behind Access.

Or create it from the CLI / API

With the cf CLI (or any Cloudflare API client), a self-hosted app with a bypass policy is a single PUT to /accounts/<account-id>/access/apps/<app-id>:

{
  "name": "terminal - cookie-less paths",
  "type": "self_hosted",
  "domain": "terminal.mydomain.com/manifest.webmanifest",
  "self_hosted_domains": [
    "terminal.mydomain.com/manifest.webmanifest",
    "terminal.mydomain.com/sw.js",
    "terminal.mydomain.com/logo.svg",
    "terminal.mydomain.com/icons",
    "terminal.mydomain.com/apple-touch-icon.png",
    "terminal.mydomain.com/gqjs/static",
    "terminal.mydomain.com/gqjs/api"
  ],
  "destinations": [
    { "type": "public", "uri": "terminal.mydomain.com/manifest.webmanifest" },
    { "type": "public", "uri": "terminal.mydomain.com/sw.js" },
    { "type": "public", "uri": "terminal.mydomain.com/logo.svg" },
    { "type": "public", "uri": "terminal.mydomain.com/icons" },
    { "type": "public", "uri": "terminal.mydomain.com/apple-touch-icon.png" },
    { "type": "public", "uri": "terminal.mydomain.com/gqjs/static" },
    { "type": "public", "uri": "terminal.mydomain.com/gqjs/api" }
  ],
  "session_duration": "24h",
  "app_launcher_visible": false,
  "auto_redirect_to_identity": false,
  "enable_binding_cookie": false,
  "http_only_cookie_attribute": true,
  "allowed_idps": [],
  "skip_interstitial": false,
  "options_preflight_bypass": false,
  "policies": [
    {
      "name": "Bypass cookie-less paths",
      "decision": "bypass",
      "include": [{ "everyone": {} }],
      "exclude": [],
      "require": [],
      "precedence": 1
    }
  ]
}

Verify

From any network, without cookies, these are the answers that mean "Access is no longer in the way":

# 200 — a public extension asset
curl -s -o /dev/null -w '%{http_code}\n' \
  https://terminal.mydomain.com/gqjs/static/hn-top-stories/app-…js

# 401 — reached Suwu, which rejected the fake token (a 302 would be Access)
curl -s -o /dev/null -w '%{http_code}\n' \
  'https://terminal.mydomain.com/gqjs/api/hn-top-stories/stories?token=x'

# 200 — the manifest the installer needs before login
curl -s -o /dev/null -w '%{http_code}\n' \
  https://terminal.mydomain.com/manifest.webmanifest

# 302 — the app itself is still protected by Access
curl -s -o /dev/null -w '%{http_code}\n' https://terminal.mydomain.com/

Full Working Example

Here's a complete ~/.suwu/suwu.env for a Cloudflare Zero Trust deployment:

# ~/.suwu/suwu.env
HOST=127.0.0.1
EXTRA_HOSTS=*.mydomain.com
AUTH_PASS=a1b2c3d4e5f6...  # sha256 of your password
SERVER_MODE=http
HTTP_PORT=8180

And the corresponding Cloudflare tunnel config:

# ~/.cloudflared/config.yml
tunnel: abc123-def456
credentials-file: /root/.cloudflared/abc123-def456.json

ingress:
  - hostname: terminal.mydomain.com
    service: http://127.0.0.1:8181
    originRequest:
      noTLSVerify: true
  - service: http_status:404

Start both services:

# Start the Suwu server (via systemd or directly)
suwu daemon start

# Start the tunnel (via systemd)
sudo systemctl start cloudflared

Visit https://terminal.mydomain.com — you'll see Cloudflare's access challenge, then the Suwu password prompt, and finally your terminal.

Troubleshooting

Symptom Likely cause
403 Forbidden on /api/token EXTRA_HOSTS doesn't match the Host header your proxy sends. Check what Host the proxy forwards — it must match a pattern in EXTRA_HOSTS.
Certificate warning in browser SERVER_MODE=https is enabled, but the local certs don't match your public domain. Use SERVER_MODE=http when Cloudflare handles TLS.
Tunnel connects but 502 Bad Gateway Suwu server is not running, or the tunnel points to the wrong port. Verify with curl http://127.0.0.1:8181/api/token on the server.
Cloudflare access page not showing Access policy not applied to the application. Check Zero Trust Dashboard → Access → Applications.
An extension tile renders but never loads data; DevTools shows a 302 to cloudflareaccess.com and blocked:csp Access is intercepting /gqjs/static/* or /gqjs/api/*. Sandboxed extension frames cannot send cookies, so those paths need a Bypass application — see Step 5.
Home-screen icon is a letter tile on iOS even though the site icon is right /apple-touch-icon.png is behind Access while /icons/* is bypassed. Add it to the bypass application, then delete and re-add the home-screen icon.
DevTools shows blocked:csp for an extension script Usually the redirect above: CSP checks redirect targets, and the Access login host is not (and must not be) in the extension's script-src. Fix the bypass rather than the CSP.