r81330 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81329‎ | r81330 | r81331 >
Date:22:36, 1 February 2011
Author:tstarling
Status:ok
Tags:
Comment:
(bug 27093, CVE-2011-0047): Fixed CSS injection vulnerability. The StringUtils.php patch is by Roan, the Sanitizer.php patch is by me.
Modified paths:
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)
  • /trunk/phase3/includes/StringUtils.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Sanitizer.php
@@ -747,6 +747,13 @@
748748 // Remove any comments; IE gets token splitting wrong
749749 $value = StringUtils::delimiterReplace( '/*', '*/', ' ', $value );
750750
 751+ // Remove anything after a comment-start token, to guard against
 752+ // incorrect client implementations.
 753+ $commentPos = strpos( $value, '/*' );
 754+ if ( $commentPos !== false ) {
 755+ $value = substr( $value, 0, $commentPos );
 756+ }
 757+
751758 // Decode escape sequences and line continuation
752759 // See the grammar in the CSS 2 spec, appendix D.
753760 static $decodeRegex;
Index: trunk/phase3/includes/StringUtils.php
@@ -81,16 +81,20 @@
8282 }
8383
8484 if ( $tokenType == 'start' ) {
85 - $inputPos = $tokenOffset + $tokenLength;
8685 # Only move the start position if we haven't already found a start
8786 # This means that START START END matches outer pair
8887 if ( !$foundStart ) {
8988 # Found start
 89+ $inputPos = $tokenOffset + $tokenLength;
9090 # Write out the non-matching section
9191 $output .= substr( $subject, $outputPos, $tokenOffset - $outputPos );
9292 $outputPos = $tokenOffset;
9393 $contentPos = $inputPos;
9494 $foundStart = true;
 95+ } else {
 96+ # Move the input position past the *first character* of START,
 97+ # to protect against missing END when it overlaps with START
 98+ $inputPos = $tokenOffset + 1;
9599 }
96100 } elseif ( $tokenType == 'end' ) {
97101 if ( $foundStart ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r81331(bug 27093, CVE-2011-0047): Fixed CSS injection vulnerability. The StringUtil...tstarling22:37, 1 February 2011
r81332(bug 27093, CVE-2011-0047): Fixed CSS injection vulnerability. The StringUtil...tstarling22:37, 1 February 2011
r81333(bug 27093, CVE-2011-0047): Fixed CSS injection vulnerability. The StringUtil...tstarling22:37, 1 February 2011

Status & tagging log