Sécurisation de nginx

Dans le but de sécuriser nginx, la documentation propose plusieurs header. Nous n’avons pour le moment pas vérifié si ça marchait, mais simplement fait confiance à la documentation (vérification dans un second temps).

ssl_protocols TLSv1.2;
ssl_session_cache shared:SSL:10m;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/dhparam.pem;

ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:!ECDHE-PSK-AES256-CBC-SHA384:!ECDHE-PSK-AES256-CBC-SHA:!SRP-RSA-AES-256-CBC-SHA:!SRP-AES-256-CBC-SHA:!RSA-PSK-AES256-CBC-SHA384:!DHE-PSK-AES256-CBC-SHA384:!RSA-PSK-AES256-CBC-SHA:!DHE-PSK-AES256-CBC-SHA:!AES256-SHA:!PSK-AES256-CBC-SHA384:!PSK-AES256-CBC-SHA:!ECDHE-PSK-AES128-CBC-SHA256:!ECDHE-PSK-AES128-CBC-SHA:!SRP-RSA-AES-128-CBC-SHA:!SRP-AES-128-CBC-SHA:!RSA-PSK-AES128-CBC-SHA256:!DHE-PSK-AES128-CBC-SHA256:!RSA-PSK-AES128-CBC-SHA:!DHE-PSK-AES128-CBC-SHA:!AES128-SHA:!PSK-AES128-CBC-SHA256:!PSK-AES128-CBC-SHA:!TLS_AES_256_GCM_SHA384:!TLS_CHACHA20_POLY1305_SHA256:!TLS_AES_128_GCM_SHA256";

ssl_stapling on;
ssl_stapling_verify on;

add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options DENY;
add_header X-XSS-Protection "1; mode=block"; 
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains" always ;

add_header Content-Security-Policy
	"default-src  'self'
	http://localhost:8000/wp-includes/blocks/navigation/style.min.css?ver=5.9.3
	http://localhost:8000/wp-content/themes/twentytwentytwo/style.css?ver=1.1
	http://localhost:8000/wp-content/themes/twentytwentytwo/assets/images/flight-path-on-transparent-d.png
	http://localhost:8000/wp-includes/blocks/navigation/view.min.js?ver=3776ea67846b3bb10fe8f7cdd486b0ba
	;" always;

Nous pouvons vous dire que la configuration de Content-Security-Policy va poser un problème en l’état et que la page wordpress ne va pas apparaître de façon correcte. Nous avons une solution qui consiste à utiliser le mot-clé unsafe-inline cependant l’anssi nous demande d’interdire ce mot. Nous vous montrerons plus tard dans le hugo la redirection sur 192.168.3.2/blog

Untitled

De façons à pouvoir faire un curl -I avec un peu plus d’information, nous avons autorisé HEAD en plus de PUT, GET, POST de façon temporaire.

┌──(l01㉿L01)-[~/DM4/nginx]
└─$ curl -kI https://192.168.3.2 --cert-type P12  -E ./l01.p12:nopass
HTTP/1.1 200 OK
Date: Fri, 06 May 2022 16:29:51 GMT
Content-Type: text/html
Content-Length: 8
Last-Modified: Tue, 03 May 2022 11:55:39 GMT
Connection: keep-alive
ETag: "6271183b-8"
Allow: GET, POST, PUT, HEAD
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Content-Security-Policy: default-src 'self';
Strict-Transport-Security: max-age=31536000; includeSubdomains
Accept-Ranges: bytes

Sécurité en plus

Nous avons mis en place un système permettant de mieux résister aux attaques ddos.

[...]

# protection contre ddos 1
limit_conn_zone $binary_remote_addr zone=addr:10m;
limit_conn_status 429;
limit_req_zone $binary_remote_addr zone=one:10m rate=3r/s;
limit_req_status 429;

[...]

server {

		[...]

		# protection contre ddos 2
		limit_conn addr 10;
		limit_conn_log_level warn;
		limit_req zone=one burst=5 delay=9;

		[...]
}

Grâce à cette configuration, nous ralentissons les requêtes qui arrivent de manières trop répétées sur un temps trop court.

Untitled