This repository was archived by the owner on Jul 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
[WIP] Implement secure_headers gem #282
Open
jgarber623-gov
wants to merge
5
commits into
master
Choose a base branch
from
secure-headers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
295d16c
Revert "Disable default ActionDispatch headers in production"
jgarber623-gov a35db52
Add secure_headers gem and LICENSE info
jgarber623-gov 2c3600b
Implement secure_headers features
jgarber623-gov d13908d
Change HSTS header max-age to 1 year
jgarber623-gov ef8d8f9
Rework nginx configuration (#282 feedback)
jgarber623-gov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -332,30 +332,13 @@ files: | |
|
|
||
| charset utf-8; | ||
|
|
||
| # With Content Security Policy (CSP) enabled (and a browser that supports it (http://caniuse.com/#feat=contentsecuritypolicy), | ||
| # you can tell the browser that it can only download content from the domains you explicitly allow | ||
| # CSP can be quite difficult to configure, and cause real issues if you get it wrong | ||
| # There is website that helps you generate a policy here http://cspisawesome.com/ | ||
| add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://dap.digitalgov.gov https://www.google-analytics.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://www.google-analytics.com *.tile.openstreetmap.org; frame-ancestors 'none'; frame-src https://www.youtube.com;" always; | ||
|
|
||
| # MIME type sniffing security protection | ||
| # There are very few edge cases where you wouldn't want this enabled. | ||
| add_header X-Content-Type-Options nosniff always; | ||
|
|
||
| # The X-Frame-Options header indicates whether a browser should be allowed | ||
| # to render a page within a frame or iframe. | ||
| add_header X-Frame-Options SAMEORIGIN always; | ||
|
|
||
| # Force the latest IE version | ||
| add_header X-UA-Compatible "IE=Edge"; | ||
|
|
||
| # The X-XSS-Protection header is used by Internet Explorer version 8+ | ||
| # The header instructs IE to enable its inbuilt anti-cross-site scripting filter. | ||
| add_header X-XSS-Protection "1; mode=block" always; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meh. If we can, great, otherwise, don't sweat it. |
||
|
|
||
| # HSTS (HTTP Strict Transport Security) | ||
| # This header tells browsers to cache the certificate for six months and to connect exclusively via HTTPS. | ||
| add_header Strict-Transport-Security "max-age=15768000" always; | ||
| # This header tells browsers to cache the certificate for one year and to connect exclusively via HTTPS. | ||
| add_header Strict-Transport-Security "max-age=31556952" always; | ||
|
|
||
| if ($redirect_uri) { | ||
| return 301 https://$redirect_uri; | ||
|
|
@@ -372,18 +355,30 @@ files: | |
| return 301 https://$host$request_uri; | ||
| } | ||
|
|
||
| location ~* \.(?:manifest|appcache|xml|json|pdf|docx?)$ { | ||
| location ~* \.(?:json|xml)$ { | ||
| access_log off; | ||
| add_header Cache-Control "no-cache, no-store, must-revalidate"; | ||
|
|
||
| try_files $uri @move-mil-rails; | ||
| } | ||
|
|
||
| location ~* \.(?:ico|txt)$ { | ||
| access_log off; | ||
|
|
||
| add_header Cache-Control "no-cache, no-store, must-revalidate"; | ||
| } | ||
|
|
||
| location /assets/ { | ||
| access_log off; | ||
|
|
||
| add_header Cache-Control "max-age=31536000"; | ||
| } | ||
|
|
||
| location /documents/ { | ||
| access_log off; | ||
|
|
||
| add_header Cache-Control "no-cache, no-store, must-revalidate"; | ||
| } | ||
|
|
||
| try_files $uri @move-mil-rails; | ||
|
|
||
| error_page 404 = /404.html; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,9 +39,6 @@ | |
| # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache | ||
| # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX | ||
|
|
||
| # Disable ActionDispatch's default headers (these are handled by nginx) | ||
| config.action_dispatch.default_headers = {} | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for this anymore… |
||
| # Mount Action Cable outside main process or domain | ||
| # config.action_cable.mount_path = nil | ||
| # config.action_cable.url = 'wss://example.com/cable' | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Rails.application.configure do | ||
| config.action_dispatch.default_headers.merge!( | ||
| 'X-UA-Compatible' => 'IE=Edge' | ||
| ) | ||
| end | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. secure_headers doesn't cover this IE-specific header, so adding this initializer here and merging it with Action Dispatch's default headers. |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # rubocop:disable Lint/PercentStringArray | ||
| SecureHeaders::Configuration.default do |config| | ||
| config.csp = { | ||
| base_uri: %w['self'], | ||
| block_all_mixed_content: true, | ||
| child_src: %w[www.youtube.com], | ||
| default_src: %w['self'], | ||
| form_action: %w['self'], | ||
| frame_ancestors: %w['none'], | ||
| img_src: %w['self' data: www.google-analytics.com *.tile.openstreetmap.org], | ||
| plugin_types: %w[application/x-shockwave-flash], | ||
| script_src: %w['self' 'unsafe-inline' dap.digitalgov.gov www.google-analytics.com], | ||
| style_src: %w['self' 'unsafe-inline'] | ||
| } | ||
|
|
||
| config.hsts = "max-age=#{1.year.to_i}" | ||
| config.referrer_policy = %w[origin-when-cross-origin strict-origin-when-cross-origin] | ||
| config.x_content_type_options = 'nosniff' | ||
| config.x_download_options = 'noopen' | ||
| config.x_frame_options = 'deny' | ||
| config.x_permitted_cross_domain_policies = 'none' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| config.x_xss_protection = '1; mode=block' | ||
| end | ||
| # rubocop:enable Lint/PercentStringArray | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need to make sure this CSP header is delivered on root requests. For the error pages in particular, as well as any other directly delivered HTML, we should add one in.