|
8 | 8 | # This can be done by setting a `Content Security Policy` which |
9 | 9 | # whitelists trusted sources of content for your website. |
10 | 10 | # |
11 | | -# The example header below allows ONLY scripts that are loaded from |
12 | | -# the current website's origin (no inline scripts, no CDN, etc). |
13 | | -# That almost certainly won't work as-is for your website! |
| 11 | +# There is no policy that fits all websites, you will have to modify |
| 12 | +# the `Content-Security-Policy` directives in the example below depending |
| 13 | +# on your needs. |
14 | 14 | # |
15 | | -# To make things easier, you can use an online CSP header generator |
16 | | -# such as: https://www.cspisawesome.com/. |
| 15 | +# The example policy below aims to: |
17 | 16 | # |
| 17 | +# (1) Restrict all fetches by default to the origin of the current website |
| 18 | +# by setting the `default-src` directive to `'self'` - which acts as a |
| 19 | +# fallback to all "Fetch directives" (https://developer.mozilla.org/en-US/docs/Glossary/Fetch_directive). |
| 20 | +# |
| 21 | +# This is convenient as you do not have to specify all Fetch directives |
| 22 | +# that apply to your site, for example: |
| 23 | +# `connect-src 'self'; font-src 'self'; script-src 'self'; style-src 'self'`, etc. |
| 24 | +# |
| 25 | +# This restriction also means that you must explicitly define from |
| 26 | +# which site(s) your website is allowed to load resources from. |
| 27 | +# |
| 28 | +# (2) The `<base>` element is not allowed on the website. This is to |
| 29 | +# prevent attackers from changing the locations of resources loaded |
| 30 | +# from relative URLs. |
| 31 | +# |
| 32 | +# If you want to use the `<base>` element, then `base-uri 'self'` |
| 33 | +# can be used instead. |
| 34 | +# |
| 35 | +# (3) Form submissions are only allowed from the current website by |
| 36 | +# setting: `form-action 'self'`. |
| 37 | +# |
| 38 | +# (4) Prevents all websites (including your own) from embedding your |
| 39 | +# webpages within e.g. the `<iframe>` or `<object>` element by |
| 40 | +# setting `frame-ancestors 'none'`. |
| 41 | +# |
| 42 | +# The `frame-ancestors` directive helps avoid "Clickjacking" attacks |
| 43 | +# and is similar to the `X-Frame-Options` header. |
| 44 | +# |
| 45 | +# Browsers that support the CSP header will ignore `X-Frame-Options` |
| 46 | +# if `frame-ancestors` is also specified. |
| 47 | +# |
| 48 | +# (5) Forces the browser to treat all the resources that are served over |
| 49 | +# HTTP as if they were loaded securely over HTTPS by setting the |
| 50 | +# `upgrade-insecure-requests` directive. |
| 51 | +# |
| 52 | +# Please note that `upgrade-insecure-requests` does not ensure |
| 53 | +# HTTPS for the top-level navigation. If you want to force the |
| 54 | +# website itself to be loaded over HTTPS you must include the |
| 55 | +# `Strict-Transport-Security` header. |
| 56 | +# |
| 57 | +# To make your CSP implementation easier, you can use an online CSP header |
| 58 | +# generator such as: |
| 59 | +# https://report-uri.com/home/generate/ |
| 60 | +# |
| 61 | +# It is encouraged that you validate your CSP header using a CSP validator |
| 62 | +# such as: |
| 63 | +# https://csp-evaluator.withgoogle.com |
| 64 | +# |
| 65 | +# https://csp.withgoogle.com/docs/ |
18 | 66 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy |
19 | | -# https://www.w3.org/TR/CSP3/ |
20 | | -# https://content-security-policy.com/ |
21 | 67 | # https://www.html5rocks.com/en/tutorials/security/content-security-policy/ |
| 68 | +# https://www.w3.org/TR/CSP/ |
22 | 69 |
|
23 | 70 | <IfModule mod_headers.c> |
24 | | - Header set Content-Security-Policy "script-src 'self'; object-src 'self'" "expr=%{CONTENT_TYPE} =~ m#text/html#i" |
| 71 | + # (1) (2) (3) (4) (5) |
| 72 | + Header set Content-Security-Policy "default-src 'self'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests" "expr=%{CONTENT_TYPE} =~ m#text/html#i" |
25 | 73 | </IfModule> |
0 commit comments