This Jekyll plugin automatically builds an HTML content-security-policy for a Jekyll site. The plugin
will scan .html
files generated by Jekyll and attempt to locate images, styles, scripts, frames etc and build a
content security policy HTML meta tag. The script will also generate SHA256 hashes for inline scripts and styles. If
the script finds elements with style attributes <div style="color: red"></div>
, the script will extract the style
information and build a style element to which will also pass through the content security policy generation.
To speed up development of Jekyll based sites whilst also helping to generate secure HTML files protected from XSS.
.html
files generated by Jekyll.<script>alert("Hello World!");</script>
and generates an SHA256 hash.<style>.hello { color: "red"; }</style>
and generates an SHA256 hash.<style>
elements.https://strongscot.com/images/logo.svg
would be converted to
https://strongscot.com/images/
under strict and https://strongscot.com
under relaxed..html
.Add the plugin your Gemfile within the jekyll_plugins group:
group :jekyll_plugins do
gem 'jekyll-content-security-policy-generator'
... other gem files
end
Then install
bundle install
For some reason, Nokogiri will install with both the ARM (M1) and x86 variants which will confuse bundler. Best way I found to fix this was to open the Gemfile.lock and remove the:
nokogiri (1.11.3-arm64-darwin)
racc (~> 1.4)
Or the x86 if you have an M1 mac.
Alternatively, you can add nokogiri
to your Gemfile, like so:
group :jekyll_plugins do
gem 'nokogiri'
gem 'jekyll-content-security-policy-generator'
... other gem files
end