nginx-proxy-manager/backend
Jamie Curnow 66ab4b24d1 Stop non-admins injecting nginx directives through host fields
advanced_config is admin-only, but other fields are written into nginx
config as-is and the schema barely limited them. A non-admin could add
any directive through them:

- location path, forward_host and forward_path (any non-empty string)
- proxy host forward_host (a quote breaks out of set $server "...")
- redirection forward_domain_name and stream forwarding_host (their
  pattern allowed ";", e.g. "example.com; return 200; #")
- access list IPv6 addresses ("%.+" zone id allowed "::1%x; allow all")
- domain names (a newline got out of the header comment)

Validation
- New lib/nginx-values.js holds the rules. Values can't contain
  characters that end or change an nginx token: whitespace, control
  characters, ; { } " ' # \, and no $ in a host. Location paths allow a
  modifier and an unquoted or double-quoted URI, so =, ~, ~* and ^~
  locations and quoted regexes keep working.
- The API schemas use the same patterns, including the certificate
  schema's own copy of the domain rule. A test fails if they drift.
- generateConfig checks stored values again, so rows saved before these
  rules can't inject either. The check is about nginx structure only:
  a stored value the API would now reject, but which can't add
  directives, still renders. If a value is unsafe, nothing is written
  and the host is marked offline with the reason in nginx_err. The same
  check covers per-location access lists and the Let's Encrypt request
  config.
- htpasswd user names can't contain ":" or control characters, which
  corrupted the file.

Fixes along the way
- IPv6 client addresses: drop zone ids, which nginx's allow/deny
  rejects anyway, and fix broken escapes (literal "d" for digits, an
  unescaped ".").
- Rewrite the domain rule used by redirection and stream hosts so it
  can't backtrack exponentially. It accepts the same values.
- Pattern errors still say "must match pattern", but no longer quote
  the regex.

Tests
- backend/test/nginx-values.test.js, run by `yarn test` and in
  scripts/ci/test-and-build. Real request schemas reject an injection
  set and accept valid values on every endpoint. Accepted values,
  rendered through the real templates and parsed using nginx's
  tokenizer rules, keep the same statement structure. The check
  refuses unsafe stored rows.
- NginxValues.cy.js: injection attempts from a non-admin get 400, and
  hosts using valid edge-case values come up with nginx_online true.
2026-11-10 08:20:02 +10:00
..
certbot Merge pull request #5951 from Alexis-Loskoutoff/fix/update-infomaniak-certbot-plugin 2026-11-05 10:03:35 +10:00
config Update SQLite client configuration from sqlite3 to better-sqlite3 2026-02-14 23:53:43 -08:00
internal Stop non-admins injecting nginx directives through host fields 2026-11-10 08:20:02 +10:00
lib Stop non-admins injecting nginx directives through host fields 2026-11-10 08:20:02 +10:00
migrations feat: rate limit auth endpoints and scope user proxy host permissions 2026-11-05 12:16:36 +05:00
models Optimise isAdmin lookups 2026-11-09 22:25:07 +10:00
routes Fix second round of review findings from PR #6029 2026-11-09 23:39:26 +10:00
schema Stop non-admins injecting nginx directives through host fields 2026-11-10 08:20:02 +10:00
scripts Use the row's own model and host type in regenerate-config 2026-08-28 12:02:52 +03:00
templates Fix a proxy host whose access list can't be loaded is now denied to 2026-11-09 22:04:32 +10:00
test Stop non-admins injecting nginx directives through host fields 2026-11-10 08:20:02 +10:00
.gitignore
app.js Fall back to error code 500 when not set in error object 2026-05-18 16:55:41 +10:00
biome.json Update dependencies 2026-11-09 11:55:20 +10:00
db.js Updated backend packages 2026-08-22 23:10:26 +10:00
index.js Don't start IP ranges renewal timer when fetching is disabled 2026-10-02 02:08:28 +05:30
knexfile.js Updated backend packages 2026-08-22 23:10:26 +10:00
logger.js feat: Add a Logs viewer to the admin UI 2026-09-22 13:11:38 -03:00
migrate.js
nodemon.json
package.json Stop non-admins injecting nginx directives through host fields 2026-11-10 08:20:02 +10:00
setup.js Merge branch 'develop' into develop 2026-09-23 18:53:06 +07:00
validate-schema.js
yarn.lock Update dependencies 2026-11-09 11:55:20 +10:00