Skip to content

fix(api): trust proxy headers over local socket TLS state in websocket origin check - #868

Merged
scttbnsn merged 1 commit into
dev/v1.7from
fix/v1.7-ws-origin-trustproxy
Aug 25, 2026
Merged

scttbnsn merged 1 commit into
dev/v1.7from
fix/v1.7-ws-origin-trustproxy

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #867.

With DD_SERVER_TRUSTPROXY enabled but X-Forwarded-Proto absent on a websocket upgrade, isOriginAllowed fell back to the local socket's encrypted flag. Behind a TLS-terminating proxy (Traefik in the report) the backend socket is plain HTTP, so a browser's https:// Origin never matched and every upgrade got a hard 403 while REST kept working (Express's own trust-proxy machinery resolves req.protocol there). Not auth-specific; the reporter's OIDC-only setup just made it look that way. The trust-proxy-enabled test block never exercised a realistic socket, so the branch was untested.

Fix: when trust proxy is on and the forwarded protocol header is absent, treat the protocol as unknown and skip that comparison (matching Express trust-proxy semantics); host validation keeps its teeth, trust-proxy-off behavior is untouched. Also adds a debug log on every rejection with the origin/host/protocol and raw forwarded-header values so the next 403 explains itself.

Verified: six new tests including the reporter's exact deployment shape (TDD, new tests confirmed red against the unfixed code), full app suite 412 files / 13,092 tests green at 100% coverage, biome clean, full pre-push gate green.

Changelog

  • 🐛 Fixed WebSocket origin checks when DD_SERVER_TRUSTPROXY is enabled and X-Forwarded-Proto is absent.
  • 🔒 Preserved host validation and trust-proxy-disabled behavior.
  • ✨ Added debug logging for rejected WebSocket origins.
  • ✨ Added six tests for trusted TLS-terminating proxy scenarios.

…t origin check

With trust proxy enabled but X-Forwarded-Proto absent on a websocket
upgrade, isOriginAllowed fell back to the local socket's encrypted flag.
Behind a TLS-terminating proxy that socket is plain HTTP, so a browser's
https:// Origin never matched and every upgrade got a hard 403 while
REST worked fine. The protocol is now treated as unknown and skipped
from the comparison instead, matching Express's own trust-proxy
semantics; host validation keeps its teeth. Adds a debug log on
rejection with the origin/host/protocol details for diagnosing future
mismatches. Closes #867.
@scttbnsn

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@vercel

vercel Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
drydock-website Ready Ready Preview Aug 25, 2026 11:27am
drydockdemo-website Ready Ready Preview Aug 25, 2026 11:27am

@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b1e5792d-7c0a-4e99-9266-07fe23632889

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 29847587-c829-4156-b033-fd3cd1b06e1e

📥 Commits

Reviewing files that changed from the base of the PR and between da1f6cb and c352f05.

⛔ Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !CHANGELOG.md
📒 Files selected for processing (2)
  • app/api/ws-upgrade-utils.test.ts
  • app/api/ws-upgrade-utils.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The WebSocket origin check now treats the protocol as unknown when a trusted proxy omits X-Forwarded-Proto. It no longer compares that origin protocol with the backend socket state in this case. Rejected origins emit scoped debug details. Tests cover direct HTTPS rejection, trusted TLS-terminating proxies, host mismatches, and logging behavior.

Suggested labels: second-opinion

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #867. With trust-proxy mode enabled and no X-Forwarded-Proto header, the protocol becomes unknown, so valid websocket origins are not rejected due to backend TLS state. Host …
Out of Scope Changes check ✅ Passed All reviewed changes support the linked issue. The logger and rejection diagnostics improve origin-validation troubleshooting, and the added tests verify the proxy behavior and host validation. No unr…
Full details: Linked Issues check

Explanation

The changes address issue #867. With trust-proxy mode enabled and no X-Forwarded-Proto header, the protocol becomes unknown, so valid websocket origins are not rejected due to backend TLS state. Host validation remains active, trust-proxy-disabled behavior remains covered, and tests cover the reported proxy configuration.

Full details: Out of Scope Changes check

Explanation

All reviewed changes support the linked issue. The logger and rejection diagnostics improve origin-validation troubleshooting, and the added tests verify the proxy behavior and host validation. No unrelated code changes are shown.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/v1.7-ws-origin-trustproxy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the second-opinion Summon Greptile for a second-opinion review label Aug 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@greptileai Review exact head c352f05f7848942c0829a641e3fc979f4a0b0fdb. Review for correctness, security issues, and cross-file regressions.

@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttbnsn
scttbnsn merged commit 85df047 into dev/v1.7 Aug 25, 2026
34 checks passed
scttbnsn added a commit that referenced this pull request Aug 25, 2026
…t origin check (v1.6 backport) (#872)

fix(api): trust proxy headers over local socket TLS state in websocket origin check (#868)

With trust proxy enabled but X-Forwarded-Proto absent on a websocket
upgrade, isOriginAllowed fell back to the local socket's encrypted flag.
Behind a TLS-terminating proxy that socket is plain HTTP, so a browser's
https:// Origin never matched and every upgrade got a hard 403 while
REST worked fine. The protocol is now treated as unknown and skipped
from the comparison instead, matching Express's own trust-proxy
semantics; host validation keeps its teeth. Adds a debug log on
rejection with the origin/host/protocol details for diagnosing future
mismatches. Closes #867.
scttbnsn added a commit that referenced this pull request Aug 26, 2026
Rolls the Unreleased changelog content into a dated 1.7.0-rc.4 section
(adding a new demo-headers Security entry for #878 alongside the
existing OpenSSL/WebSocket-proxy/bare-integer-tag entries) and stamps
the rc.4 identity across README.md and its six translations, the
website's site-config/site-content, the current docs quickstart tag
matrix and API examples, and the demo mock fixtures. Updates the
release-identity/docs-identity/changelog-links/readme-translations
test fixtures and highlight excerpts to match.

Four highlight areas: the WebSocket log-stream TLS-proxy 403 fix
(#867/#868), the bare-integer-tag ranking fix (#859/#871), the
six-CVE OpenSSL base-image bump (#881), and the demo site's missing
security headers (#878).
@scttbnsn
scttbnsn deleted the fix/v1.7-ws-origin-trustproxy branch August 27, 2026 23:57

This branch was successfully deployed

2 active deployments
Preview – drydock-website — c352f05f Deployed Aug 25, 2026 by vercel[bot]
Preview – drydockdemo-website — c352f05f Deployed Aug 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

second-opinion Summon Greptile for a second-opinion review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants