Skip to content

Commit 3e09e3f

Browse files
committed
feat: update HSTS checks to use the apex domain if it's available
1 parent c57c7df commit 3e09e3f

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

ready/checks/hsts.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def check_hsts_header_should_be_included_in_response(responses, **kwargs):
1717
def check_hsts_header_should_have_a_long_max_age(responses, **kwargs):
1818
try:
1919
hsts = responses["response"].headers.get("strict-transport-security", "")
20-
max_age_re = re.compile("max-age=(\d+)", re.IGNORECASE)
20+
max_age_re = re.compile(r"max-age=(\d+)", re.IGNORECASE)
2121
m = max_age_re.match(hsts)
2222
max_age = int(m.groups()[0])
2323
if max_age < 31536000:
@@ -40,9 +40,15 @@ def check_hsts_header_should_have_a_long_max_age(responses, **kwargs):
4040
# Check: HSTS Header should have includeSubdomains
4141
def check_hsts_header_should_have_includesubdomains(responses, **kwargs):
4242
hsts = responses["response"].headers.get("strict-transport-security", "")
43+
44+
# this check uses the response from the Apex/Second level domain if it fails for the
45+
# provided domain. See: https://github.com/sesh/ready/issues/22
46+
if "includesubdomains" not in hsts.lower() and responses.get("response_fld"):
47+
hsts = responses["response_fld"].headers.get("strict-transport-security", "") + " (from apex domain)"
48+
4349
return result(
4450
"includesubdomains" in hsts.lower(),
45-
f"HSTS Header should have includeSubdomains ({hsts})",
51+
f"HSTS Header should have includeSubDomains ({hsts})",
4652
"ssl_hsts_subdomains",
4753
**kwargs,
4854
)
@@ -51,9 +57,15 @@ def check_hsts_header_should_have_includesubdomains(responses, **kwargs):
5157
# Check: HSTS Header should have preload
5258
def check_hsts_header_should_have_preload(responses, **kwargs):
5359
hsts = responses["response"].headers.get("strict-transport-security", "")
60+
61+
# this check use the response from the Apex/Second Level domain if it exists
62+
# instead of any subdomains. See: https://github.com/sesh/ready/issues/22
63+
if responses.get("response_fld"):
64+
hsts = responses["response_fld"].headers.get("strict-transport-security", "") + " (from apex domain)"
65+
5466
return result(
55-
"preload" in hsts.lower(),
56-
f"HSTS Header should have preload ({hsts})",
67+
"preload" in hsts.lower() and "includesubdomains" in hsts.lower(),
68+
f"HSTS Header should have preload and includeSubDomains ({hsts})",
5769
"ssl_hsts_preload",
5870
**kwargs,
5971
)

ready/ready.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from importlib import resources
88
from . import checks as checks_module
99

10-
VERSION = "1.4.0"
10+
VERSION = "1.5.0"
1111

1212
from ready.checks.bad_response import (
1313
check_bad_response_cloudflare,
@@ -152,7 +152,7 @@ def ready(
152152
if USE_FLD:
153153
fld = get_fld(domain, fix_protocol=True)
154154
else:
155-
fld = "Disabled. Install tld if fld is different to domain."
155+
fld = "Disabled. Install tld to improve support for subdomains."
156156

157157
if not hide_output:
158158
print(f"URL (no scheme): {domain}, Domain (no path): {domain_with_no_path}, Second Level Domain: {fld}")
@@ -221,6 +221,10 @@ def ready(
221221
)
222222

223223
if USE_FLD and domain != fld:
224+
responses["response_fld"] = response_or_none(
225+
f"https://{fld}", "response_fld", request_filter, verify=False, headers=DEFAULT_HEADERS, timeout=3
226+
)
227+
224228
responses["dns_ns_response_fld"] = response_or_none(f"https://dns.google/resolve?name={fld}&type=NS")
225229
responses["dns_mx_response_fld"] = response_or_none(f"https://dns.google/resolve?name={fld}&type=MX")
226230
responses["dns_spf_response_fld"] = response_or_none(f"https://dns.google/resolve?name={fld}&type=SPF")

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = ready-check
3-
version = 1.4.0
3+
version = 1.5.0
44
author = Brenton Cleeland
55
author_email = [email protected]
66
description = A developer-friendly web scanning tool

0 commit comments

Comments
 (0)