Repository navigation
Fix chat WebSocket URL for subpath reverse proxy deployments - #17250
Merged
Merged
Conversation
When RStudio Server is behind a reverse proxy at a subpath
(e.g., /rstudio/), buildWebSocketUrl() now prepends the
session-root-path to the port-mapped WebSocket path. Without this,
the browser sends the WebSocket upgrade to /p/{hash}/ai-chat/ws
which bypasses the proxy's location block and omits cookies scoped
to the subpath, causing authentication failures.
Addresses #17249
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Move the path normalization and concatenation logic from buildWebSocketUrl() into a pure function assembleWebSocketPath() in ChatConstants. This makes the slash handling and root-path prepending testable without session state. Add ChatConstantsTests.cpp covering: no root path, root path with/without trailing slash, session URL prefix, portmapped path with/without leading slash, combined trailing slashes, IPv6 port paths, and deep root paths. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The length() > 1 guard kept "/" as-is, producing "//ai-chat". Use the same unconditional trim as the old code so "/" collapses to empty. Add a test case for this edge. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Restore cookie-scoping rationale in buildWebSocketUrl() explaining why all three path prefixes are needed - Use session-root-path (the session option name) instead of www-root-path (the server option) in the inline comment - Document the fixed /ai-chat suffix in the header doc comment Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
kevinushey
approved these changes
Mar 19, 2026
kevinushey
left a comment
Collaborator
There was a problem hiding this comment.
Clean, well-structured bugfix. The pure function extraction is the right call for testability, and the test coverage is thorough with good edge cases.
Contributor
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Addresses #17249.
Summary
session-root-pathto the chat WebSocket URL inbuildWebSocketUrl()when RStudio Server is behind a subpath reverse proxy (e.g.,/rstudio/)/p/{hash}/ai-chat/wsinstead of/rstudio/p/{hash}/ai-chat/ws, which bypasses the proxy's location block and omits cookies scoped to the subpathDetails
buildWebSocketUrl()already prepends theRS_SESSION_URLenv var for Workbench session prefixes, but did not account for thesession-root-pathoption. In open-source RStudio Server,RS_SESSION_URLis always empty, so subpath deployments produced WebSocket URLs without the root path prefix.Other port-mapped features (Shiny, Viewer, Plumber) are unaffected because they return relative URLs that the browser resolves against the current page. The chat code constructs an absolute path, so it needs the root path explicitly.
The fix reads
options().rootPath()and prepends it when set to something other than the default/. Thewww-root-pathserver option passes this to the session automatically via--session-root-path.Test plan
/p/{hash}/ai-chat/ws/rstudio/): chat WebSocket connects at/rstudio/p/{hash}/ai-chat/ws#ifdef RSTUDIO_SERVER)