fix: close connection on extension-sidecar provenance rejection

Same class as the auth/CSRF close-on-reject: the sidecar proxy's
same-origin provenance check runs before read_body(), so an HTTP/1.1
connection reused after a 403 would parse the unread body as the next
request line. Flag close_connection on this path too.

Found by Greptile review of #6658; covered by a new unit test.
This commit is contained in:
Rodrigo Gomes da Silva authored and n committed 2026-09-22 12:06:08 +00:00
1 parent 6a8011f983
commit 1bd3c72e17
2 files changed
+22

No files matched your search

@@ -54,3 +54,21 @@ def test_token_rejected_csrf_closes_connection(monkeypatch):
assert routes._check_csrf(handler) is False
assert handler.close_connection is True
def test_sidecar_provenance_rejected_closes_connection(monkeypatch):
"""Sidecar proxy provenance rejection also runs before read_body()."""
import api.routes as routes
handler = SimpleNamespace(
path="/api/extensions/ext1/sidecar/proxy",
command="POST",
close_connection=False,
)
monkeypatch.setattr(routes, "_match_extension_sidecar_proxy_path", lambda _path: ("ext1", "/proxy"))
monkeypatch.setattr(routes, "_check_same_origin_browser_request", lambda _handler, **_: False)
monkeypatch.setattr(routes, "j", lambda _handler, _payload, status=200: None)
routes._handle_extension_sidecar_proxy(handler, SimpleNamespace(path=handler.path, query=""), "POST")
assert handler.close_connection is True