HTML::Defang

Kirsle
kirsle
Posted by Kirsle on Tuesday, Jun 19 2012 @ 4:24 PM
I decided to take a serious look at the HTML::Defang module. It's supposed to take some arbitrary HTML input and sanitize it, removing anything potentially malicious in the process (attempts to execute JavaScript code, embedding of iframes, applets, etc.)

It does a pretty decent job, but I found one thing it doesn't handle very well by default. In CSS code, it will attempt to comment out an attribute if you attempt to use JavaScript with it. Some example input:

<span style="background-image: url('javascript:alert(1)')">
HTML::Defang will turn that into this:
<span style="/*background-image: url('javascript:alert(1)')*/">
But, if you begin and end your CSS attribute with an end-comment and start-comment instead, HTML::Defang leaves the code looking like this:
<span style="/**/background-image: url('javascript:alert(1)')/**/">
Now, granted, this sort of exploit only really hits Internet Explorer users (at least for older versions of IE), but it is a pretty big issue still. This is basically how Samy pwned MySpace, after all.

Anyway, I've written a test CGI script for HTML::Defang: you can try to break it here. I added a custom CSS handler that will neutralize JavaScript attempts from the CSS code to handle that problem I found in HTML::Defang. You can see the source code by clicking the link at the bottom of that page.

If anybody finds a way to get JavaScript to execute on that page, let me know. :) I've tried all the usual tricks and haven't found a loophole yet.

Categories: HTML , Curiosity , Perl

[ Kirsle's Blog ]

Comments

There are 0 comments on this page.

Leave a Comment

Login with Facebook
Your name:
Your Email: (optional)
Message:
You can use emoticons in your comment (opens in new window).

If you can see this, don't touch the following fields.

Kirsle
» Homepage (RSS)
» About Me
» Photo Albums
» Guestbook
» Contact Me
Channels
» Linux (47)
» General (44)
» Perl (34)
» Rant (21)
» Software (15)
» RiveScript (9)
» Gnome 3 (8)
» HowTo (8)
» Windows (8)
» HTML (7)
» Android (6)
» Design (6)
» Siikir (6)
» Tk (6)
» Curiosity (5)
» Blackhat (4)
» Gay (4)
» Java (4)
» Minecraft (4)
» Reviews (4)
» VirtualBox (4)
» DOS (3)
» KAGE (3)
» Licensing (3)
» Photos (3)
» Xfce (3)
» ttf2eot (3)
Creativity
» 3D Renderings
» Flash Animation
» JavaScript
» Fonts
» Metacity
» Tutorials
Software
» RiveScript
» Error Generator
» Tk Calculator
» Terminal Apps
» CyanChat Client
Web Tools
» TTF to EOT
» Text Fader
» Favicons
» Distance Calc
» Azulian Encoder
» XBM Masks
Subdomains
» Shell Scripts
» Linux RPMs
» Kirsle::Nano
» Minecraft Server
Miscellany
¤ Pokemon Fuchsia City
¤ DOS and Windows
¤ Raspberry Pi
Links
¤ Google+
¤ Facebook
¤ New MySpace
¤ Twitter
¤ Github
¤ CPAN
Fan Club
» Log In
» Sign Up

Stats
-= Today =-
> Total hits: 387
> Unique: 197
-= All Time =-
> Total hits: 1420069
> Unique: 155378
» Traffic History
» Referrers