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:
Back up .env.
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.
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)
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 main2026-11-22 01:03:02 -05:00
jared
deleted branch trusted-proxy-auth2026-11-22 01:03:04 -05:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Closes #37.
Do not merge until
TRUSTED_PROXIESis set on the Pulse serverThis change fails closed. Merging auto-deploys and restarts Pulse, and if
TRUSTED_PROXIESis missing from the server's.envat that point, every SSO login gets 401.Before merging, on the Pulse server:
.env.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) andauthenticatePage(HTML pages) now sharessoIdentity()inlib/pageauth.js.ssoIdentity()ignores theRemote-*headers unless the TCP peer address is inTRUSTED_PROXIES, a list of addresses or CIDR ranges (IPv4 or IPv6). The::ffff:prefix is stripped before the check.X-Forwarded-ForandX-Real-IPare never consulted, since a client could forge them.TRUSTED_PROXIESis unset, no SSO login succeeds and a warning is printed at startup.x.x.x.x/does not become a/0.upsertUsernow runs only for trusted requests.Testing
tests/pageauth.test.js. The full suite passes (45 tests).After the merge, verify
curl -H 'Remote-User: x' -H 'Remote-Groups: admin' http://<pulse>:8080/api/usergets 401.Trusted proxies for SSO headers: 1.The WebSocket gap is tracked separately in #38.
🤖 Generated with Claude Code