Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F34883412
T297570.patch
Lucas_Werkmeister_WMDE (Lucas Werkmeister (WMDE))
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Authored By
Lucas_Werkmeister_WMDE
Dec 14 2021, 10:38 AM
2021-12-14 10:38:24 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
T297570.patch
View Options
From cb0291f01f41de7fa1d919caf2a6f37829672e12 Mon Sep 17 00:00:00 2001
From: Lucas Werkmeister <lucas.werkmeister@wikimedia.de>
Date: Tue, 14 Dec 2021 11:36:56 +0100
Subject: [PATCH] SECURITY: Ignore formatter URLs with bad protocol
Only use the formatter URL if it has one of three, known-good protocols:
HTTPS, HTTP, or telephone number.
Bug: T297570
Change-Id: I37ece1dfdc80d38055067c9c4fa73ba591acd8bd
---
lib/includes/PropertyInfoSnakUrlExpander.php | 17 ++++++++++++++++-
.../phpunit/PropertyInfoSnakUrlExpanderTest.php | 10 ++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/lib/includes/PropertyInfoSnakUrlExpander.php b/lib/includes/PropertyInfoSnakUrlExpander.php
index ae09276573..0dd7f3db30 100644
--- a/lib/includes/PropertyInfoSnakUrlExpander.php
+++ b/lib/includes/PropertyInfoSnakUrlExpander.php
@@ -16,6 +16,15 @@
*/
class PropertyInfoSnakUrlExpander implements SnakUrlExpander {
+ /**
+ * URL protocols (schemes) that are allowed in the pattern.
+ */
+ private const ALLOWED_PROTOCOLS = [
+ 'https' => null,
+ 'http' => null,
+ 'tel' => null,
+ ];
+
/**
* @var PropertyInfoProvider
*/
@@ -50,8 +59,14 @@ public function expandUrl( PropertyValueSnak $snak ) {
'/',
rawurlencode( $value->getValue() )
);
+ $url = str_replace( '$1', $id, $pattern );
+
+ $parsedUrl = wfParseUrl( $url );
+ if ( !$parsedUrl || !array_key_exists( $parsedUrl['scheme'], self::ALLOWED_PROTOCOLS ) ) {
+ return null;
+ }
- return str_replace( '$1', $id, $pattern );
+ return $url;
}
}
diff --git a/lib/tests/phpunit/PropertyInfoSnakUrlExpanderTest.php b/lib/tests/phpunit/PropertyInfoSnakUrlExpanderTest.php
index 757580d0c5..6000097dbb 100644
--- a/lib/tests/phpunit/PropertyInfoSnakUrlExpanderTest.php
+++ b/lib/tests/phpunit/PropertyInfoSnakUrlExpanderTest.php
@@ -29,6 +29,7 @@ public function provideExpandUrl() {
$p3 = new NumericPropertyId( 'P3' );
$p4 = new NumericPropertyId( 'P4' );
$p5 = new NumericPropertyId( 'P5' );
+ $p6 = new NumericPropertyId( 'P6' );
$p523 = new NumericPropertyId( 'P523' );
$infoLookup = new MockPropertyInfoLookup( [
@@ -47,6 +48,10 @@ public function provideExpandUrl() {
PropertyInfoLookup::KEY_DATA_TYPE => 'string',
PropertyInfoLookup::KEY_FORMATTER_URL => 'http://acme.info/foo#$1',
],
+ $p6->getSerialization() => [
+ PropertyInfoLookup::KEY_DATA_TYPE => 'string',
+ PropertyInfoLookup::KEY_FORMATTER_URL => 'javascript:alert()//$1',
+ ],
] );
$infoProvider = new FieldPropertyInfoProvider( $infoLookup, PropertyInfoLookup::KEY_FORMATTER_URL );
@@ -89,6 +94,11 @@ public function provideExpandUrl() {
new PropertyValueSnak( $p5, $value ),
'http://acme.info/foo#X%26Y'
],
+ 'pattern with illegal protocol' => [
+ $infoProvider,
+ new PropertyValueSnak( $p6, $value ),
+ null,
+ ],
];
}
--
2.30.2
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9303679
Default Alt Text
T297570.patch (2 KB)
Attached To
Mode
T297570: XSS in Wikibase using formatter URL (CVE-2021-45472)
Attached
Detach File
Event Timeline
Log In to Comment