Skip to content

Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.

fix(security): stop an untrusted request path from re-pointing the auto-router (#885)

Aurora Capitalabf480a9fe9d
diff --git a/claude-ops/scripts/crsproxy-reauth/crsproxy_auto_router.py b/claude-ops/scripts/crsproxy-reauth/crsproxy_auto_router.py
index 1f0ecc75..a95946b1 100644
--- a/claude-ops/scripts/crsproxy-reauth/crsproxy_auto_router.py
+++ b/claude-ops/scripts/crsproxy-reauth/crsproxy_auto_router.py
@@ -19,6 +19,7 @@ import re
import sys
import time
import urllib.error
+import urllib.parse
import urllib.request
from collections import defaultdict
from datetime import datetime, timezone
@@ -210,12 +211,43 @@ class PressureTracker:
# ---------------------------------------------------------------------------
+def build_upstream_url(upstream, path):
+ """Join an untrusted request path onto the trusted upstream base.
+
+ SECURITY (CodeQL py/partial-ssrf): this used to be `upstream + path`, and
+ `path` is the raw request line from any client that can reach the listener.
+ Plain concatenation lets the client re-point the request at a host it
+ chooses while the code still reads as if it targets the local upstream:
+
+ "http://127.0.0.1:8319" + "//evil.com/x" -> host evil.com
+ "http://127.0.0.1:8319" + "@evil.com/x" -> host evil.com (userinfo)
+
+ Because this proxy forwards the client's headers verbatim, that would hand
+ the upstream Authorization header to an attacker-controlled server.
+
+ The fix keeps only the path and query of whatever was supplied and re-hosts
+ it on the upstream's own scheme/netloc, so the destination host can never be
+ influenced by the request. Backslashes are normalised first: several HTTP
+ stacks treat "\\\\evil.com" as "//evil.com".
+ """
+ base = urllib.parse.urlsplit(upstream)
+ supplied = urllib.parse.urlsplit(str(path or "").replace("\\", "/"))
+
+ safe_path = supplied.path or "/"
+ if not safe_path.startswith("/"):
+ safe_path = "/" + safe_path
+
+ return urllib.parse.urlunsplit(
+ (base.scheme, base.netloc, safe_path, supplied.query, "")
+ )
+
+
def proxy_to_upstream(upstream, method, path, headers, body, timeout=UPSTREAM_TIMEOUT):
"""Proxy a single request to the upstream cli-proxy-api.
Returns (status_code, response_headers_dict, response_body_bytes).
"""
- url = upstream + path
+ url = build_upstream_url(upstream, path)
skip = {"host", "connection", "transfer-encoding", "content-length"}
forward_headers = {k: v for k, v in headers.items() if k.lower() not in skip}
diff --git a/claude-ops/scripts/crsproxy-reauth/test_auto_router.py b/claude-ops/scripts/crsproxy-reauth/test_auto_router.py
index 478b4ccb..8833f119 100644
--- a/claude-ops/scripts/crsproxy-reauth/test_auto_router.py
+++ b/claude-ops/scripts/crsproxy-reauth/test_auto_router.py
@@ -563,5 +563,77 @@ class TestNoSecretsInLogs(unittest.TestCase):
shutil.rmtree(tmpdir)
+
+
+class TestUpstreamURLConstruction(unittest.TestCase):
+ """Regression tests for CodeQL py/partial-ssrf (alert #327).
+
+ `proxy_to_upstream` built its target as `upstream + path`, where `path` is
+ the raw request line from an untrusted client. Because `urljoin`-free string
+ concatenation keeps whatever the client sent, a path beginning with `//` or
+ `@` re-points the request at an attacker-controlled HOST while still looking
+ like it targets the local upstream:
+
+ "http://127.0.0.1:8319" + "//evil.com/x" -> host evil.com
+ "http://127.0.0.1:8319" + "@evil.com/x" -> host evil.com (userinfo)
+
+ The proxy forwards client headers, so that leaks the upstream Authorization
+ header to the attacker's server. These tests pin the host, not the string.
+ """
+
+ UPSTREAM = "http://127.0.0.1:8319"
+
+ def _host_of(self, path):
+ from urllib.parse import urlsplit
+
+ return urlsplit(router.build_upstream_url(self.UPSTREAM, path)).netloc
+
+ def test_normal_path_is_unchanged(self):
+ self.assertEqual(
+ router.build_upstream_url(self.UPSTREAM, "/v1/chat/completions"),
+ "http://127.0.0.1:8319/v1/chat/completions",
+ )
+
+ def test_query_string_is_preserved(self):
+ self.assertEqual(
+ router.build_upstream_url(self.UPSTREAM, "/v1/models?limit=5"),
+ "http://127.0.0.1:8319/v1/models?limit=5",
+ )
+
+ def test_path_without_leading_slash_is_normalised(self):
+ self.assertEqual(
+ router.build_upstream_url(self.UPSTREAM, "v1/models"),
+ "http://127.0.0.1:8319/v1/models",
+ )
+
+ def test_protocol_relative_path_cannot_change_host(self):
+ self.assertEqual(self._host_of("//evil.com/x"), "127.0.0.1:8319")
+
+ def test_userinfo_path_cannot_change_host(self):
+ self.assertEqual(self._host_of("@evil.com/x"), "127.0.0.1:8319")
+
+ def test_backslash_variant_cannot_change_host(self):
+ self.assertEqual(self._host_of("\\\\evil.com/x"), "127.0.0.1:8319")
+
+ def test_absolute_url_cannot_change_host(self):
+ self.assertEqual(self._host_of("http://evil.com/x"), "127.0.0.1:8319")
+
+ def test_traversal_cannot_escape_upstream_host(self):
+ self.assertEqual(self._host_of("/../../evil"), "127.0.0.1:8319")
+
+ def test_every_hostile_path_keeps_the_upstream_host(self):
+ for hostile in [
+ "//evil.com/x",
+ "///evil.com/x",
+ "@evil.com/x",
+ "http://evil.com/x",
+ "https://evil.com/x",
+ "\\\\evil.com/x",
+ "//user:[email protected]/x",
+ ]:
+ with self.subTest(path=hostile):
+ self.assertEqual(self._host_of(hostile), "127.0.0.1:8319")
+
+
if __name__ == "__main__":
unittest.main()