r68811 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68810‎ | r68811 | r68812 >
Date:03:05, 1 July 2010
Author:bawolff
Status:ok (Comments)
Tags:
Comment:
Some security fixes to the DynamicPageList (third party) extension

I think there are other issues with this extension, but this addresses
some of the most obvious XSS issues. I do not think the way this extension
plays with $wgRawHtml is a good idea.
Modified paths:
  • /trunk/extensions/DynamicPageList/DPLMain.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DynamicPageList/DPLMain.php
@@ -767,11 +767,11 @@
768768 break;
769769
770770 case 'rowcolformat':
771 - $sRowColFormat = $sArg;
 771+ $sRowColFormat = self::killHtmlTags( $sArg );
772772 break;
773773
774774 case 'userdateformat':
775 - $sUserDateFormat = $sArg;
 775+ $sUserDateFormat = self::killHtmlTags( $sArg );
776776 break;
777777
778778 case 'escapelinks':
@@ -783,13 +783,14 @@
784784 break;
785785
786786 case 'inlinetext':
787 - $sInlTxt = $sArg;
 787+ $sInlTxt = self::killHtmlTags( $sArg );
788788 break;
789789
790790 case 'format':
791791 case 'listseparators':
792792 // parsing of wikitext will happen at the end of the output phase
793793 // we replace '\n' in the input by linefeed because wiki syntax depends on linefeeds
 794+ $sArg = self::killHtmlTags( $sArg );
794795 $sArg = str_replace( '\n', "\n", $sArg );
795796 $sArg = str_replace( "¶", "\n", $sArg ); // the paragraph delimiter is utf8-escaped
796797 $aListSeparators = explode( ',', $sArg, 4 );
@@ -873,25 +874,28 @@
874875 case 'replaceintitle':
875876 // we offer a possibility to replace some part of the title
876877 $aReplaceInTitle = explode( ',', $sArg, 2 );
 878+ if (isset($aReplaceInTitle[1])) {
 879+ $aReplaceInTitle[1] = self::killHtmlTags( $aReplaceInTitle[1] );
 880+ }
877881 break;
878882
879883 case 'resultsheader':
880 - $sResultsHeader = $sArg;
 884+ $sResultsHeader = self::killHtmlTags( $sArg );
881885 break;
882886 case 'resultsfooter':
883 - $sResultsFooter = $sArg;
 887+ $sResultsFooter = self::killHtmlTags( $sArg );
884888 break;
885889 case 'noresultsheader':
886 - $sNoResultsHeader = $sArg;
 890+ $sNoResultsHeader = self::killHtmlTags( $sArg );
887891 break;
888892 case 'noresultsfooter':
889 - $sNoResultsFooter = $sArg;
 893+ $sNoResultsFooter = self::killHtmlTags( $sArg );
890894 break;
891895 case 'oneresultheader':
892 - $sOneResultHeader = $sArg;
 896+ $sOneResultHeader = self::killHtmlTags( $sArg );
893897 break;
894898 case 'oneresultfooter':
895 - $sOneResultFooter = $sArg;
 899+ $sOneResultFooter = self::killHtmlTags( $sArg );
896900 break;
897901
898902 /**
@@ -3539,4 +3543,26 @@
35403544 $wgExtVariables->vardefine( $dummy, 'DPL_totalPages', $totalPages );
35413545 $wgExtVariables->vardefine( $dummy, 'DPL_pages', $pages );
35423546 }
 3547+ /**
 3548+ * turn <html> -> &lt;html&gt;
 3549+ * needed because this extension uses weird hacks with $wgRawHtml
 3550+ * Even with this, I still would not have too much confidence in this extension.
 3551+ *
 3552+ * this will break things in a limited way if someone enabled $wgRawHtml for the site
 3553+ * but I think its worth it.
 3554+ *
 3555+ * note, $text should be from user. it should never contain <html> in it unless someone is
 3556+ * being naughty.
 3557+ */
 3558+ private static function killHtmlTags( $text ) {
 3559+ //escape <html>
 3560+ $text = preg_replace('/<([^>]*[hH][tT][mM][lL][^>]*)>/', '&lt;$1&gt;', $text);
 3561+ //if we still have <html>, someone is doing something weird, like double nesting to get
 3562+ //around the escaping - just escape it all. <html> should never be here unless someone
 3563+ // is being naughty, so it shouldn't cause problems.
 3564+ if (preg_match('/<[^>]*[hH][tT][mM][lL][^>]*>/', $text)) {
 3565+ $text = htmlspecialchars($text);
 3566+ }
 3567+ return $text;
 3568+ }
35433569 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r68812(Bug 22675) Fix DynamicPageList (3rd party) to work with mediawiki post r61913...bawolff03:44, 1 July 2010

Comments

#Comment by Nikerabbit (talk | contribs)   05:43, 1 July 2010

How about using the case-insensitive flag or modifier for the regexp?

#Comment by Bawolff (talk | contribs)   18:07, 1 July 2010

That would also work fine. Considering how short the regex is I don't think it would make much difference in readability. I sometimes find doing the whole [aA] thing is a good reminder to myself that it matches both lowercase and uppercase, where the case insensitivity flag sometimes is easier to miss, but thats just me.

Status & tagging log