@@ -17,7 +17,7 @@ def check_hsts_header_should_be_included_in_response(responses, **kwargs):
17
17
def check_hsts_header_should_have_a_long_max_age (responses , ** kwargs ):
18
18
try :
19
19
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 )
21
21
m = max_age_re .match (hsts )
22
22
max_age = int (m .groups ()[0 ])
23
23
if max_age < 31536000 :
@@ -40,9 +40,15 @@ def check_hsts_header_should_have_a_long_max_age(responses, **kwargs):
40
40
# Check: HSTS Header should have includeSubdomains
41
41
def check_hsts_header_should_have_includesubdomains (responses , ** kwargs ):
42
42
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
+
43
49
return result (
44
50
"includesubdomains" in hsts .lower (),
45
- f"HSTS Header should have includeSubdomains ({ hsts } )" ,
51
+ f"HSTS Header should have includeSubDomains ({ hsts } )" ,
46
52
"ssl_hsts_subdomains" ,
47
53
** kwargs ,
48
54
)
@@ -51,9 +57,15 @@ def check_hsts_header_should_have_includesubdomains(responses, **kwargs):
51
57
# Check: HSTS Header should have preload
52
58
def check_hsts_header_should_have_preload (responses , ** kwargs ):
53
59
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
+
54
66
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 } )" ,
57
69
"ssl_hsts_preload" ,
58
70
** kwargs ,
59
71
)
0 commit comments