fix(auth): the review items of #854 that go on top

- The strip removed the proxy headers from req.headers only, while
  req.raw.rawHeaders and req.raw.headersDistinct still held the secret.
  takeTrustedProxyHeaders() now takes the raw message and removes them
  from both. A plain splice is not enough on a real IncomingMessage: its
  headers and headersDistinct getters are lazy and walk rawHeaders up to
  the count stored at parse time, so one that first runs after the splice
  throws. Both are read (cached) first. Two tests, each caught by its
  mutation: the stripping test checks the raw list, and a real http
  request checks all three views and that the getters still answer.
- CLAUDE.md's Rate limit row names the trusted-proxy secret's own bucket.
- The wiki lists the loopback addresses the check accepts, as the
  contributor offered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-12-03 10:22:23 +01:00
1 parent a117955490
commit 4be36b0404
6 files changed
+113 -8

No files matched your search

+3 -1
View File
@@ -660,7 +660,9 @@ peer (§3).
loopback paths cannot drift apart.
- **The headers never travel further.** The first auth hook, right after the Host guard
and in every auth mode, reads both headers and deletes them from the request, before
any exemption (QR, web‑tab and HTML‑view capabilities) or route runs. So the web‑tab
any exemption (QR, web‑tab and HTML‑view capabilities) or route runs. They go from all
three views Node keeps of a request: `headers`, the raw `rawHeaders` list and
`headersDistinct`. So the web‑tab
relay cannot forward the secret to a dashboard (as a second layer the relay also drops both default names and
the configured username header; its WebSocket leg sends only `origin` and `cookie`).
- **No auto‑provisioning.** The username must name an existing, enabled account, so an
+3 -2
View File
@@ -143,8 +143,9 @@ On every request the proxy adds two headers:
| `X-Codeman-Proxy-Secret` | the shared secret |
| `X-Codeman-User` | the Codeman username (another name can be set with `CODEMAN_TRUSTED_PROXY_USER_HEADER`: an `X-…` header such as `X-Forwarded-User`, or `Remote-User`; standard and reserved headers are refused, because the header is removed from every request) |
Codeman believes them only from a loopback connection with the matching secret, so keep
Codeman bound to `127.0.0.1` and the proxy on the same host. It removes both headers from
Codeman believes them only from a loopback connection (`127.0.0.1`, `::1` or
`::ffff:127.0.0.1`) with the matching secret, so keep Codeman bound to `127.0.0.1` and the
proxy on the same host. It removes both headers from
every request before anything else sees them. The exact rules are in
[`docs/security-architecture.md` §10a](https://github.com/Ark0N/Codeman/blob/master/docs/security-architecture.md).