-
-
Notifications
You must be signed in to change notification settings - Fork 3
Generate server headers especially Content-Security-Policy #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Generate server headers especially Content-Security-Policy #27
Conversation
|
Avoids the need to hard code the hashes when using a CSP. Depends on thuliteio/core#27 Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
592db4f to
4b9de12
Compare
|
There are many deployment options, each with its own configuration file. Although Netlify sponsors Thulite’s hosting, I prefer to keep Thulite platform-agnostic and support any hosting provider using its preferred configuration. This approach works well with the current setup — using common practice. I think automatically generating configuration files can be challenging—for example, when generating them for different routes. I do like the idea of automatically generating hashes for resource files though, and I think that’s something Hugo does well.
Note that you wouldn’t want to add a nonce or hash to an external JavaScript file—if the script changes, it could stop working. |
Avoids the need to hard code the hashes when using a CSP. Depends on thuliteio/core#27 Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
Heh. Yeah. I am pondering the rest of your response.. |
Collect information needed to generate custom headers, especially Content-Security-Policy. Information is gathered from Hugo `data` configuration and generated hashes for stylesheets. Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
And remove the hard-coded hash that is no longer required. Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
Collects headers and redirects from content frontmatter aliaes and informaton from `data` entires. With `outputFormat` configuration in `hugo.toml` allows generating platform agnostic json with the header and redirect details. Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
With 'outputFormats' and 'outputs' configuration in `hugo.toml`, adds Netlify `_headers` and/or `_redirects` file generation and/or Apache 2.4 `.htaccess` configuration with headers and/or redirects. Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
4b9de12 to
75c4f4b
Compare
|
I've revamped so that the I can drop the last three commits (sample Apache and Netlify config generation) if you want. Instead, I genericize the header and redirects collection and emit JSON for the headers and or or redirects (assuming Does this work for you, so that 'collection' infrastructure is present but the base design is provider agnostic? |
For the apache config we need to convert the Netlify style redirect patterns to Apache regexes and substitutions. Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
Avoids the need to hard code the hashes when using a CSP. Depends on thuliteio/core#27 Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
|
I have to give this some proper thought, then I get back to you |
Summary
Generates JSON files with headers and redirects information. Optionally generates configuration for Apache 2.4
.htaccessand/or Netlify_headersand_redirects.This enables setting the Content-Security-Policy with hashes for security. This will allow avoiding the uses of hard-coded nonces[1] and avoids the need to hard code the hashes whenever a script or style changes.
Basic example
Header configuration
Define the headers in
data/serverHeaders/static.tomlanddata/serverHeaders/dynamic/*.tomlstatic.tomlmight look like:a dynamic header might look like this one in
data/serverHeaders/dynamic/Content-Security-Policy.tomlFor the CSP above define the values for
##VAR_analytics##and##VAR_styleHashes##by creating:/layouts/_partials/header-custom-values/analytics.htmlsuch as:{{- with site.Params.analyticsUrl }}{{- . -}}{{- end -}}/layouts/_partials/header-custom-values/styleHashes.htmlsuch as:{{- $styleHashes := (union ((partial "head/stylesheet-hashes.html" .).hashes) ((partial "head/libsass-hash.html" "scss/app.scss").hashes) ) -}} {{- return $styleHashes -}}Enable the header and redirect JSON generation in
hugo.toml(Optional) Enable Netlify and/or Apache 2.4
.htaccessconfiguration generationConfigure domain redirects
NOTE You do not include the main domain (the domain you want to be the baseURL: in this case
www.wildtechgarden.ca) inredirectDomains.Aliases are automatically turned into redirects.
Configure additional redirects. For example, in
/data/serverRedirects/path-status.tomlFinally, configure any regex redirects in
/data/serverRedirects/wildcard.toml(using the same style of config as Netlify).Motivation
Enable a proper Content-Security-Policy (and related headers). That is a CSP that with calculated hashes rather than hard-coded nonces and/or 'unsafe-inline' enabled.
Use proper header-based redirects instead of HTTP-REFRESH redirects.
Checks
npm run test(if relevant)[1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP#nonces