diff options
author | Stan Hu <stanhu@gmail.com> | 2019-08-05 23:14:32 -0700 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2019-08-07 12:37:31 +1000 |
commit | 5fbbd3dd6e965f76ecf1767373bddd236a78a4be (patch) | |
tree | b3331f59d21a479deb970f4067b47c8352d8731e /app/views/layouts/_head.html.haml | |
parent | fa216b0e86433192ba4e39a05f42217fb4685173 (diff) | |
download | gitlab-ce-5fbbd3dd6e965f76ecf1767373bddd236a78a4be.tar.gz |
Add support for Content-Security-Policy
A nonce-based Content-Security-Policy thwarts XSS attacks by allowing
inline JavaScript to execute if the script nonce matches the header
value. Rails 5.2 supports nonce-based Content-Security-Policy headers,
so provide configuration to enable this and make it work.
To support this, we need to change all `:javascript` HAML filters to the
following form:
```
= javascript_tag nonce: true do
:plain
...
```
We use `%script` throughout our HAML to store JSON and other text, but
since this doesn't execute, browsers don't appear to block this content
from being used and require the nonce value to be present.
Diffstat (limited to 'app/views/layouts/_head.html.haml')
-rw-r--r-- | app/views/layouts/_head.html.haml | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index ac774803f95..271b73326fa 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -40,7 +40,7 @@ = stylesheet_link_tag "highlight/themes/#{user_color_scheme}", media: "all" - = Gon::Base.render_data + = Gon::Base.render_data(nonce: content_security_policy_nonce) - if content_for?(:library_javascripts) = yield :library_javascripts @@ -56,6 +56,7 @@ = yield :project_javascripts = csrf_meta_tags + = csp_meta_tag - unless browser.safari? %meta{ name: 'referrer', content: 'origin-when-cross-origin' } |