Skip to content

Commit

Permalink
update dependencies, change resolver session behaviour and bump versi…
Browse files Browse the repository at this point in the history
…on v1.0.0

Resolver session are now only accept httpx.Client rather than requests.Client, this is because dnspython changes makes it no longer accepting requests.Client

also update dependencies to fix 2 CVE (requests and dnspython)

- CVE-2024-35195
- CVE-2023-29483
  • Loading branch information
mansuf committed Sep 7, 2024
1 parent 84fa2d6 commit 5ee3a5c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
17 changes: 17 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## v1.0.0

In summary, this update introduce some breaking changes to resolver session and update library dependencies.

### Breaking changes

Now function `requests_doh.resolver.set_resolver_session` only accept `httpx.Client` rather than `requests.Client`.
This is because [dnspython changes](https://dnspython.readthedocs.io/en/stable/whatsnew.html#id6) makes it no longer
accepting `requests.Client`

And `requests_doh.resolver.get_resolver_session` are now returning `httpx.Client` rather than `requests.Client`

### Dependencies

- Bump requests from v2.31.0 to v2.32.3 due to [CVE-2024-35195](https://github.com/advisories/GHSA-9wx4-h78v-vm56)
- Bump dnspython from v2.3.0 to v2.6.1 due to [CVE-2023-29483](https://github.com/advisories/GHSA-3rq5-2g8h-59hc)

## v0.3.3

### Fix bugs
Expand Down
2 changes: 1 addition & 1 deletion requests_doh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
DNS over HTTPS resolver for python requests
"""

__version__ = "0.3.3"
__version__ = "1.0.0"
__description__ = "DNS over HTTPS resolver for python requests"
__author__ = "Rahman Yusuf"
__author_email__ = "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions requests_doh/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def __init__(self, provider=None, cache_expire_time=None, **kwargs):

super().__init__(**kwargs)

def get_connection(self, url, proxies=None):
conn = super().get_connection(url, proxies)
def get_connection_with_tls_context(self, *args, **kwargs):
conn = super().get_connection_with_tls_context(*args, **kwargs)
if isinstance(conn, SOCKSHTTPSConnectionPool):
conn.ConnectionCls = SOCKSHTTPSConnection
elif isinstance(conn, SOCKSHTTPConnectionPool):
Expand Down
20 changes: 10 additions & 10 deletions requests_doh/resolver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import requests
import httpx
from dns.message import make_query
from dns.rdatatype import RdataType
from dns.query import https as query_https
Expand All @@ -10,7 +10,7 @@
NoDoHProvider
)

_resolver_session = None # type: requests.Session
_resolver_session = None # type: httpx.Client
_available_providers = {
"cloudflare": "https://cloudflare-dns.com/dns-query",
"cloudflare-security": "https://security.cloudflare-dns.com/dns-query",
Expand Down Expand Up @@ -39,26 +39,26 @@ def set_resolver_session(session):
Parameters
-----------
session: :class:`requests.Session`
session: :class:`httpx.Client`
An http session to resolve DNS
Raises
-------
ValueError
``session`` parameter is not :class:`requests.Session` instance
``session`` parameter is not :class:`httpx.Client` instance
"""
global _resolver_session

if not isinstance(session, requests.Session):
raise ValueError(f"`session` must be `requests.Session`, {session.__class__.__name__}")
if not isinstance(session, httpx.Client):
raise ValueError(f"`session` must be `httpx.Client`, {session.__class__.__name__}")

_resolver_session = session

def get_resolver_session() -> requests.Session:
def get_resolver_session() -> httpx.Client:
"""
Return
-------
requests.Session
httpx.Client
Return an http session for DoH resolver
"""
return _resolver_session
Expand Down Expand Up @@ -164,7 +164,7 @@ def remove_dns_provider(name, fallback=None):
# Let's try to remove the newly created DNS
remove_dns_provider("another-dns")
# If we send request to this URL, it would still working
# If we send request to same URL, it would still working
r = session.get("https://example.com")
print(r.status_code)
Expand Down Expand Up @@ -230,7 +230,7 @@ def resolve_dns(host):
session = get_resolver_session()

if session is None:
session = requests.Session()
session = httpx.Client()
set_resolver_session(session)

answers = set()
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
requests[socks]==2.31.0
dnspython[doh]==2.3.0
requests[socks]==2.32.3
dnspython[doh]==2.6.1

0 comments on commit 5ee3a5c

Please sign in to comment.