I have a piece of code that allows for
[url]someurl[/url]
BB-Code and replaces it with
<a href="someurl">someurl</a>
It takes two precautions to prevent XSS.
- It replaces
<
,>
and"
using a simplestr_replace
. - Uses a regex to detect
javascript:
anddata:
protocol handlers.
Since browsers decode the attribute value before further interpreting it, you can get around the regex check by encoding the URL using [url]j ... [/url]
.
So I get:
<a href="javascript:alert(1)">javascript:alert(1)</a>
Long story short: I want more than a steenkin attribute tage (who would click a link looking like that?!)
Can I somehow encode my "
, <
, etc. so it won't be replaced by the str_replace
but still be interpreted in the context of HTML?