#49785 [NEW]: htmlspecialchars() should check byte sequence more strictly
| From: | hello at iwamot dot com | Date: | Tue, 06 Oct 2009 11:40:06 +0000 |
| Subject: | #49785 [NEW]: htmlspecialchars() should check byte sequence more strictly | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-143310@lists.php.net to get a copy of this message | ||
From: hello at iwamot dot com
Operating system: all
PHP version: 5.3.0
PHP Bug Type: Strings related
Bug description: htmlspecialchars() should check byte sequence more strictly
Description:
------------
Suppose htmlspecialchars() should check byte sequence more strictly for
security reasons. An XSS exploit code has been unveiled.
http://d.hatena.ne.jp/t_komura/20091004/1254665511
[ja]
I wrote a primitive patch.
http://iwamot.com/misc/html.c.patch.20091006
I don't know whether it is useful though :)
Reproduce code:
---------------
// overlong UTF-8 sequence
echo htmlspecialchars("A\xC0\xAF&", ENT_QUOTES, 'UTF-8');
// invalid Shift_JIS sequence
echo htmlspecialchars("B\x80&", ENT_QUOTES, 'Shift_JIS');
echo htmlspecialchars("C\x81\x7f&", ENT_QUOTES, 'Shift_JIS');
// invalid EUC-JP sequence
echo htmlspecialchars("D\x80&", ENT_QUOTES, 'EUC-JP');
echo htmlspecialchars("E\xA1\xFF&", ENT_QUOTES, 'EUC-JP');
echo htmlspecialchars("F\x8E\xFF&", ENT_QUOTES, 'EUC-JP');
echo htmlspecialchars("G\x8F\xA1\xFF&", ENT_QUOTES, 'EUC-JP');
Expected result:
----------------
output nothing
Actual result:
--------------
A_&B_&C&D_&E__&F__&G___&
("_" means an invalid byte)
--
Edit bug report at http://bugs.php.net/?id=49785&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49785&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49785&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49785&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=49785&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49785&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=49785&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=49785&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=49785&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=49785&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=49785&r=support
Expected behavior: http://bugs.php.net/fix.php?id=49785&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=49785&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=49785&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=49785&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49785&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49785&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=49785&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=49785&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=49785&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=49785&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=49785&r=mysqlcfg