Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Changed is_hsts() function to check both https endpoints. #204

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

mcdonnnj
Copy link
Member

@mcdonnnj mcdonnnj commented Aug 15, 2019

Work-in-progress: DO NOT MERGE!!

This PR is to fix #194 by checking both https and httpswww endpoints to determine HSTS status for the domain.

If an https endpoint is live then its HSTS status is used to determine the domain's HSTS status.
@mcdonnnj mcdonnnj requested a review from a team August 15, 2019 20:44
@mcdonnnj mcdonnnj self-assigned this Aug 15, 2019
@@ -1199,16 +1199,20 @@ def is_missing_intermediate_cert(domain):

def is_hsts(domain):
"""
Domain has HSTS if its canonical HTTPS endpoint has HSTS.
Domain has HSTS if both https and httpswww endpoints have HSTS when live.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The canonical endpoint was (I think) introduced by @h-m-f-t in an effort to make the HTTPS report results more digestible by the less technical. I'd have to know his thoughts on this change before approving.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @climber-girl 's point was that if both endpoints are live then both should have HSTS. I think this section of RFC6797 touches on what I mean although it is in the context of a web application and the includeSubDomains directive.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't completely understand all of the reasons for only focusing on the canonical endpoint. It seems like we assume that that is where most users will end up, but plenty of others may use the other endpoint (if it is live), and attackers could take advantage of the other endpoint (via spear-phishing URLs and the like) if it is not sufficiently protected.

strictly_forces_https already looks at both http endpoints, not just the canonical one, but downgrades_https currently only looks at the canonical https endpoint. If we switch this HSTS check to check both endpoints, then we should probably change some other checks to look at both endpoints (such as downgrades_https and maybe even follow-on sslyze checks). Should most of these checks for both endpoints be in new "Strictly_Enforces" checks or should these be changed in the existing checks?

@jsf9k jsf9k changed the title Changed is_hsts() function to check both https endpoints. WIP: Changed is_hsts() function to check both https endpoints. Aug 15, 2019
@jsf9k jsf9k added this to In progress in BOD 18-01 via automation Aug 15, 2019
echudow
echudow previously approved these changes Aug 19, 2019
Copy link
Collaborator

@echudow echudow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just remember that this has the potential to negatively effect the results for a number of domains, so be prepared for questions.

@jsf9k jsf9k requested review from dav3r and h-m-f-t August 19, 2019 19:51
Copy link
Member

@dav3r dav3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution works for me- the docstring is clear and the code is clean. 👍

BOD 18-01 automation moved this from In progress to Reviewer approved Aug 19, 2019
@echudow echudow dismissed their stale review August 20, 2019 12:19

This code will fail if any of the hsts values are None (which is possible if there is a problem getting the HSTS header such as when Client Authentication is required)

BOD 18-01 automation moved this from Reviewer approved to Review in progress Aug 20, 2019
The hsts values for any endpoint can be None, so the code needs to gracefully handle when it is None by viewing it as Unknown and only using the other actual values instead.
@echudow
Copy link
Collaborator

echudow commented Aug 20, 2019

I committed changes to address when the hsts field is None. There might be a more concise way to do this using Python logic, but I was very confused at first seeing that in Python when there are None's the order of an or matters so that (None or False) != (False or None).

@mcdonnnj
Copy link
Member Author

@echudow in hsts_check() it explicitly sets endpoint.hsts = False if there is no STS header. Would you elaborate on what circumstances you would see a None for the endpoint.hsts value?

@echudow
Copy link
Collaborator

echudow commented Aug 20, 2019

@mcdonnnj You're right. Sorry, I was testing this code change in my fork which is a little different and leaves endpoint.hsts as None if it couldn't fully connect to the site and get the headers. Your original code should work here. My update should work too even without there ever being any None values since that is a subcase (and it would be easier for me to merge in the upstream changes).

@mcdonnnj
Copy link
Member Author

@echudow Ah, that makes sense. I agree that there's no harm in leaving the change. I just wanted to make sure it was needed and I see why it's useful for compatibility with your fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Review in progress
BOD 18-01
  
Review in progress
Development

Successfully merging this pull request may close these issues.

HSTS not checked at both https endpoints
4 participants