Setup CSP Headers for a website
Adds CSP headers to your request, based on configuration in a yml file.
SilverStripe Framework 4.x PHP 5.6+
composer require firesphere/cspheaders
When using this module and have CSS hashes or nonces enabled, any inline styles declared on HTML Elements themselves will not work anymore.
allow-inline) in your yml config.
Default for css is therefore
true for security reasongs.
Firesphere\CSPHeaders\View\CSPBackend: csp_config: report-only: false report-uri: "https://mydomain.report-uri.com" base-uri: allow:  self: true default-src:  frame-src: allow:  self: false connect-src: allow:  self: true font-src: allow:  self: true form-action: self: true frame-ancestors:  img-src: allow:  blob: true self: true data: true media-src:  object-src:  plugin-types:  script-src: allow:  self: true unsafe-inline: false unsafe-eval: false style-src: self: true unsafe-inline: true upgrade-insecure-requests: true jsSRI: true cssSRI: false useNonce: false --- Only: environment: 'dev' --- Firesphere\CSPHeaders\View\CSPBackend: csp_config: report-only: true
Setting the legacy headers flag to true, will add the IE legacy headers like
X-XSS-PROTECTION. Default value is false
When you enable the Reporting API you will receive deprecation, intervention and crash reports from the browser. To enable this you need to set a HTTP response header with the following name and value.
Configure the allowed domains. If domains change, they need to be added programmatically.
If you don't want to use the script tag, use the nonce. In the template, you can use
$Nonce to get the current request nonce, e.g. if you are using <script> tags in your template
It's useful to only use the wizard in dev mode, to discover the URI's and sha's you need to add. This prevents needless reports and helps you set up the wizard.
You do need to set the report-to uri to your wizard uri, otherwise the system will encounter a failure.
If you want to submit forms to a different domain, you can add the allowed domains under the forms section
If you use the default methods provided by the
Requirements class, the needed SHA's and SRI's are automatically calculated for you.
Any header set in the
nginx.conf files will override the headers
set by this module.
This module is published under BSD 3-clause license, although these are not in the actual classes, the license does apply:
Copyright (c) 2012-NOW(), Simon "Sphere" Erkelens
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pictured below is a cow, just for you.
/( ,,,,, )\ _\,;;;;;;;,/_ .-"; ;;;;;;;;; ;"-. '.__/`_ / \ _`\__.' | (')| |(') | | .--' '--. | |/ o o \| | | / \ _..=.._ / \ /:. '._____.' \ ;::' / \ .; | _|_ _|_ ::| .-| '==o==' '|-. / | . / \ | \ | | ::| | | .| | ( ') (. )::| |: | |; U U ;|:: | `| |' | | \ U U / |' | | ##V| |_/`"""`\_| |V## ##V## ##V##