Skip to content

Commit c82d5db

Browse files
committed
Auto merge of #2100 - kzys:nginx-headers, r=jtgeibel
Move security-related HTTP response headers from Rust to nginx.conf We'd like to have these headers on the FastBoot server as well.
2 parents 758ada4 + 93ea166 commit c82d5db

File tree

3 files changed

+23
-71
lines changed

3 files changed

+23
-71
lines changed

config/nginx.conf.erb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
<%
2+
def s3_host(env)
3+
cdn = env['S3_CDN']
4+
if cdn and !cdn.empty?
5+
return cdn
6+
end
7+
8+
region = env['S3_REGION']
9+
bucket = env['S3_BUCKET']
10+
11+
if region and !region.empty?
12+
region = "-#{region}"
13+
end
14+
15+
return "#{bucket}.s3#{region}.amazonaws.com"
16+
end
17+
%>
18+
119
daemon off;
220
#Heroku dynos have at least 4 cores.
321
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;
@@ -121,6 +139,11 @@ http {
121139
expires max;
122140
}
123141

142+
add_header X-Content-Type-Options "nosniff";
143+
add_header X-Frame-Options "SAMEORIGIN";
144+
add_header X-XSS-Protection "1; mode=block";
145+
add_header Content-Security-Policy "default-src 'self'; connect-src 'self' https://docs.rs https://<%= s3_host(ENV) %>; script-src 'self' 'unsafe-eval' https://www.google.com; style-src 'self' https://www.google.com https://ajax.googleapis.com; img-src *; object-src 'none'";
146+
124147
add_header Strict-Transport-Security "max-age=31536000" always;
125148
add_header Vary 'Accept, Accept-Encoding, Cookie';
126149
proxy_set_header Host $http_host;

src/middleware.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use self::debug::*;
1515
use self::ember_index_rewrite::EmberIndexRewrite;
1616
use self::head::Head;
1717
use self::log_connection_pool_status::LogConnectionPoolStatus;
18-
use self::security_headers::SecurityHeaders;
1918
use self::static_or_continue::StaticOrContinue;
2019

2120
pub mod app;
@@ -28,7 +27,6 @@ mod head;
2827
mod log_connection_pool_status;
2928
mod log_request;
3029
mod require_user_agent;
31-
mod security_headers;
3230
mod static_or_continue;
3331

3432
use conduit_conditional_get::ConditionalGet;
@@ -74,9 +72,6 @@ pub fn build_middleware(app: Arc<App>, endpoints: R404) -> MiddlewareBuilder {
7472
env == Env::Production,
7573
));
7674

77-
if env == Env::Production {
78-
m.add(SecurityHeaders::new(&config.uploader));
79-
}
8075
m.add(AppMiddleware::new(app));
8176

8277
// Parse and save the user_id from the session cookie as part of the authentication logic

src/middleware/security_headers.rs

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)