Skip to content

Commit e9e212c

Browse files
authored
Merge pull request #154 from dhs-ncats/tighten-www-redirect-check
Redirects to www only matter if they're within the same hostname
2 parents 86a860c + 1b736c7 commit e9e212c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

pshtt/pshtt.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ def basic_check(endpoint):
335335
base_immediate = parent_domain_for(subdomain_immediate)
336336

337337
endpoint.redirect_immediately_to = immediate
338-
endpoint.redirect_immediately_to_www = (re.match(r'^https?://www\.', immediate) is not None)
339338
endpoint.redirect_immediately_to_https = immediate.startswith("https://")
340339
endpoint.redirect_immediately_to_http = immediate.startswith("http://")
341340
endpoint.redirect_immediately_to_external = (base_original != base_immediate)
@@ -344,6 +343,14 @@ def basic_check(endpoint):
344343
(subdomain_original != subdomain_immediate)
345344
)
346345

346+
# We're interested in whether an endpoint redirects to the www version
347+
# of itself (not whether it redirects to www prepended to any other
348+
# hostname, even within the same parent domain).
349+
endpoint.redirect_immediately_to_www = (
350+
subdomain_immediate.startswith("www.") and
351+
(re.sub("www\.", "", subdomain_immediate) == subdomain_original)
352+
)
353+
347354
if ultimate_req is not None:
348355
# For ultimate destination, use the URL we arrived at,
349356
# not Location header. Auto-resolves relative redirects.
@@ -592,12 +599,6 @@ def root_down(endpoint):
592599
)
593600
)
594601

595-
def goes_to_www(endpoint):
596-
return (
597-
endpoint.redirect_immediately_to_www and
598-
(not endpoint.redirect_immediately_to_external)
599-
)
600-
601602
all_roots_unused = root_unused(https) and root_unused(http)
602603

603604
all_roots_down = root_down(https) and root_down(http)
@@ -606,8 +607,8 @@ def goes_to_www(endpoint):
606607
at_least_one_www_used and
607608
all_roots_unused and (
608609
all_roots_down or
609-
goes_to_www(https) or
610-
goes_to_www(http)
610+
https.redirect_immediately_to_www or
611+
http.redirect_immediately_to_www
611612
)
612613
)
613614

0 commit comments

Comments
 (0)