I was wondering if this function would be vulnerable to XSS.
var url = "google.com";
if (url.indexOf("http") != 0) {
url = "http://" + url;
}
$("<a/>").attr("href", url);
The 'url' is user input, and the <a/>
would be placed on some webpage.
I couldn't find a way to execute javascript code on this function. But before I implement this, it would be nice somebody can take a look.