Handle some security settings.

This commit is contained in:
Andrea Dell'Amico 2021-07-28 14:18:03 +02:00
parent e538066bf4
commit 71a7fc437a
Signed by: adellam
GPG Key ID: 147ABE6CEB9E20FF
2 changed files with 28 additions and 0 deletions

View File

@ -89,6 +89,16 @@ nginx_cors_allowed_methods: 'GET, POST, OPTIONS'
# 'Accept, Accept-CH, Accept-Charset, Accept-Datetime, Accept-Encoding, Accept-Ext, Accept-Features, Accept-Language, Accept-Params, Accept-Ranges, Access-Control-Allow-Credentials, Access-Control-Allow-Headers, Access-Control-Allow-Methods, Access-Control-Allow-Origin, Access-Control-Expose-Headers, Access-Control-Max-Age, Access-Control-Request-Headers, Access-Control-Request-Method, Age, Allow, Alternates, Authentication-Info, Authorization, C-Ext, C-Man, C-Opt, C-PEP, C-PEP-Info, CONNECT, Cache-Control, Compliance, Connection, Content-Base, Content-Disposition, Content-Encoding, Content-ID, Content-Language, Content-Length, Content-Location, Content-MD5, Content-Range, Content-Script-Type, Content-Security-Policy, Content-Style-Type, Content-Transfer-Encoding, Content-Type, Content-Version, Cookie, Cost, DAV, DELETE, DNT, DPR, Date, Default-Style, Delta-Base, Depth, Derived-From, Destination, Differential-ID, Digest, ETag, Expect, Expires, Ext, From, GET, GetProfile, HEAD, HTTP-date, Host, IM, If, If-Match, If-Modified-Since, If-None-Match, If-Range, If-Unmodified-Since, Keep-Alive, Label, Last-Event-ID, Last-Modified, Link, Location, Lock-Token, MIME-Version, Man, Max-Forwards, Media-Range, Message-ID, Meter, Negotiate, Non-Compliance, OPTION, OPTIONS, OWS, Opt, Optional, Ordering-Type, Origin, Overwrite, P3P, PEP, PICS-Label, POST, PUT, Pep-Info, Permanent, Position, Pragma, ProfileObject, Protocol, Protocol-Query, Protocol-Request, Proxy-Authenticate, Proxy-Authentication-Info, Proxy-Authorization, Proxy-Features, Proxy-Instruction, Public, RWS, Range, Referer, Refresh, Resolution-Hint, Resolver-Location, Retry-After, Safe, Sec-Websocket-Extensions, Sec-Websocket-Key, Sec-Websocket-Origin, Sec-Websocket-Protocol, Sec-Websocket-Version, Security-Scheme, Server, Set-Cookie, Set-Cookie2, SetProfile, SoapAction, Status, Status-URI, Strict-Transport-Security, SubOK, Subst, Surrogate-Capability, Surrogate-Control, TCN, TE, TRACE, Timeout, Title, Trailer, Transfer-Encoding, UA-Color, UA-Media, UA-Pixels, UA-Resolution, UA-Windowpixels, URI, Upgrade, User-Agent, Variant-Vary, Vary, Version, Via, Viewport-Width, WWW-Authenticate, Want-Digest, Warning, Width, X-Content-Duration, X-Content-Security-Policy, X-Content-Type-Options, X-CustomHeader, X-DNSPrefetch-Control, X-Forwarded-For, X-Forwarded-Port, X-Forwarded-Proto, X-Frame-Options, X-Modified, X-OTHER, X-PING, X-PINGOTHER, X-Powered-By, X-Requested-With, Observe'
nginx_cors_allowed_headers: 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With,Accept-Language,X-CustomHeader,Content-Range,Range,Observe'
nginx_set_xss_protection: True
nginx_set_content_security_options: False
# Choiches: 'self', 'none', a list of domains
nginx_content_security_acl:
- 'self'
# - 'none'
# - '{{ ansible_domain }}'
nginx_set_frame_origin: False
# SAMEORIGIN, DENY, ''
nginx_x_frame_options: 'SAMEORIGIN'
# Find a set of acceptable defaults for the cache setup
nginx_cache_enabled: False

View File

@ -44,6 +44,15 @@ server {
error_log /var/log/nginx/{{ item.server_name }}_error.log;
{% endif %}
{% if nginx_set_xss_protection %}
add_header X-XSS-Protection "1; mode=block";
{% endif %}
{% if nginx_set_frame_origin %}
add_header X-Frame-Options "{{ nginx_x_frame_options }}";
{% endif %}
{% if nginx_set_content_security_options %}
add_header Content-Security-Policy "frame-ancestors {% for l in nginx_content_security_acl %} '{{ l }}'{% endfor %};";
{% endif %}
server_tokens {{ item.server_tokens | default('off') }};
{% if item.ssl_enabled and item.ssl_only %}
@ -249,6 +258,15 @@ server {
include /etc/nginx/snippets/nginx-server-ssl.conf;
{% if nginx_set_xss_protection %}
add_header X-XSS-Protection "1; mode=block";
{% endif %}
{% if nginx_set_frame_origin %}
add_header X-Frame-Options "{{ nginx_x_frame_options }}";
{% endif %}
{% if nginx_set_content_security_options %}
add_header Content-Security-Policy "frame-ancestors {% for l in nginx_content_security_acl %} '{{ l }}'{% endfor %};";
{% endif %}
server_tokens {{ item.server_tokens | default('off') }};
{% if nginx_cors_enabled %}