@
mario:
my
klingon: joke was just pointing out that inside an event handler you don't need to specify any scheme (neither javascript: nor vbscript:), because the attribute isn't expected to be an URL but just raw script code.
In JavaScript, any non-reserved-keyword identifier sequence followed by colons (
\w+:) is parsed as a label.
For instance,
javascript: while(true) {
while(true) {
alert(1);
break javascript;
}
alert(2); // this statement is never reached
}
alert(3);
outputs 1 and 3.
That's why
onclick="javascript:someCode()" doesn't produce any error, even if it's plain useless and should be written just
onclick="someCode()".
On the other hand, you still need to filter \w+script: as a potential XSS vector, because it's likely to be used as a proper URL, for instance in an iframe, a meta refresh or a Flash GetURL().
An example of attack which is conveniently detectable only if you're triggered by "javascript:" is [
sla.ckers.org]
@
ronald:
I'm not sure, what security advantage would I gain if src attribute was limited to a certain file extension (aside breaking many applications which dynamically generate included scripts and which don't/can't use URL rewriting, e.g. those relying on Struts validators)?
Once someone manages to (over)write a script tag, I'm pwned anyway, ain't I?
Also notice that the file extension doesn't mean that much over HTTP, where the MIME type is inferred looking at the "Content-Type" header.
So your examples are unlikely to work as they are, unless you've configured your web server to attach "Content-Type: text/javascript" to every random file or you're testing locally.
However, if you were impressed by those snippets, I bet you'll go crazy for the following:
<script type="text/javascript" src="data:text/javascript,alert(document.location)"></script>
It works with Opera and with Firefox (
without NoScript - otherwise, it will be blocked even on trusted sites). IE7 doesn't support data: URLs.
--
*
hackademix.net*
There's a browser safer than Firefox... Firefox, with NoScript