Adds a CSP that is enabled by default
What does this MR do?
This MR enables the Content-Security-Policy by default. Most of the policy is very generic and not strict at all. The idea is mostly for this to be a "better than nothing" iteration. The critical piece however is the addition of strict-dynamic
to the script-src
directive. This builds on a previous MR that added nonce
s to add <script>
tags and should greatly reduce the impact of XSS in GitLab. As XSS is one of the vulnerabilities we see the most, this will lead to increased security and also $ savings on the bug bounty program by greatly reducing the impact of successful exploitation.
strict-dynamic
allows loading JavaScript from <script>
tags with a valid nonce
attribute and then allows those validated scripts to do as they please. When a browser supports strict-dynamic
, it ignores the other attributes present in the script-src
directive.
Browsers that don't support strict-dynamic
(i.e. Safari as far as GitLab-supported browsers are concerned) fall back on the other elements of the script-src
directive which is why 'self' 'unsafe-inline' 'unsafe-eval' https://www.recaptcha.net https://apis.google.com"
is also included in the policy. This comes from the documentation where we recommend those items to be added to the CSP.
Dev concerns
CSPs are often annoying for developers because it breaks a bunch of a stuff in the development environment. I spent some time testing around that to avoid such a situation and that's why in dev
the webpack dev server is dynamically added to the CSP allowlist.
Breaking change concerns
- Users that currently have custom CSP settings will override those new defaults and shouldn't see a difference when upgrading.
- Users that current use the default settings will have the CSP enabled when they update
-
There is a small risk of something breaking on the more customized installs though I tried to prevent most of that.
The good news is that should something break for a specific customer with custom settings, we don't need to ship a patch everything can be fixed with a configuration change. For this reason here I think that targeting %14.0 might be safer. WDYT maintainer? :)
-
Closes #30720
Related documentation MR omnibus-gitlab!5210 (merged)
Also related to this AppSec initiative https://gitlab.com/gitlab-com/gl-security/appsec/appsec-reviews/-/issues/44
Screenshots (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have included a changelog entry. -
I have not included a changelog entry because _____.
-
-
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team