PHP, Zend Framework and Other Crazy Stuff
CodeIgniter 2.0.2: Cross-Site Scripting (XSS) Fixes And Recommendations
As many of my readers know, I have a keen dislike for regular expression based HTML sanitisation. Regular expressions simply do not understand HTML’s nested nature and the numerous possible HTML/CSS standards it must abide by. The result is that far too many developers try to program this understanding (and unfortunately their lack of comprehensive understanding) into home grown sanitisers using as little code and tests as possible. It’s a horrendous and reprehensible practice that has created a large field of so-called sanitisers and XSS cleaners which are riddled with obvious vulnerabilities despite all their sincere and utterly false claims to the contrary. The perception of safety they create is almost always a fantasy. As I’ve said before, this serves only one purpose – to lend support to claims that PHP is insecure. And why disagree given PHP’s prominence on the internet and this continuing refusal by developers to just do the right thing and use a secure solution that really does work?
Since I’ve completed my research into a broad set of these, for now, I’ll close with a final example given its widespread usage, confusing documentation and lack of a clear disclosure to date of security vulnerabilities.
On April 7, EllisLab released CodeIgniter 2.0.2 as a security maintenance release prompted by a report I sent to EllisLab shortly before St. Paddy’s Day (around mid-March). That report indicated the expected response and my own disclosure policy. This blog post is being published in accordance with those. The disclosure to date of the vulnerabilities afflicting previous CodeIgniter versions is mentioned only in the CodeIgniter 2.0.2 news release (from April 7) as follows:
An update to both CodeIgniter Reactor and CodeIgniter Core (v 2.0.1) was released today. This is a security maintenance release and is a recommended update for all sites. The security fix patches a small vulnerability in the cross site scripting filter.
EllisLab’s news release for CodeIgniter 2.0.2 makes mention of “a small vulnerability”. This small vulnerability is mentioned no where else (not even the actual changelog for 2.0.2). In reality, I reported seven distinct vulnerabilities across two classes. These vulnerabilities might allow an attacker to inject arbitrary HTML, CSS or Javascript, i.e. Cross-Site Scripting (XSS) into an application’s output. It would be nice if, in the future, EllisLab aim for more accuracy in their news releases and disclosed both the number and nature of the security vulnerabilities fixed in their release changelogs.
Users of CodeIgniter 2.0.x and 1.7.x are strongly urged to upgrade to CodeIgniter 2.0.2 (or later) as soon as possible to avail of these critical security fixes.
In addition, users are urged to follow some basic steps when writing or updating CodeIgniter applications:
- Escape ALL data being injected into views using PHP’s htmlspecialchars() function, remembering to pass the character encoding being used as the third parameter. A helper function may be useful to keep the typing to a minimum.
- Use HTMLPurifier when you need to sanitise HTML data or user input such as HTML comments, HTML emails, or RSS/Atom content (basically any HTML you do not explicitly generate yourself!).
- Ensure that all HTML pages are served with a valid Content-Type HTTP header and/or a meta tag equivalent which also declares the charset for that page. Note that HTML5 offers a separate charset element for this purpose. This helps prevent character encoding based XSS attacks by informing the browser of the correct character encoding to use.
- Ensure that all views/templates distributed by third parties are likewise reviewed to ensure they utilise proper escaping and XSS sanitisation.
CodeIgniter is one of the most prominent “micro frameworks”, web application frameworks that prosper by offering their users unparalleled simplicity. It is unusual as a framework in that it does not make any reference to standard escaping mechanisms for views/templates such as the PHP htmlspecialchars() function anywhere in its source code, examples or documentation. This may create the unfortunate impression that users should instead filter input using an XSS filter function in the CI_Security class and do nothing on output. Users taking this approach may be particularly at risk from these security vulnerabilities.
My recommendation to the CodeIgniter developers, as documented in my original report, is to deprecate and remove the CI_Security class’ XSS filter. Responsible vendors should never persist in distributing and advocating the use of insecure software. I also urge them to revise their documentation to ensure that best security practice is noted in the area of writing views/templates and offer a shortcut function to an escaping mechanism for HTML output to standardise and ease its use by members.
Related posts:
- Regex HTML Sanitisation: Off With Its Head!
- Open Letter to Gareth Heyes: Regex HTML Sanitisation Doesn’t Work
- HTML Purifier 2.0.0 – new version of the PHP HTML filter library
- Zend Framework Proposal: Zend\Html\Filter (HTML Sanitisation And Manipulation)
- HTML Sanitisation: The Devil’s In The Details (And The Vulnerabilities)
| Print article | This entry was posted by padraic on May 10, 2011 at 11:43 am, and is filed under PHP General, PHP Security, Zend Framework. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
-
David Arnold
-
http://www.facebook.com/profile.php?id=512423576 Paul Whitehead
-
http://www.register-domainname.in/ Domain Registration India
-
http://jthmcomics.blogspot.com/ JTHMcomics
-
http://twitter.com/damienmartyn201 damien martyn
-
http://coolnerdblog.blogspot.com/ Nerd Blog
-
http://gamemariobros.blogspot.com/ Mariobros
-
Anonymous
-
http://twitter.com/LamXuan Dinh Xuan
-
http://iphone5world.net rachel veron
-
Anonymous
-
http://gesundabnehmenrezepte.org Alex Neumann
-
http://profiles.google.com/r4ideals R4iDeals Deals
-
steve martin
-
consagreenwood
-
http://www.facebook.com/people/Khurram-Threeightyone/100001484428675 Khurram Threeightyone
-
http://www.facebook.com/people/Khurram-Threeightyone/100001484428675 Khurram Threeightyone
-
http://%/zznxhvr9 LEWIS
-
http://%/zzxxdth9 TERRENCE
-
http://%/zzrxpeo9 BRANDON
-
http://%/zzarncy2 RONNIE
-
http://%/zztlqnr9 PERRY
-
http://%/zzuptsh3 ENRIQUE
-
http://%/zzjnuzm4 RICARDO
-
http://%/zzbqtqk6 RUSSELL
-
http://%/zzjwfit9 SALVADOR
-
http://%/zzblduf9 ARTHUR
-
http://%/zzhmxxx9 GABRIEL
-
http://%/zzdwmni6 MIKE
-
http://%/zziljil5 GUY
-
http://%/zzqrzco4 FELIX
-
http://%/zzbried1 ALFRED
-
http://%/zzljgqs2 VICTOR
-
http://%/zzxywjo8 TERRENCE
-
http://%/zzhwnyr1 RICK
-
http://%/zzrvbio1 MATHEW
-
http://%/zzfufdw3 SAM
-
http://%/zzsvjkz2 RUBEN
-
http://%/zzfzhar3 BILLY
-
http://%/zzdclpp6 WILLIAM
-
http://%/zzapcwm2 CARL
-
http://%/zzqjhtz6 ANGELO
-
http://%/zzohptm5 ADAM
-
http://%/zznvxoz1 BOB
-
http://%/zznmuss6 LLOYD
-
http://%/zzmjfwe5 ROY
-
http://%/zzdwvco7 LUIS
-
http://%/zzmiycm3 DARYL
-
http://%/zzqwxvk7 CLIFTON
-
http://%/zzkdirt7 BERNARD
-
http://%/zzfnlia2 RAY
-
http://%/zzrtboq7 LAWRENCE
-
http://%/zzfucku4 MARION
-
http://%/zzhdutd6 RONALD
-
http://%/zzftykc2 JERRY
-
http://%/zzvxldw9 BRETT
-
http://%/zzbqpoy6 JOEL
-
http://%/zzugbox6 MARION
-
http://%/zzzojpb5 BRYAN
-
http://%/zzkfvkf8 GLENN
-
http://%/zzezias2 JASON
-
http://%/zzfhpbr8 LEWIS
-
http://%/zzjpmgj4 BRUCE
-
http://%/zzzszqr6 DALE
-
http://%/zzfcxvb3 VINCENT
-
http://%/zzptgdk4 NORMAN
-
http://%/zzzxspe1 DWIGHT
-
http://%/zzuiacl6 RICARDO
-
http://%/zzumtag5 NICHOLAS
-
http://%/zzkqmgi4 AARON
-
http://%/zzbroca1 VINCENT
-
http://%/zzxwoib2 NICK
-
http://%/zzqvpvm7 RENE
-
http://%/zzeeqjc8 KIRK
-
http://%/zzbslri4 ANGELO
-
http://%/zzarzoe8 KEN
-
http://%/zzrqwlf9 BARRY
-
http://%/zzyjuxl8 STEPHEN
-
http://%/zzcjjos3 AUSTIN
-
http://%/zznjsvh1 DOUGLAS
-
http://%/zzumety6 RICHARD
-
http://%/zzyigrb1 STEPHEN
-
http://%/zzwmanv2 JULIUS
-
http://%/zzmtbvq7 ALAN
-
http://%/zzictkq7 TYLER
-
http://%/zzsakhk3 gerard
-
http://%/zzthsfx4 JEFFERY
-
http://%/zzovmhi9 JERRY
-
http://%/zzppofs9 JAMES
-
http://%/zzrtmev4 MARION
-
http://%/zzqtgnp9 EDWIN
-
http://%/zzjptkp3 EDWIN
-
http://%/zzbxdub2 PETER
-
http://%/zzxcsoc5 TIMOTHY
-
http://%/zzxhucy7 RAY
-
http://%/zzfywdc4 RONNIE
-
http://%/zzsnush3 GREG
-
http://%/zzmrqei2 ZACHARY
-
http://%/zzgwtvr6 TRAVIS
-
http://%/zzwhsre6 ALEXANDER
-
http://%/zzyzaeh5 CHRIS
-
http://%/zzqlvsj3 HERMAN
-
http://%/zzjuici8 BRYAN
-
http://%/zzbuvlt4 LEO
-
http://%/zzdlwfc1 MARK
-
http://%/zzjfeub9 HENRY
-
http://%/zzrweep5 HUBERT
-
http://%/zzdgbto2 JEFFERY
-
http://%/zzxcmni5 IVAN
-
http://%/zzymmxo2 MILTON
-
http://%/zzwhyli7 RANDY
-
http://%/zzrhnzh2 ANDRE
-
http://%/zzfmknz6 JOSHUA
-
http://%/zzveuxp6 JAY
-
http://%/zzyfjxa9 ADAM
-
http://%/zzubjsl8 WADE
-
http://%/zzejmqb5 JULIO
-
http://%/zztatbh7 JEFF
-
http://%/zzaisut1 PERRY
-
http://%/zzxloym2 BEN

