Page MenuHomePhabricator

Fix or remove $wmgUseCSPReportOnlyHasSession (CSP only for logged-in users)
Closed, ResolvedPublic

Description

Summary: $wmgUseCSPReportOnlyHasSession currently seems to have no effect. If we want it, we should fix it so it does something again; if we don’t want it, we should remove it from the config.

As far as I can tell, Make CSP enforce on beta removed the effect that $wmgUseCSPReportOnlyHasSession had. Prior to that change, the CSP “extension function” returned early if there was no session, and otherwise made some unconditional $wgCSPReportOnlyHeader assignments. After that change, those assignments were wrapped in a check for either $wmgUseCSP (when assigning $wgCSPHeader) or $wmgUseCSPReportOnly (when assigning $wgCSPReportOnlyHeader); when neither of these conditions is true, the function does nothing. But the early return if there is no session is also wrapped in if ( !$wmgUseCSPReportOnly && !$wmgUseCSP ) now, so it can only be reached if there are no CSP changes anyway. In other words, it’s dead code – unless I misunderstood the logic somewhere.

Beta currently sends a CSP header for anonymous request even though $wmgUseCSPReportOnlyHasSession is set to true for all wikis everywhere:

$ curl -sI https://en.wikipedia.beta.wmflabs.org/wiki/Main_Page | grep -i '^content-security-policy:'
content-security-policy: script-src 'unsafe-eval' blob: 'self' meta.wikimedia.beta.wmflabs.org *.wikimedia.beta.wmflabs.org *.wikipedia.beta.wmflabs.org *.wikinews.beta.wmflabs.org *.wiktionary.beta.wmflabs.org *.wikibooks.beta.wmflabs.org *.wikiversity.beta.wmflabs.org *.wikisource.beta.wmflabs.org *.wikiquote.beta.wmflabs.org wikidata.beta.wmflabs.org m.wikidata.beta.wmflabs.org *.wikivoyage.beta.wmflabs.org *.mediawiki.beta.wmflabs.org wikifunctions.beta.wmflabs.org m.wikifunctions.beta.wmflabs.org *.wikimedia.org *.wikipedia.org *.wikinews.org *.wiktionary.org *.wikibooks.org *.wikiversity.org *.wikisource.org wikisource.org *.wikiquote.org *.wikidata.org *.wikifunctions.org *.wikivoyage.org *.mediawiki.org ws://visualeditor-realtime.wmflabs.org cxserver-beta.wmcloud.org recommend.wmflabs.org 'unsafe-inline' login.wikimedia.beta.wmflabs.org; default-src 'self' data: blob: https://upload.wikimedia.beta.wmflabs.org upload.wikimedia.beta.wmflabs.org https://commons.wikimedia.beta.wmflabs.org https://upload.wikimedia.org https://commons.wikimedia.org meta.wikimedia.beta.wmflabs.org *.wikimedia.beta.wmflabs.org *.wikipedia.beta.wmflabs.org *.wikinews.beta.wmflabs.org *.wiktionary.beta.wmflabs.org *.wikibooks.beta.wmflabs.org *.wikiversity.beta.wmflabs.org *.wikisource.beta.wmflabs.org *.wikiquote.beta.wmflabs.org wikidata.beta.wmflabs.org m.wikidata.beta.wmflabs.org *.wikivoyage.beta.wmflabs.org *.mediawiki.beta.wmflabs.org wikifunctions.beta.wmflabs.org m.wikifunctions.beta.wmflabs.org *.wikimedia.org *.wikipedia.org *.wikinews.org *.wiktionary.org *.wikibooks.org *.wikiversity.org *.wikisource.org wikisource.org *.wikiquote.org *.wikidata.org *.wikifunctions.org *.wikivoyage.org *.mediawiki.org ws://visualeditor-realtime.wmflabs.org cxserver-beta.wmcloud.org recommend.wmflabs.org wikimedia.org en.wikibooks.beta.wmflabs.org en.wikinews.beta.wmflabs.org en.wikiquote.beta.wmflabs.org en.wikisource.beta.wmflabs.org en.wikiversity.beta.wmflabs.org en.wikivoyage.beta.wmflabs.org en.wiktionary.beta.wmflabs.org api.wikimedia.beta.wmflabs.org commons.wikimedia.beta.wmflabs.org login.wikimedia.beta.wmflabs.org; style-src 'self' data: blob: https://upload.wikimedia.beta.wmflabs.org upload.wikimedia.beta.wmflabs.org https://commons.wikimedia.beta.wmflabs.org https://upload.wikimedia.org https://commons.wikimedia.org meta.wikimedia.beta.wmflabs.org *.wikimedia.beta.wmflabs.org *.wikipedia.beta.wmflabs.org *.wikinews.beta.wmflabs.org *.wiktionary.beta.wmflabs.org *.wikibooks.beta.wmflabs.org *.wikiversity.beta.wmflabs.org *.wikisource.beta.wmflabs.org *.wikiquote.beta.wmflabs.org wikidata.beta.wmflabs.org m.wikidata.beta.wmflabs.org *.wikivoyage.beta.wmflabs.org *.mediawiki.beta.wmflabs.org wikifunctions.beta.wmflabs.org m.wikifunctions.beta.wmflabs.org *.wikimedia.org *.wikipedia.org *.wikinews.org *.wiktionary.org *.wikibooks.org *.wikiversity.org *.wikisource.org wikisource.org *.wikiquote.org *.wikidata.org *.wikifunctions.org *.wikivoyage.org *.mediawiki.org ws://visualeditor-realtime.wmflabs.org cxserver-beta.wmcloud.org recommend.wmflabs.org wikimedia.org 'unsafe-inline'; object-src 'none'; report-uri /w/api.php?action=cspreport&format=json

Event Timeline

Krinkle subscribed.

I agree with Lucas' analysis that this feature is not working and (probably) safe to remove.

Tagging the group board for awareness/triage. The CSP component in MediaWiki core was developed in 2016 under contract by Security Team but currently has no documented owner, and has been slowly bit-rotting and lacking maintenance for several years.

Slowly removing stuff bit by bit is not exactly strategic, so a more explicit decision about this would help so that it can either be removed all at once, or if kept, that someone can think about what they do and do not want to support and do so intentionally instead of based on happenstance by random error.

Just noting that $wmgUseCSPReportOnlyHasSession was removed as part of https://gerrit.wikimedia.org/r/1283020 and https://gerrit.wikimedia.org/r/1283049. This didn't really "fix" this issue, but the complications arising from it are not currently an issue within Wikimedia production.

Well, it's removed, so I think this can be called fixed. It can be reopened if anyone has any further plans.