Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[upd] httpx v0.21.2 --> v0.23.3 & httpx-socks v0.7.2 --> v0.7.5 #2302

Closed
wants to merge 1 commit into from

Conversation

return42
Copy link
Member

Dependabot alerts but did not update the httpx dependencies.

@dalf what do you think, can upgrade httpx packages?

I test this PR on my instance https://darmarit.org/searx/ .. so far I could not detect any issues.

Related: https://github.com/searxng/searxng/security/dependabot/4

@dalf
Copy link
Member

dalf commented Mar 31, 2023

Most probably, this code needs to be updated:

class AsyncHTTPTransportNoHttp(httpx.AsyncHTTPTransport):
"""Block HTTP request"""
async def handle_async_request(self, request):
raise httpx.UnsupportedProtocol('HTTP protocol is disabled')
class AsyncProxyTransportFixed(AsyncProxyTransport):
"""Fix httpx_socks.AsyncProxyTransport
Map python_socks exceptions to httpx.ProxyError exceptions
"""
async def handle_async_request(self, request):
try:
return await super().handle_async_request(request)
except ProxyConnectionError as e:
raise httpx.ProxyError("ProxyConnectionError: " + e.strerror, request=request) from e
except ProxyTimeoutError as e:
raise httpx.ProxyError("ProxyTimeoutError: " + e.args[0], request=request) from e
except ProxyError as e:
raise httpx.ProxyError("ProxyError: " + e.args[0], request=request) from e
def get_transport_for_socks_proxy(verify, http2, local_address, proxy_url, limit, retries):
# support socks5h (requests compatibility):
# https://requests.readthedocs.io/en/master/user/advanced/#socks
# socks5:// hostname is resolved on client side
# socks5h:// hostname is resolved on proxy side
rdns = False
socks5h = 'socks5h://'
if proxy_url.startswith(socks5h):
proxy_url = 'socks5://' + proxy_url[len(socks5h) :]
rdns = True
proxy_type, proxy_host, proxy_port, proxy_username, proxy_password = parse_proxy_url(proxy_url)
verify = get_sslcontexts(proxy_url, None, verify, True, http2) if verify is True else verify
return AsyncProxyTransportFixed(
proxy_type=proxy_type,
proxy_host=proxy_host,
proxy_port=proxy_port,
username=proxy_username,
password=proxy_password,
rdns=rdns,
loop=get_loop(),
verify=verify,
http2=http2,
local_address=local_address,
limits=limit,
retries=retries,
)
def get_transport(verify, http2, local_address, proxy_url, limit, retries):
verify = get_sslcontexts(None, None, verify, True, http2) if verify is True else verify
return httpx.AsyncHTTPTransport(
# pylint: disable=protected-access
verify=verify,
http2=http2,
limits=limit,
proxy=httpx._config.Proxy(proxy_url) if proxy_url else None,
local_address=local_address,
retries=retries,
)

Without diving into the httpx code, a simple check is to upgrade, start a with mitmproxy for example and configure SearXNG to use it. If the requests are sent through the proxy that's good. Note that socks4, socks5, http and https proxies need to be tested. And then other parameters need to be checked.

I was hoping the version 0.24 to be released sooner.

I will have a look at it tomorrow.

@return42
Copy link
Member Author

I was hoping the version 0.24 to be released sooner.

From my side there is no need to hurry ... should we wait? --> encode/httpx#2534 (comment)

Note that socks4, socks5, http and https proxies need to be tested. And then other parameters need to be checked. .. I will have a look at it tomorrow.

Thanks a lot, I would be overwhelmed with this for now / wouldn't know how to assemble a setup for a test :-o

Comment on lines 7 to 16
pygments==2.14.0
python-dateutil==2.8.2
pyyaml==6.0
httpx[http2]==0.21.2
httpx[http2]==0.23.3
Brotli==1.0.9
uvloop==0.17.0
httpx-socks[asyncio]==0.7.2
httpx-socks[asyncio]==0.7.5
setproctitle==1.3.2
redis==4.5.4
markdown-it-py==2.2.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy @dalf's comment from return42@d86ec70#commitcomment-107513541 to here ..

The important thing to test is the proxy configuration (http and socks). When I have tried with mitmproxy and verify: ~/.mitmproxy/mitmproxy-ca-cert.cer I had an error. It worked before.

@return42 return42 marked this pull request as draft April 4, 2023 16:51
@dalf
Copy link
Member

dalf commented Apr 5, 2023

Another note: in new version httpx supports socks and http proxy but not https proxy.
For https proxy, httpx-socks is still required.

See:

@mrpaulblack
Copy link
Member

Closing in favor of #2644; Closing.

@return42 return42 deleted the upd-httpx branch September 15, 2023 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants