Initial support for Content Security Policy, disabled by default
authorBrian Wolff <bawolff+wn@gmail.com>
Mon, 29 Feb 2016 04:13:10 +0000 (23:13 -0500)
committerKunal Mehta <legoktm@member.fsf.org>
Mon, 14 May 2018 04:01:11 +0000 (21:01 -0700)
commit70941efd35562dcb7003229b56c91a98a67de7a9
treef4d835e587e90f1a478a2de7cdfddb3fdae96695
parentd888d84e60acf7d5284762d74a42a12615e045c8
Initial support for Content Security Policy, disabled by default

The primary goal here is a defense in depth measure to
stop an attacker who found a bug in the parser allowing
them to insert malicious attributes.

This wouldn't stop someone who could insert a full
script tag (since at current it can't distinguish between
malicious and legit user js). It also would not prevent
DOM-based or reflected XSS for anons, as the nonce value
is guessable for anons when receiving a response cached
by varnish. However, the limited protection of just stopping
stored XSS where the attacker only has control of attributes,
is still a big win in my opinion. (But it wouldn't prevent
someone who has that type of xss from abusing things like
data-ooui attribute).

This will likely break many gadgets. Its expected that any
sort of rollout on Wikimedia will be done very slowly, with
lots of testing and the report-only option to begin with.

This is behind feature flags that are off by default, so
merging this patch should not cause any change in default
behaviour.

This may break some extensions (The most obvious one
is charinsert (See fe648d41005), but will probably need
some testing in report-only mode to see if anything else breaks)

This uses the unsafe-eval option of CSP, in order to
support RL's local storage thingy. For better security,
we may want to remove some of the sillier uses of eval
(e.g. jquery.ui.datepicker.js).

For more info, see spec: https://www.w3.org/TR/CSP2/
Additionally see:
https://www.mediawiki.org/wiki/Requests_for_comment/Content-Security-Policy

Bug: T135963
Change-Id: I80f6f469ba4c0b608385483457df96ccb7429ae5
19 files changed:
RELEASE-NOTES-1.32
autoload.php
docs/hooks.txt
includes/ContentSecurityPolicy.php [new file with mode: 0644]
includes/DefaultSettings.php
includes/EditPage.php
includes/GlobalFunctions.php
includes/Html.php
includes/OutputPage.php
includes/api/ApiCSPReport.php
includes/debug/MWDebug.php
includes/resourceloader/ResourceLoader.php
includes/resourceloader/ResourceLoaderClientHtml.php
includes/skins/Skin.php
includes/skins/SkinTemplate.php
includes/specialpage/ChangesListSpecialPage.php
tests/phpunit/includes/ContentSecurityPolicyTest.php [new file with mode: 0644]
tests/phpunit/includes/OutputPageTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php