Skip to content

gate forwarded host/proto headers on proxy trust model - #390

Open
lovasoa wants to merge 2 commits into
masterfrom
ophir.lojkine/gate-forwarded-headers-proxy-trust
Open

gate forwarded host/proto headers on proxy trust model#390
lovasoa wants to merge 2 commits into
masterfrom
ophir.lojkine/gate-forwarded-headers-proxy-trust

Conversation

@lovasoa

@lovasoa lovasoa commented May 28, 2026

Copy link
Copy Markdown
Owner

Fixes #373. HTTP code trusted x-forwarded-host/x-forwarded-proto/forwarded unconditionally, while socket client-IP resolution already gates forwarded headers behind WBO_IP_SOURCE. Direct deployments could be fed spoofed canonical URLs, an attacker-controlled cookie Secure flag, and high-cardinality fake server.address metrics.

One shared helper now drives both surfaces: trustsForwardedHeaders(config) returns true only when IP_SOURCE is X-Forwarded-For or Forwarded (the same sources that imply a trusted proxy for IP resolution). The three header-reading spots (findBaseUrl, requestScheme/requestAuthority, cookie Secure) call it and fall back to req.socket.encrypted/req.headers.host on direct deploys.

Proof, forwarded headers ignored on a direct deployment:

$ WBO_SILENT=true node --test test-node/*.test.js
ℹ tests 314
ℹ pass 314
ℹ fail 0

New tests assert the gate directly:

  • templating.test.js: spoofed x-forwarded-host/proto ignored, base URL falls back to real host.
  • server_routes.test.js: cookie is NOT Secure from spoofed x-forwarded-proto on a direct deploy; still Secure behind a configured proxy.
  • socket_policy.test.js: trustsForwardedHeaders truth table.

npm run lint and npm run typecheck pass. Net +129 LOC, mostly tests.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e1a88cd28

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/socket/policy.mjs
Comment on lines +237 to +240
return (
normalizedIpSource === "x-forwarded-for" ||
normalizedIpSource === "forwarded"
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Trust forwarded host/proto for custom proxy IP headers

For deployments behind a trusted CDN/proxy that use a documented custom WBO_IP_SOURCE such as CF-Connecting-IP (README.md lines 43 and 186), this returns false, so the new callers in templating and cookie generation ignore X-Forwarded-Proto/X-Forwarded-Host. In that configuration HTTPS board pages will emit a non-Secure user-secret cookie and generate http/internal-host base and canonical URLs even though the deployment is explicitly configured to trust the proxy-provided client IP.

Useful? React with 👍 / 👎.

A custom WBO_IP_SOURCE such as CF-Connecting-IP is a trusted-proxy
deployment too, so HTTPS pages must keep emitting Secure cookies and
https canonical URLs. Trust forwarded headers whenever IP_SOURCE is not
the default remoteAddress.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P1: Gate HTTP forwarded host/proto behind trusted proxy config

1 participant