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

Add security related headers to build.servo.org #511

Closed
wants to merge 1 commit into from

Conversation

@jarondl
Copy link

jarondl commented Oct 17, 2016

Add some headers to build.servo.org to improve our Mozilla Observatory
score. The helps the cause of #473, by raising our score from F (0) to a
whopping B- (65). The testing is still basic, the docker-observatory
based testing will go in a different PR.

To get to an A+ we must first implement https.

This is the local observatory report:

Score Rule                       Description
      -20 redirection                Does not redirect to an https site.
      -20 strict-transport-security  HTTP Strict Transport Security (HSTS)
        header cannot be set for sites not available over https.
       -5 contribute                 Contribute.json file missing from root
        of website.
        5 content-security-policy    Content Security Policy (CSP)
        implemented without 'unsafe-inline' or 'unsafe-eval'.
        5 x-frame-options            X-Frame-Options (XFO) implemented via
        the CSP frame-ancestors directive.

    Score: 65
    Grade: B-


This change is Reviewable

Add some headers to `build.servo.org` to improve our Mozilla Observatory
score. The helps the cause of #473, by raising our score from F (0) to a
whopping B- (65). The testing is still basic, the docker-observatory
based testing will go in a different PR.

To get to an A+ we must first implement https.

This is the local observatory report:

   Score Rule                       Description
      -20 redirection                Does not redirect to an https site.
      -20 strict-transport-security  HTTP Strict Transport Security (HSTS)
        header cannot be set for sites not available over https.
       -5 contribute                 Contribute.json file missing from root
        of website.
        5 content-security-policy    Content Security Policy (CSP)
        implemented without 'unsafe-inline' or 'unsafe-eval'.
        5 x-frame-options            X-Frame-Options (XFO) implemented via
        the CSP frame-ancestors directive.

    Score: 65
    Grade: B-
@highfive
Copy link

highfive commented Oct 17, 2016

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @aneeshusa (or someone else) soon.

@aneeshusa
Copy link
Member

aneeshusa commented Oct 17, 2016

@jarondl Can you point me to some documentation about the contribute.json file? I haven't heard of this and didn't see it on the observatory results.

@jarondl
Copy link
Author

jarondl commented Oct 17, 2016

Yes, contribute.json is quite obscure. I have found out about it only when I've browsed through the observatory code to resolve some issues.
According to the observatory, only Mozilla related websites must have it, see for example:

https://observatory.mozilla.org/analyze.html?host=mozilla.org

The list of mozilla related sites is hard coded here: https://github.com/mozilla/http-observatory/blob/7dd04ff5b51e39698a8b683df33ef430b4ed4213/httpobs/conf/httpobs.conf#L33
and servo is not there, but in all fairness it should be. We should submit a PR to add it, and lower our grade from 70 to 65.

@jarondl
Copy link
Author

jarondl commented Oct 18, 2016

I believe the tests have failed because buildbot is down in travis. This should be solved by #505, right?

@aneeshusa
Copy link
Member

aneeshusa commented Oct 30, 2016

Buildbot immediately stops on Travis after being started (due to our fake test credentials not validating IIRC), which I don't have an easy fix for. In the meantime, I believe this is why I added the make_cors_request function in #375, since Nginx should still add the headers even though the status code indicates error (since Buildbot is down). Try adding/using that in this test.

Copy link
Member

aneeshusa left a comment

Sorry about the delay in reviewing. The headers themselves and the test case look good modulo a few nits, the Salt side needs a little more work.

@@ -0,0 +1,15 @@
# The following headers were added to pass the mozilla http observatory

This comment has been minimized.

Copy link
@aneeshusa

aneeshusa Oct 30, 2016

Member

nit: mozilla -> Mozilla

@@ -0,0 +1,15 @@
# The following headers were added to pass the mozilla http observatory
# test suit.

This comment has been minimized.

Copy link
@aneeshusa

aneeshusa Oct 30, 2016

Member

spelling: suit -> suite

# All of them are very simple in this case, because both homu and buildbot
# do not use external resources.

# CSP is the most important one

This comment has been minimized.

Copy link
@aneeshusa

aneeshusa Oct 30, 2016

Member

The options we're setting are fairly basic and IMO the headers are readable enough as is that we don't need an expository comment for each one.

@@ -14,6 +14,15 @@ nginx:
- watch_in:
- service: nginx

/etc/nginx/conf.d/https_headers.conf:
file.managed:
- source: salt://nginx/https_headers.conf

This comment has been minimized.

Copy link
@aneeshusa

aneeshusa Oct 30, 2016

Member

Use salt://{{ tpldir }}/files/https_headers.conf, and make a files subdir to put the config file in.

I'm not sure how well you know Salt, but we'll also want the /etc/nginx/conf.d state from #375 and some requisites to order things correctly/restart nginx automatically on config change. I can also take care of this if you'd like.

failures = []
for header in expected_headers:
if header not in actual_headers:
failures.append('Missing or changed header - {}:{}'.format(*header))

This comment has been minimized.

Copy link
@aneeshusa

aneeshusa Oct 30, 2016

Member

This line is failing tidy because it is too long.

"default-src 'self'; frame-ancestors 'none'"),
('X-Frame-Options', 'DENY'),
('X-XSS-Protection', '1; mode=block'),
('X-Content-Type-Options', 'nosniff')]

This comment has been minimized.

Copy link
@aneeshusa

aneeshusa Oct 30, 2016

Member

style nit: leave a trailing comma after this last tuple, and put the closing ] by itself on the next line.

failures.append('Missing or changed header - {}:{}'.format(*header))

if len(failures) > 0:
return Failure('nginx is serving wrong securirty headers',

This comment has been minimized.

Copy link
@aneeshusa

aneeshusa Oct 30, 2016

Member

spelling: securirty -> security

@aneeshusa
Copy link
Member

aneeshusa commented Oct 30, 2016

Also, please open a separate issue about contribute.json to keep this PR about headers.

@jarondl
Copy link
Author

jarondl commented Oct 30, 2016

Hi @aneeshusa , thanks for reviewing, I will work on it.

@aneeshusa
Copy link
Member

aneeshusa commented Jan 7, 2018

I'm going to close this as it's been inactive for a while; anyone is welcome to pick this work up again.

@aneeshusa aneeshusa closed this Jan 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.