The OWASP XSS Prevention Worksheet recommends "URL escape before inserting untrusted data into HTML URL parameter values".
I don't understand how someone could break out of a URL context or inject a new subcontext to perform a XSS attack in a URL. As the browser interprets the URL, can certain characters be used to terminate the processing of the URL and force the browser to start processing a new injected URL?
http://somesite.com/about<terminating character>javascript:;alert("hello")
Can someone please provide examples of how someone would perform an XSS injection in a URL?
<a href="[user supplied]">
which is obviously bad as it allows the javascript protocol to be inserted (as you mentioned in your question (javascript:evil()
)) and has to be handled differently than other attributes. I don't think there is a way to switch to it once part of the URL is given. The only way to actually context switch that comes to mind is using an@
, but that has nothing to do with xss. – tim Feb 23 '15 at 15:53#
and&
need to be escaped, as the OWASP guide saysExcept for alphanumeric characters, escape all characters with ASCII values
these will already be converted to%xx
format and will not be dangerous as the attribute context cannot be escaped. – SilverlightFox Feb 24 '15 at 09:11