Skip to content

Commit

Permalink
[TECH] Forcer le HTTPS sur les environnements non dev
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Oct 29, 2024
2 parents 1e55b2e + d7aa760 commit d8b7346
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 0 deletions.
9 changes: 9 additions & 0 deletions admin/servers.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ split_clients "${request_id}" $upstream_host {
* <%= ENV['APP'].gsub(/^pix-[^-]+-/, "pix-api-") %>.<%= ENV['API_HOST_SUFFIX'] || 'scalingo.io' %>;
}

#add a catch all on http port to forward to the convenient https
server {
listen 80 default_server;
server_name _;
add_header Strict-Transport-Security "max-age=31536001; includeSubDomains; preload";
return 301 https://$host$request_uri;
}

server {
access_log logs/access.log keyvalue;
server_name localhost;
Expand Down Expand Up @@ -119,6 +127,7 @@ server {
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection 1;
add_header Strict-Transport-Security "max-age=31536001; includeSubDomains; preload";

<% ENV.each do |key,value|
if key.start_with? 'ADD_HTTP_HEADER' %>
Expand Down
11 changes: 11 additions & 0 deletions api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ const createBareServer = function () {
},
};

// Force https on non-dev environments
if (config.environment !== 'development') {
serverConfiguration.routes.security = {
hsts: {
includeSubDomains: true,
preload: true,
maxAge: 31536000,
},
};
}

return new Hapi.server(serverConfiguration);
};

Expand Down
9 changes: 9 additions & 0 deletions certif/servers.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ split_clients "${request_id}" $upstream_host {
* <%= ENV['APP'].gsub(/^pix-[^-]+-/, "pix-api-") %>.<%= ENV['API_HOST_SUFFIX'] || 'scalingo.io' %>;
}

#add a catch all on http port to forward to the convenient https
server {
listen 80 default_server;
server_name _;
add_header Strict-Transport-Security "max-age=31536001; includeSubDomains; preload";
return 301 https://$host$request_uri;
}

server {
access_log logs/access.log keyvalue;
server_name localhost;
Expand Down Expand Up @@ -136,6 +144,7 @@ server {
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection 1;
add_header Strict-Transport-Security "max-age=31536001; includeSubDomains; preload";

<% ENV.each do |key,value|
if key.start_with? 'ADD_HTTP_HEADER' %>
Expand Down
9 changes: 9 additions & 0 deletions junior/servers.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ upstream api {
server <%= ENV['APP'].gsub(/^pix-[^-]+-/, "pix-api-") %>.<%= ENV['API_HOST_SUFFIX'] || 'scalingo.io' %>:443 max_fails=<%= ENV['NGINX_UPSTREAM_MAX_FAILS'] || 3 %> fail_timeout=<%= ENV['NGINX_UPSTREAM_FAIL_TIMEOUT'] || '5s' %>;
}

#add a catch all on http port to forward to the convenient https
server {
listen 80 default_server;
server_name _;
add_header Strict-Transport-Security "max-age=31536001; includeSubDomains; preload";
return 301 https://$host$request_uri;
}

server {
access_log logs/access.log keyvalue;
server_name localhost;
Expand Down Expand Up @@ -114,6 +122,7 @@ server {
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection 1;
add_header Strict-Transport-Security "max-age=31536001; includeSubDomains; preload";

<% ENV.each do |key,value|
if key.start_with? 'ADD_HTTP_HEADER' %>
Expand Down
9 changes: 9 additions & 0 deletions mon-pix/servers.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ split_clients "${request_id}" $upstream_host {
* <%= ENV['APP'].gsub(/^pix-[^-]+-/, "pix-api-") %>.<%= ENV['API_HOST_SUFFIX'] || 'scalingo.io' %>;
}

#add a catch all on http port to forward to the convenient https
server {
listen 80 default_server;
server_name _;
add_header Strict-Transport-Security "max-age=31536001; includeSubDomains; preload";
return 301 https://$host$request_uri;
}

server {
access_log logs/access.log keyvalue;
server_name localhost;
Expand Down Expand Up @@ -143,6 +151,7 @@ server {
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection 1;
add_header Strict-Transport-Security "max-age=31536001; includeSubDomains; preload";

<% ENV.each do |key,value|
if key.start_with? 'ADD_HTTP_HEADER' %>
Expand Down
9 changes: 9 additions & 0 deletions orga/servers.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ split_clients "${request_id}" $upstream_host {
* <%= ENV['APP'].gsub(/^pix-[^-]+-/, "pix-api-") %>.<%= ENV['API_HOST_SUFFIX'] || 'scalingo.io' %>;
}

#add a catch all on http port to forward to the convenient https
server {
listen 80 default_server;
server_name _;
add_header Strict-Transport-Security "max-age=31536001; includeSubDomains; preload";
return 301 https://$host$request_uri;
}

server {
access_log logs/access.log keyvalue;
server_name localhost;
Expand Down Expand Up @@ -136,6 +144,7 @@ server {
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection 1;
add_header Strict-Transport-Security "max-age=31536001; includeSubDomains; preload";

<% ENV.each do |key,value|
if key.start_with? 'ADD_HTTP_HEADER' %>
Expand Down
9 changes: 9 additions & 0 deletions servers.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ log_format keyvalue
# as we are about to override it in the server directive here below
access_log off;

#add a catch all on http port to forward to the convenient https
server {
listen 80 default_server;
server_name _;
add_header Strict-Transport-Security "max-age=31536001; includeSubDomains; preload";
return 301 https://$host$request_uri;
}

server {
access_log logs/access.log keyvalue;
server_name localhost;
Expand All @@ -39,6 +47,7 @@ server {
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection 1;
add_header Strict-Transport-Security "max-age=31536001; includeSubDomains; preload";

<% ENV.each do |key,value|
if key.start_with? 'ADD_HTTP_HEADER' %>
Expand Down

0 comments on commit d8b7346

Please sign in to comment.