Only trust Authelia identity headers from TRUSTED_PROXIES #39

Merged
jared merged 1 commits from trusted-proxy-auth into main 2026-11-22 01:03:02 -05:00
Owner

Closes #37.

Do not merge until TRUSTED_PROXIES is set on the Pulse server

This change fails closed. Merging auto-deploys and restarts Pulse, and if TRUSTED_PROXIES is missing from the server's .env at that point, every SSO login gets 401.

Before merging, on the Pulse server:

  1. Back up .env.
  2. Add TRUSTED_PROXIES=<NPM address>, keeping the file's owner and mode.

The code currently running ignores the setting, so adding it early is safe.

What changes

  • authenticateSSO (API) and authenticatePage (HTML pages) now share ssoIdentity() in lib/pageauth.js.
  • ssoIdentity() ignores the Remote-* headers unless the TCP peer address is in TRUSTED_PROXIES, a list of addresses or CIDR ranges (IPv4 or IPv6). The ::ffff: prefix is stripped before the check.
  • X-Forwarded-For and X-Real-IP are never consulted, since a client could forge them.
  • If TRUSTED_PROXIES is unset, no SSO login succeeds and a warning is printed at startup.
  • Invalid entries are logged and skipped. They are never widened, so x.x.x.x/ does not become a /0.
  • Rejected identity headers are logged with their source address.
  • upsertUser now runs only for trusted requests.
  • Worker and Gandalf API-key routes are unchanged.
  • The README documents the setting.

Testing

  • Added 14 jest tests in tests/pageauth.test.js. The full suite passes (45 tests).
  • eslint reports no errors and 3 warnings. The warnings were already there before this change.

After the merge, verify

  • A spoofed curl -H 'Remote-User: x' -H 'Remote-Groups: admin' http://<pulse>:8080/api/user gets 401.
  • The startup log shows Trusted proxies for SSO headers: 1.
  • A real login through NPM still works.

The WebSocket gap is tracked separately in #38.

🤖 Generated with Claude Code

Closes #37. ## Do not merge until `TRUSTED_PROXIES` is set on the Pulse server This change **fails closed**. Merging auto-deploys and restarts Pulse, and if `TRUSTED_PROXIES` is missing from the server's `.env` at that point, every SSO login gets 401. Before merging, on the Pulse server: 1. Back up `.env`. 2. Add `TRUSTED_PROXIES=<NPM address>`, keeping the file's owner and mode. The code currently running ignores the setting, so adding it early is safe. ## What changes - `authenticateSSO` (API) and `authenticatePage` (HTML pages) now share `ssoIdentity()` in `lib/pageauth.js`. - `ssoIdentity()` ignores the `Remote-*` headers unless the TCP peer address is in `TRUSTED_PROXIES`, a list of addresses or CIDR ranges (IPv4 or IPv6). The `::ffff:` prefix is stripped before the check. - `X-Forwarded-For` and `X-Real-IP` are never consulted, since a client could forge them. - If `TRUSTED_PROXIES` is unset, no SSO login succeeds and a warning is printed at startup. - Invalid entries are logged and skipped. They are never widened, so `x.x.x.x/` does not become a `/0`. - Rejected identity headers are logged with their source address. - `upsertUser` now runs only for trusted requests. - Worker and Gandalf API-key routes are unchanged. - The README documents the setting. ## Testing - Added 14 jest tests in `tests/pageauth.test.js`. The full suite passes (45 tests). - eslint reports no errors and 3 warnings. The warnings were already there before this change. ## After the merge, verify - A spoofed `curl -H 'Remote-User: x' -H 'Remote-Groups: admin' http://<pulse>:8080/api/user` gets **401**. - The startup log shows `Trusted proxies for SSO headers: 1`. - A real login through NPM still works. The WebSocket gap is tracked separately in #38. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 1 commit 2026-11-22 01:00:58 -05:00
Only trust Authelia identity headers from TRUSTED_PROXIES
Security / JS Security (npm audit) (push) Failing after 17s
Lint / JS (eslint) (push) Successful in 18s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Lint / JS (eslint) (pull_request) Successful in 18s
Test / JS Tests (jest) (push) Successful in 20s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / JS Security (npm audit) (pull_request) Failing after 17s
Test / JS Tests (jest) (pull_request) Successful in 17s
e302234187
authenticateSSO and authenticatePage took the user and groups straight
from the Remote-* headers, and the server listens on every interface, so
any LAN host could connect directly, claim any user and group, and run
commands on the workers. It could also write whatever it claimed into the
users table.

Add TRUSTED_PROXIES (addresses or CIDR ranges) and ignore the identity
headers unless the TCP peer is on the list. The peer address is used
rather than a forwarding header, which a client could forge. It fails
closed: unset means no SSO login succeeds, with a startup warning.
Rejected attempts are logged with their source. Worker and Gandalf
API-key routes are unchanged.

Closes #37

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared scheduled this pull request to auto merge when all checks succeed 2026-11-22 01:03:01 -05:00
jared merged commit b8a7b2c3b9 into main 2026-11-22 01:03:02 -05:00
jared deleted branch trusted-proxy-auth 2026-11-22 01:03:04 -05:00
Sign in to join this conversation.