Repository navigation
Expand file tree
/
Copy pathnginx.example.conf
More file actions
85 lines (81 loc) · 4.72 KB
/
Copy pathnginx.example.conf
File metadata and controls
85 lines (81 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# =============================================================================
# Autonomous Loop Studio — nginx guard (storage + dev tooling)
# =============================================================================
#
# nginx does NOT read .htaccess, so the storage/.htaccess and tests/.htaccess
# that ship with the app do nothing here. Without the rules below, a default
# nginx config will happily serve:
#
# https://yoursite/router/storage/config.json <- access token + API keys
# https://yoursite/router/storage/state.json <- agents, allow/deny lists
# https://yoursite/router/storage/sessions/*.json <- conversation history
# https://yoursite/router/tests/js/run.mjs <- dev tooling, not runtime
#
# And the same again for any SECOND copy of the app kept inside the web root --
# a backup, an archive of an older version, a folder dropped in for reference:
# each one brings its own storage/ with the same keys in it, so the rules below
# match those folder names at any depth, not only directly under /router/:
#
# https://yoursite/router/old-copy/storage/config.json
# https://yoursite/router/the-copy-before-the-huge-ui-change/storage/config.json
#
# Drop these `location` blocks inside the server{} that serves the app (or
# inside the `location /router/ { ... }` block), then: nginx -t && systemctl
# reload nginx.
#
# The strongest fix is to keep storage/ OUTSIDE the document root. If the app
# must live in the docroot (the one-folder design), the rules below are
# mandatory.
# -----------------------------------------------------------------------------
# 1) Never expose runtime data, secrets, or dev-only tooling -- as ANY path
# segment, at any depth. `tests` is not runtime code (serve.php and
# tests/.htaccess already refuse it), but the guard belongs in every serving
# mode, not just the two that read .htaccess.
#
# The `(.+/)?` is what covers a nested copy of the app. This file used to
# anchor on `^/router/(storage|...)/`, which refused the real folder and left
# `/router/<any copy>/storage/config.json` wide open -- the same token and
# keys, one folder down. `~*` makes it case-insensitive, matching the check in
# serve.php, so a case variant cannot slip past on a case-insensitive disk.
# It also covers the bare folder with or without a trailing slash, and a file
# whose NAME merely contains one of these words is not touched
# (/router/ui/js/tests.js and /router/ui/.../storage.js stay served).
#
# API routes are exempt (`(?!api/)` after the prefix): they are endpoints, not
# files. The UI asks for /router/api/sessions to list sessions, and a rule that
# matched that name broke the sidebar. No API route maps onto a path on disk --
# the handlers open storage/ themselves, server-side.
location ~* ^/router/(?!(?:.*/)?api/)(?:.+/)?(storage|logs|tmp|sessions|tests)(/|$) {
deny all;
return 404; # 404 (not 403) so the folder's existence isn't confirmed
}
# 2) Never serve dotfiles (.htaccess, .git, .env, .htpasswd, ...) anywhere.
# `well-known` is left open for ACME / Let's Encrypt challenges.
location ~ /\.(?!well-known) {
deny all;
return 404;
}
# 3) Never serve loose data files, even if they land outside storage/ (a stray
# backup, an export, a php.ini, a key). The API's own JSON does not use a
# .json URL, so this blocks files only, never an endpoint. `.*` already spans
# subdirectories, so a nested copy's config.json is caught here too even if its
# folders were renamed to something rule 1 does not name.
location ~ ^/router/.*\.(json|log|ini|bak|old|sql|key|pem)$ {
deny all;
return 404;
}
# 4) Never cache the HTML entry points (JS/CSS already carry ?v= cache busters).
# nginx ignores .htaccess AND the <meta http-equiv> tags in the pages, so
# without this a deploy ships new modules while the browser keeps showing
# yesterday's page around them (e.g. Config without the Speech section).
# This block is a COMMENT on purpose: nginxGuards.test.php treats every
# `location ~` as a deny rule, so an active regex location here would read as
# "index.html is refused" and fail. Paste this INSIDE the server{} that
# serves the app (or inside `location /router/ { ... }`):
#
# location = /router/ { expires 0; add_header Cache-Control "no-store, no-cache, must-revalidate" always; }
# location = /router/index.html { expires 0; add_header Cache-Control "no-store, no-cache, must-revalidate" always; }
# location = /router/ui/index.html { expires 0; add_header Cache-Control "no-store, no-cache, must-revalidate" always; }
#
# Exact-match (`=`) locations are used so nothing else can match them, and
# the guard test keeps passing because no new regex location is introduced.