Skip to content

Websocket origin rejection warning does not mention a trusted X-Forwarded-Proto when that is the cause #7857

Done

Description

@masenf

Problem

In prod mode the event websocket accepts the backend's own origin. With trusted_proxy_hops >= 1, a trusted X-Forwarded-Proto: https makes an http:// origin a mismatch (by design, #7799). When that is the reason for a rejection, the once-per-worker warning describes the wrong cause. It prints the Host and X-Forwarded-Host it saw, then advises setting REFLEX_DEPLOY_URL and says "a reverse proxy must forward the original Host header". The Host already matches, and the real cause is the scheme: the trusted proxy claims https while the page was loaded over http, for example a misconfigured proxy or an http page behind a hop that sets X-Forwarded-Proto: https.

The rejection itself is correct; only the diagnosis is misleading.

Repro (reflex 0.11.0a2)

  1. REFLEX_TRUSTED_PROXY_HOPS=1 REFLEX_API_URL=http://app.test:3341 reflex run --env prod --backend-port 3340 (single-port).
  2. Put a plain-http reverse proxy on :3341 that keeps Host and sets X-Forwarded-Proto: https.
  3. Open http://app.test:3341/ in a browser.

Actual: the websocket gets 403 forever, and the log says:

Rejected an event websocket from origin 'http://app.test:3341': in prod mode the backend accepts only its own origin (request Host 'app.test:3341', X-Forwarded-Host None trusted); if it is your frontend's origin, set REFLEX_DEPLOY_URL on the backend to the frontend's public URL or add it to cors_allowed_origins; a reverse proxy must forward the original Host header.

Expected: the warning names the trusted X-Forwarded-Proto value it used. When the origin's host matches and only the scheme differs, the hint says so: the page is served over http while the trusted proxy reports https, so fix the proxy's X-Forwarded-Proto or serve the page over https.

Fix

  • reflex/app.py, _SocketOriginCheck.__call__: include the trusted X-Forwarded-Proto entry in the "request Host …, X-Forwarded-Host …" part of the warning.
  • When _origin_matches_request(origin, hosts, None) is true but the call with the trusted proto is false, use a scheme-specific hint instead of the Host-forwarding one. Do not put the rejected origin into any setting's value (any client can send the first rejected handshake).
  • Extend test_socketio_rejection_warns_once_with_fix in tests/units/test_app.py with an X-Forwarded-Proto: https + http:// origin case at trusted_proxy_hops=1.

Activity

  1. added
    bug
    release-train
    on Nov 11, 2026
  2. linear-code commented on Nov 11, 2026

    @linear-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrelease-train

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions