Skip to content

RStudio proxy attempts to proxy localhost through http_proxy #19100

Open

Description

@hsmallbone

System details

RStudio Edition : Server
RStudio Version :  rstudio-server-rhel-2026.09.0-174
OS Version      : RHEL 9.8
R Version       : 4.6

Steps to reproduce the problem

Run RStudio-Server with http_proxy set and attempt to start Posit AI Assistant
Refused to connect to Posit AI Assistant error will pop up
Network connections show 403 error - websocket connection refused

Describe the problem in detail

I am running RStudio-Server on a host with a http_proxy
I enabled Posit AI Assistant but was unable to connect with error 403
Turns out that RStudio-Server will attempt to proxy the localhost over the environment http_proxy which fails
No errors are logged anywhere except clientside
This is fixable by setting no_proxy='localhost' but this fix is difficult to find

Describe the behavior you expected

I expected localhost/127.0.0.1 to not be proxied over http proxy or some documentation about this

  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Activity

  1. added theissue type on Oct 14, 2026
  2. self-assigned this
    on Oct 14, 2026
  3. gtritchie commented on Oct 14, 2026

    @gtritchie
    Member

    Thanks for the report, @hsmallbone. This is a bug: rserver applies http_proxy to its own connections to localhost, and it can't reach the RStudio server's localhost through a remote proxy. It isn't specific to Posit Assistant; anything RStudio Server proxies to a local port is affected (Shiny apps, Quarto previews, and so on). It's also a documentation gap, because the open-source docs never say that localhost needs to be listed in no_proxy.

    Workaround: add the local addresses to no_proxy wherever you set http_proxy, for example in /etc/rstudio/env-vars:

    http_proxy=http://your-proxy:8080
    https_proxy=http://your-proxy:8080
    no_proxy=localhost,127.0.0.1,::1

    Keep any other entries you already have in no_proxy, then restart RStudio Server (sudo rstudio-server restart), since the proxy settings are only read at startup.

    For more detail, see Outgoing Proxies in the Posit Workbench admin guide. It's written for Workbench, but the env-vars and no_proxy sections apply to RStudio Server as well; the Workbench-only features it lists and the Launcher note don't.

    We'll follow up with a fix so local connections never go through the proxy.

  4. gtritchie commented on Oct 14, 2026

    @gtritchie
    Member

    Notes for the fix

    Line numbers are from main at a1ea17e.

    Root cause. TcpIpAsyncClient::connectAndWriteRequest (src/cpp/core/include/core/http/TcpIpAsyncClient.hpp:92) calls proxyUtils().httpProxyUrl(address_, port_) and connects to the proxy whenever that returns a URL. The SSL client does the same with httpsProxyUrl (TcpIpAsyncClientSsl.hpp:90). ProxyUtils::shouldProxy (src/cpp/core/http/ProxyUtils.cpp:86) exempts a destination only when a no_proxy rule matches it. Nothing exempts loopback by default. This was introduced in 8ed7b75 (rstudio-pro#5893) and first released in v2024.12.0.

    Affected paths:

    • Open source: rserver's /p/ and /p6/ handler, proxyLocalhostRequest in src/cpp/server/session/ServerSessionProxy.cpp, connects with a LocalhostAsyncClient to "localhost" (:1523) or "::1" (:1527). Posit Assistant's WebSocket uses /p/ in server mode (buildWebSocketUrl in SessionChat.cpp), and so does anything else served through a port-mapped URL.
    • rstudio-pro, Launcher sessions: the session proxy in rsession (src/cpp/session/http/SessionProxy.cpp) connects to "localhost" the same way. Launcher jobs inherit rserver's proxy variables through forwardHttpProxyVars().

    Symptom since 2026.08.0. The port-ownership check from #18330 runs against the proxy's address and port instead of the local app's, so it fails. handleLocalhostError then returns a 403, "Not authorized to access the requested port". LocalhostAsyncClient.hpp:76 logs Refusing localhost proxy to port <N> at WARN, where <N> is the proxy's port. The request never reaches the proxy.

    Fix. Make ProxyUtils::shouldProxy return false for loopback destinations, whatever no_proxy says:

    • the hostname localhost, case-insensitive;
    • any IPv4 address in 127.0.0.0/8;
    • ::1.

    For IP literals, parse with boost::asio::ip::make_address and check is_loopback(); don't match strings. Make the exemption by destination address, not by client class. In rstudio-pro, LocalhostAsyncClient(Ssl) also connects to remote hosts: the rserver-to-session-host hop in ServerSessionProxyOverlay.cpp and ServerAgentsViewProxy.cpp. Admins' no_proxy settings must keep controlling those.

    Remove the now-redundant rules. The 127.0.0.1:<port> no-proxy rules added in desktop and standalone mode (src/cpp/session/SessionMain.cpp:2780 and :2797) become dead code once loopback is always exempt. Remove them. Check whether addNoProxyRule and createNoProxyRule(address, port) have other callers before deleting them.

    Tests. Add tests to src/cpp/core/http/ProxyUtilsTests.cpp, following the existing pattern (set the env vars, then construct ProxyUtils directly). With http_proxy and https_proxy set and no no_proxy:

    • httpProxyUrl and httpsProxyUrl return none for localhost, LOCALHOST, 127.0.0.1, 127.1.2.3 and ::1;
    • they still return the proxy for a non-loopback host and IP, such as example.com and 10.0.0.1;
    • an existing no_proxy rule for a non-loopback host still applies.

    Run them with ./build/src/cpp/rstudio-tests --scope core.

    NEWS. Add a ### Fixed entry linking #19100. Released users have been affected since 2024.12.

    Out of scope:

    • The ownership-check warning reports the proxy's port as <N>. That's worth fixing separately.
    • The Workbench docs (docs/server/admin/access_and_security/outgoing_proxies.qmd in rstudio-pro) say to add localhost to no_proxy. That advice becomes unnecessary but stays harmless, so updating it can follow the downstream merge.
  5. removed their assignment
    on Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions