From e2a6fe571166160b9caed45f35910a7b9b50d2c0 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Tue, 7 Jun 2016 22:35:15 -0400 Subject: [PATCH] SECURITY: XSS in unclosed internal links rawurldecode was being run on unclosed internal links which could allow an attacker to insert arbitrary html into the page. See also related: r13302 Bug: T137264 Change-Id: I4e112a9e918df9fe78b62c311939239b483a21f5 --- includes/parser/Parser.php | 2 +- tests/parser/parserTests.txt | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 4f579a93be..38eb621936 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -2158,7 +2158,7 @@ class Parser { $might_be_img = true; $text = $m[2]; if ( strpos( $m[1], '%' ) !== false ) { - $m[1] = rawurldecode( $m[1] ); + $m[1] = str_replace( [ '<', '>' ], [ '<', '>' ], rawurldecode( $m[1] ) ); } $trail = ""; } else { # Invalid form; output directly diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index d6d2b29976..c7bbc62356 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -27140,3 +27140,12 @@ Thumbnail output !! end + +!! test +unclosed internal link XSS (T137264) +!! wikitext +[[#%3Cscript%3Ealert(1)%3C/script%3E| +!! html +

[[#<script>alert(1)</script>| +

+!! end -- 2.20.1