- Refuse non-GET requests whose Origin (or Sec-Fetch-Site) is not the apex or www. SameSite=Lax lets sibling subdomains such as radar. and git. send the auth cookies. The WebSocket check shares the helper and no longer accepts localhost in production. - Take the admin flag from the user row the token check already loads, so a demotion applies on the next request, not on token expiry. - Cut the refresh token lifetime from 365 to 90 days; refreshes renew it. - Docs: fix the stale revocation notes in backend/README.md and the Cloudflare Access comment in routes.caddy. Co-Authored-By: Claude Opus 5.5 <[email protected]>
299 lines
7.8 KiB
Plaintext
299 lines
7.8 KiB
Plaintext
# The route table for both modes, imported inside a `route` block: the first
|
|
# matching handle wins, so denials go first and each carve-out precedes the
|
|
# prefix it is carved from. `path` is case-insensitive on the cleaned path;
|
|
# path_regexp is case-sensitive, hence (?i). caddy/edge_test.sh checks these.
|
|
# A gated route that loses its gate import is open to the internet.
|
|
|
|
# An inner limit cannot raise an outer one, so garage-webui's 2 GB is carved out here.
|
|
@body_default not path /garage/*
|
|
request_body @body_default {
|
|
max_size 50MB
|
|
}
|
|
|
|
# ---- Denials -----------------------------------------------------------------
|
|
|
|
# Called by the backend over app-network only; spends paid Claude calls.
|
|
handle /py/internal/* {
|
|
respond 404
|
|
}
|
|
|
|
# SB_SPACE_IGNORE only hides paths from listings, so these block direct
|
|
# fetches: private/ or templates/ at any depth, any dot-segment below the
|
|
# first (SilverBullet's own endpoints live at the first), and revisions.
|
|
# Keep the folder list in step with silverbullet-public's SB_SPACE_IGNORE.
|
|
# 404, not 403, so a private path's existence isn't confirmed.
|
|
@notes_private path_regexp (?i)^/notes/(.*/)?(private|templates)(/|$)
|
|
handle @notes_private {
|
|
respond 404
|
|
}
|
|
|
|
@notes_dot path_regexp ^/notes/.+/\.
|
|
handle @notes_dot {
|
|
respond 404
|
|
}
|
|
|
|
handle /notes/.revisions* {
|
|
respond 404
|
|
}
|
|
|
|
# ---- Bare prefixes and moved URLs ----------------------------------------------
|
|
# Exact paths, so /gitea-something is left to the SPA.
|
|
redir {$BACKEND_ENDPOINT} {$BACKEND_ENDPOINT}/ 301
|
|
redir /radio /radio/ 301
|
|
redir /dozzle /dozzle/ 301
|
|
redir /garage /garage/ 301
|
|
redir /gitea https://git.{$DOMAIN}/ 301
|
|
redir /notes /notes/ 301
|
|
redir /sb https://priv.{$DOMAIN}/sb/ 301
|
|
redir /py /py/ 301
|
|
redir /jobs https://priv.{$DOMAIN}/jobs/ 301
|
|
redir /usaco /usaco/ 301
|
|
redir /tracker /tracker/ 301
|
|
redir /receipt /receipt/ 301
|
|
|
|
# Old job tracker URLs; the userscript's old @updateURL finds its update here.
|
|
redir /cv/jobs https://priv.{$DOMAIN}/jobs/ 301
|
|
redir /cv/leads https://priv.{$DOMAIN}/jobs/leads 301
|
|
redir /job-capture.user.js https://priv.{$DOMAIN}/jobs/job-capture.user.js 301
|
|
|
|
# ---- Backend API ---------------------------------------------------------------
|
|
|
|
# Not rate limited: a limit would only drop reconnect storms.
|
|
handle {$BACKEND_ENDPOINT}/ws* {
|
|
uri strip_prefix {$BACKEND_ENDPOINT}
|
|
reverse_proxy {$BACKEND_HOST}:{$BACKEND_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# stppriv's admin_gate checks every one of its requests here from one LAN IP,
|
|
# so it would exhaust the per-IP api limit. Public traffic always arrives from
|
|
# cloudflared, so it can never match.
|
|
@stppriv_gate {
|
|
path {$BACKEND_ENDPOINT}/auth/validate-admin
|
|
remote_ip {$STPPRIV_LAN_IP}
|
|
}
|
|
handle @stppriv_gate {
|
|
uri strip_prefix {$BACKEND_ENDPOINT}
|
|
reverse_proxy {$BACKEND_HOST}:{$BACKEND_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# On top of the backend's own 5/min.
|
|
handle {$BACKEND_ENDPOINT}/auth/login* {
|
|
import limit login 5 1m
|
|
uri strip_prefix {$BACKEND_ENDPOINT}
|
|
reverse_proxy {$BACKEND_HOST}:{$BACKEND_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
handle {$BACKEND_ENDPOINT}/uploads* {
|
|
import limit upload 30 1m
|
|
uri strip_prefix {$BACKEND_ENDPOINT}
|
|
reverse_proxy {$BACKEND_HOST}:{$BACKEND_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# One GraphQL query can be arbitrarily expensive.
|
|
handle {$BACKEND_ENDPOINT}/graphql* {
|
|
import limit graphql 10 1s
|
|
uri strip_prefix {$BACKEND_ENDPOINT}
|
|
reverse_proxy {$BACKEND_HOST}:{$BACKEND_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
handle {$BACKEND_ENDPOINT}/* {
|
|
import limit api 30 1s
|
|
uri strip_prefix {$BACKEND_ENDPOINT}
|
|
reverse_proxy {$BACKEND_HOST}:{$BACKEND_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# ---- Admin-gated services ------------------------------------------------------
|
|
|
|
# Docker socket access is root on the host.
|
|
handle /dozzle/* {
|
|
import admin_gate
|
|
reverse_proxy dozzle:8080 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# garage-webui on stpcore, behind its Caddy, which wants X-Core-Token (header_up
|
|
# replaces any client-sent one). Holds Garage's admin token. 2 GB for video
|
|
# uploads. A `route` so garage_upstream is set only after the gate passes.
|
|
handle /garage/* {
|
|
route {
|
|
import admin_gate
|
|
request_body {
|
|
max_size 2GB
|
|
}
|
|
vars garage_upstream yes
|
|
reverse_proxy garage:3909 {
|
|
import proxy
|
|
header_up X-Core-Token {env.GARAGE_WEBUI_TOKEN}
|
|
transport http {
|
|
dial_timeout 3s
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# Station-control UI guarded only by the icecast password.
|
|
handle /radio/admin/* {
|
|
import admin_gate
|
|
uri strip_prefix /radio
|
|
reverse_proxy {$ICECAST_HOST}:{$ICECAST_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# The notes editor is on stppriv, behind its admin gate.
|
|
handle /sb/* {
|
|
redir https://priv.{$DOMAIN}{uri} 301
|
|
}
|
|
|
|
# ---- Public services -----------------------------------------------------------
|
|
|
|
handle /radio/* {
|
|
uri strip_prefix /radio
|
|
reverse_proxy {$ICECAST_HOST}:{$ICECAST_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# Gitea is at git.DOMAIN; the registry at /v2/ is still proxied (prod.caddy).
|
|
handle_path /gitea/* {
|
|
redir https://git.{$DOMAIN}{uri} 301
|
|
}
|
|
|
|
# No prefix strip (SB_URL_PREFIX=/notes).
|
|
handle /notes/* {
|
|
reverse_proxy {$SILVERBULLET_PUBLIC_HOST}:{$SILVERBULLET_PUBLIC_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# Minutes-long searches with one slot on the Python side, so the limit is
|
|
# really concurrency protection. flush_interval passes NDJSON lines straight on.
|
|
@hotels path_regexp ^/py/hotels/(search|scan)
|
|
handle @hotels {
|
|
import limit hotel_search 3 1m
|
|
uri strip_prefix /py
|
|
reverse_proxy {$PYTHON_HOST}:{$PYTHON_PORT} {
|
|
import proxy
|
|
flush_interval -1
|
|
}
|
|
}
|
|
|
|
handle /py/* {
|
|
import limit api 30 1s
|
|
uri strip_prefix /py
|
|
reverse_proxy {$PYTHON_HOST}:{$PYTHON_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# ---- Job tracker (/jobs/) ----
|
|
# On stppriv. A 301 turns a POST into a GET, so capture clients must call
|
|
# priv. directly.
|
|
handle /jobs/* {
|
|
redir https://priv.{$DOMAIN}{uri} 301
|
|
}
|
|
|
|
# ---- USACO (/usaco/) ----
|
|
# Not stripped, not gated: the app checks the session for admin edits. The
|
|
# Gitea webhook arrives here, signed with USACO_WEBHOOK_SECRET.
|
|
handle /usaco/* {
|
|
import limit api 30 1s
|
|
reverse_proxy usaco:8080 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# ---- Activity tracker (/tracker/) ----
|
|
# The collector API (bearer keys) and the userscript bypass the gate.
|
|
# Collectors must use www: the apex 301 turns POSTs into GETs.
|
|
handle /tracker/api/v1/* {
|
|
import limit api 30 1s
|
|
uri strip_prefix /tracker
|
|
reverse_proxy activity-tracker:8080 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
handle /tracker/tracker.user.js {
|
|
uri strip_prefix /tracker
|
|
reverse_proxy activity-tracker:8080 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
handle /tracker/* {
|
|
import admin_gate
|
|
import limit api 30 1s
|
|
uri strip_prefix /tracker
|
|
reverse_proxy activity-tracker:8080 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# ---- Receipt printer (/receipt/) ----
|
|
# Runs on stppi (it is on the printer's LAN), reached over Tailscale.
|
|
# header_up replaces any client-sent X-Receipt-Token. A `route` so the
|
|
# receipt_upstream var is set only after the gate passes, so a backend outage
|
|
# is not reported as "printer offline". 17 MB: 16 MB uploads plus framing.
|
|
handle /receipt/* {
|
|
route {
|
|
import limit receipt 10 1s
|
|
request_body {
|
|
max_size 17MB
|
|
}
|
|
import permission_gate receipt
|
|
vars receipt_upstream yes
|
|
uri strip_prefix /receipt
|
|
reverse_proxy {$RECEIPT_WEB_UPSTREAM} {
|
|
import proxy
|
|
header_up X-Receipt-Token {env.RECEIPT_WEB_TOKEN}
|
|
# Fail fast when stppi is off.
|
|
transport http {
|
|
dial_timeout 3s
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# ---- Uploads (/uploads/) ----
|
|
|
|
# Private chat attachments, always on disk. Must precede /uploads/*.
|
|
handle /uploads/private/* {
|
|
import admin_gate
|
|
import upload_headers
|
|
root * /srv
|
|
file_server
|
|
}
|
|
|
|
# Garage (on stpcore) first, disk second: a 404, 5xx or dial error falls back
|
|
# to the volume, so the bucket is the source of truth.
|
|
handle /uploads/* {
|
|
import upload_headers
|
|
vars uploads_fallback yes
|
|
uri strip_prefix /uploads
|
|
reverse_proxy garage:3902 {
|
|
import proxy
|
|
header_up Host uploads.web.garage
|
|
transport http {
|
|
dial_timeout 2s
|
|
}
|
|
@not_in_bucket status 404 5xx
|
|
handle_response @not_in_bucket {
|
|
import uploads_disk
|
|
}
|
|
}
|
|
}
|