Page MenuHomePhabricator

Wikibase doesn't respect Kartographer's addExtraCSPSrc
Closed, ResolvedPublic

Description

In 889716e13798 Kartographer was changed to automatically add the map server to the CSP source list for pages that include a map on them. However this doesn't seem to work for Wikidata, due to Wikibase\Repo\ParserOutput\GlobeCoordinateKartographerDataUpdater::updateParserOutput not copying that data over.

This wouldn't affect anything in production (Because CSP is not in use yet, but also the plan is to whitelist all of *.wikimedia.org just generally). However, this is breaking things on beta wiki.

My suggested fix would be:

diff --git a/repo/includes/ParserOutput/GlobeCoordinateKartographerDataUpdater.php b/repo/includes/ParserOutput/GlobeCoordinateKartographerDataUpdater.php
index a6963cc409..6a79c92ba5 100644
--- a/repo/includes/ParserOutput/GlobeCoordinateKartographerDataUpdater.php
+++ b/repo/includes/ParserOutput/GlobeCoordinateKartographerDataUpdater.php
@@ -81,6 +81,11 @@ class GlobeCoordinateKartographerDataUpdater implements StatementDataUpdater {
                $parserOutput->addModules( $kartographerParserOutput->getModules() );
                $parserOutput->addModuleStyles( $kartographerParserOutput->getModuleStyles() );
 
+               $srcs = $kartographerParserOutput->getExtraCSPDefaultSrcs();
+               foreach( $srcs as $src ) {
+                       $parserOutput->addExtraCSPDefaultSrc( $src );
+               }
+
                $parserOutput->setExtensionData(
                        'kartographer',
                        $kartographerParserOutput->getExtensionData( 'kartographer' )

However, I'm not sure if that would work during preview. I also haven't tested this as of yet.

Alternatively, it may make sense to use ParserOutput::mergeInternalMetaDataFrom, so that this is less coupled to internal implementation details.

Acceptance Criteria: 🏕️🌟(October 2021):

  • all Wikibase pages that may contain a map add the map server to the CSP source list
    • this includes entity pages that don’t contain a map yet, but where users may add a coordinate statement – the editing UI shows a map preview

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

@Bawolff can you elaborate a bit on the issues on the Beta cluster? As far as I can tell, everything is working both on entity pages (WikibaseRepo, Q15905) and Wikitext pages that use coordinates from entities (WikibaseClient, Talk:Q15905).

Maybe this already got resolved in the meantime?

This is currently allowed under the enforcing CSP within both Wikimedia production and the beta cluster. So @Bawolff's code suggestion isn't really relevant at this time as:

(Because CSP is not in use yet, but also the plan is to whitelist all of *.wikimedia.org just generally)

is no longer accurate, as we are setting an enforcing CSP in Wikimedia production and the beta cluster, and we are allowing *.wikimedia.org, likely indefinitely. And while rolled out in haste due to 2026-user-javascript-incident, an enforcing CSP was always a desired goal of Product Safety and Integrity and not something that we envision as a temporary solution at this time.

sbassett moved this task from Backlog to Done on the ContentSecurityPolicy board.
sbassett edited projects, added: SecTeam-Processed; removed: [DEPRECATED] wdwb-tech.

Maybe this already got resolved in the meantime?

Whoops, it seems like this was at least partially addressed in https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Kartographer/+/569526? If I'm understanding that change set correctly? Regardless, this should not longer be an issue with the current enforcing CSPs in Wikimedia production and on the beta cluster and their likely future configurations.

sbassett changed the task status from Declined to Resolved.May 6 2026, 3:34 PM
sbassett assigned this task to Bawolff.
sbassett triaged this task as Low priority.