Skip to content

Commit 21bf6fd

Browse files
committed
🎉 Advance DrHeader to evalute HSTS max-age #250:bug
1 parent c2098d5 commit 21bf6fd

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

drheader/validators/header_validator.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,31 @@ def validate_value(self, config, header, directive=None):
5353
header_value = self.headers[header]
5454
strip_chars = base.get_delimiter(config, 'strip') if header.lower() in _STRIP_HEADERS else None
5555
header_items = utils.parse_policy(header_value, item_delimiter=delimiter, strip=strip_chars)
56-
5756
if config.get('preserve-order'):
5857
header_items = [item.lower() for item in header_items]
5958
expected_lower = [item.lower() for item in expected]
6059
else:
6160
header_items = {item.lower() for item in header_items}
6261
expected_lower = {item.lower() for item in expected}
63-
64-
if header_items != expected_lower:
62+
if any("max-age" in item for item in header_items):
63+
header_items_without_ma = []
64+
for item in header_items:
65+
if "max-age" not in item:
66+
header_items_without_ma.append(item)
67+
else:
68+
header_items_ma = item.split("max-age=")[1]
69+
expected_without_ma = []
70+
for expect in expected:
71+
if "max-age" not in expect:
72+
expected_without_ma.append(expect)
73+
else:
74+
expected_ma = expect.split("max-age=")[1]
75+
if header_items_without_ma != expected_without_ma or int(header_items_ma) < int(expected_ma):
76+
severity = config.get('severity', 'high')
77+
error_type = report.ErrorType.VALUE
78+
return report.ReportItem(severity, error_type, header, value=header_value, expected=expected,
79+
delimiter=delimiter)
80+
if any("max-age" in item for item in header_items) == False and header_items != expected_lower:
6581
severity = config.get('severity', 'high')
6682
error_type = report.ErrorType.VALUE
6783
return report.ReportItem(severity, error_type, header, value=header_value, expected=expected,

0 commit comments

Comments
 (0)