Validate background colour to avoid arbitrary style attribute injection. Leads to XSS in versions of IE that support dynamic properties (IE<8, and IE 8 in quirks mode).

This commit is contained in:
Tim Starling 2010-03-30 03:59:15 +00:00
parent ef03379a76
commit 6bdcff7eaf

View file

@ -510,7 +510,28 @@ class InputBox {
// Validate the width; make sure it's a valid, positive integer
$this->mWidth = intval( $this->mWidth <= 0 ? 50 : $this->mWidth );
// Validate background color
if ( !$this->isValidColor( $this->mBGColor ) ) {
$this->mBGColor = 'transparent';
}
wfProfileOut( __METHOD__ );
}
/**
* Do a security check on the bgcolor parameter
*/
public function isValidColor( $color ) {
$regex = <<<REGEX
/^ (
[a-zA-Z]* | # color names
\# [0-9a-f]{3} | # short hexadecimal
\# [0-9a-f]{6} | # long hexadecimal
rgb \s* \( \s* (
\d+ \s* , \s* \d+ \s* , \s* \d+ | # rgb integer
[0-9.]+% \s* , \s* [0-9.]+% \s* , \s* [0-9.]+% # rgb percent
) \s* \)
) $ /xi
REGEX;
return (bool) preg_match( $regex, $color );
}
}