Skip to content

Commit 205bb01

Browse files
committed
5.8.3
- Use timeout values for HTTP client timeouts
1 parent 508ff38 commit 205bb01

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
5.8.3
5+
-----
6+
7+
- Use timeout values for HTTP client timeouts
8+
49
5.8.2
510
-----
611

checkdmarc/_constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
See the License for the specific language governing permissions and
1919
limitations under the License."""
2020

21-
__version__ = "5.8.2"
21+
__version__ = "5.8.3"
2222

2323
OS = platform.system()
2424
OS_RELEASE = platform.release()
2525
USER_AGENT = f"Mozilla/5.0 (({OS} {OS_RELEASE})) checkdmarc/{__version__}"
2626
SYNTAX_ERROR_MARKER = "➞"
27+
DEFAULT_HTTP_TIMEOUT = 2.0

checkdmarc/bimi.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
)
3636

3737
import checkdmarc.resources
38-
from checkdmarc._constants import SYNTAX_ERROR_MARKER, USER_AGENT
38+
from checkdmarc._constants import SYNTAX_ERROR_MARKER, USER_AGENT, DEFAULT_HTTP_TIMEOUT
3939
from checkdmarc.utils import WSP_REGEX, HTTPS_REGEX, query_dns, get_base_domain
4040

4141
"""Copyright 2019-2023 Sean Whalen
@@ -485,6 +485,7 @@ def parse_bimi_record(
485485
domain: str = None,
486486
include_tag_descriptions: bool = False,
487487
syntax_error_marker: str = SYNTAX_ERROR_MARKER,
488+
http_timeout: float = DEFAULT_HTTP_TIMEOUT,
488489
) -> OrderedDict:
489490
"""
490491
Parses a BIMI record
@@ -494,6 +495,7 @@ def parse_bimi_record(
494495
domain (str): The domain where the BIMI record was located
495496
include_tag_descriptions (bool): Include descriptions in parsed results
496497
syntax_error_marker (str): The maker for pointing out syntax errors
498+
http_timeout (float): HTTP timeout in seconds
497499
498500
Returns:
499501
OrderedDict: An ``OrderedDict`` with the following keys:
@@ -572,7 +574,7 @@ def parse_bimi_record(
572574
if tag == "l" and tag_value != "":
573575
raw_xml = None
574576
try:
575-
response = session.get(tag_value)
577+
response = session.get(tag_value, timeout=http_timeout)
576578
response.raise_for_status()
577579
raw_xml = response.content
578580
except Exception as e:
@@ -592,7 +594,7 @@ def parse_bimi_record(
592594
elif tag == "a" and tag_value != "":
593595
cert_metadata = None
594596
try:
595-
response = session.get(tag_value)
597+
response = session.get(tag_value, timeout=http_timeout)
596598
response.raise_for_status()
597599
pem_bytes = response.content
598600
cert_metadata = get_certificate_metadata(pem_bytes, domain=domain)
@@ -677,6 +679,7 @@ def check_bimi(
677679
bimi_results["record"],
678680
include_tag_descriptions=include_tag_descriptions,
679681
domain=domain,
682+
http_timeout=timeout,
680683
)
681684
bimi_results["tags"] = parsed_bimi["tags"]
682685
if "image" in parsed_bimi.keys():

checkdmarc/mta_sts.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818

1919
from checkdmarc.utils import query_dns, WSP_REGEX
20-
from checkdmarc._constants import SYNTAX_ERROR_MARKER, USER_AGENT
20+
from checkdmarc._constants import SYNTAX_ERROR_MARKER, USER_AGENT, DEFAULT_HTTP_TIMEOUT
2121

2222
"""Copyright 2019-2023 Sean Whalen
2323
@@ -308,12 +308,15 @@ def parse_mta_sts_record(
308308
return OrderedDict(tags=tags, warnings=warnings)
309309

310310

311-
def download_mta_sts_policy(domain: str) -> OrderedDict:
311+
def download_mta_sts_policy(
312+
domain: str, http_timeout: float = DEFAULT_HTTP_TIMEOUT
313+
) -> OrderedDict:
312314
"""
313315
Downloads a domains MTA-HTS policy
314316
315317
Args:
316318
domain (str): A domain name
319+
http_timeout (float): HTTP timeout in seconds
317320
318321
Returns:
319322
OrderedDict: An ``OrderedDict`` with the following keys:
@@ -331,7 +334,7 @@ def download_mta_sts_policy(domain: str) -> OrderedDict:
331334
url = f"https://mta-sts.{domain}/.well-known/mta-sts.txt"
332335
logging.debug(f"Attempting to download HTA-MTS policy from {url}")
333336
try:
334-
response = session.get(url)
337+
response = session.get(url, timeout=http_timeout)
335338
response.raise_for_status()
336339
if "Content-Type" in response.headers:
337340
content_type = response.headers["Content-Type"].split(";")[0]
@@ -467,7 +470,7 @@ def check_mta_sts(
467470
warnings = mta_sts_record["warnings"]
468471
mta_sts_record = parse_mta_sts_record(mta_sts_record["record"])
469472
mta_sts_results["id"] = mta_sts_record["tags"]["id"]["value"]
470-
policy = download_mta_sts_policy(domain)
473+
policy = download_mta_sts_policy(domain, timeout=timeout)
471474
warnings += policy["warnings"]
472475
policy = parse_mta_sts_policy(policy["policy"])
473476
warnings += policy["warnings"]

0 commit comments

Comments
 (0)