Files
hermes-agent/plugins/platforms/matrix/session_proxy.py
Teknium 948ee7dcd0 fix(matrix): redact against the env proxy the session uses after the missing-SOCKS fallback
Finding: Matrix missing-SOCKS fallback checks the ignored SOCKS proxy.
Without aiohttp_socks, _create_matrix_session drops MATRIX_PROXY=socks5://...
and returns ClientSession(trust_env=True), which dials HTTPS_PROXY. Every
catch checked the clean, unused SOCKS URL, so the whoami catch kept
exc_info and logged the chained 'invalid literal for int(): <password>'.
matrix_redaction_proxy() now names the proxy the session really uses
(the env proxy, NO_PROXY and gateway.trust_env applied, after a fallback).
2026-11-08 19:47:57 -08:00

22 lines
976 B
Python

"""The proxy a Matrix ``ClientSession`` actually uses, for error redaction (kept out of the adapter facade)."""
from gateway.platforms.base import env_proxy_for_redaction, gateway_trust_env
def _socks_connector_missing() -> bool:
try:
import aiohttp_socks
except ImportError:
return True
return False
def matrix_redaction_proxy(proxy_url: str | None, homeserver: str | None) -> str | None:
"""Proxy to hand ``describe_proxy_error`` for an error from the session ``_create_matrix_session``
built: *proxy_url* when the session dials it, else the environment the ``trust_env`` session
reads — no proxy configured, or a SOCKS one ignored because ``aiohttp_socks`` is missing."""
socks = bool(proxy_url) and proxy_url.split("://")[0].lower().startswith("socks")
if proxy_url and not (socks and _socks_connector_missing()):
return proxy_url
return env_proxy_for_redaction(homeserver, trust_env=gateway_trust_env())