My static code analyser flags this piece of Javascript on my client's web site as a potential DOM based XSS:
var x = $('#' + window.location.hash.substr(1))
x.addClass('highlighted').find('div').show();
The code is directly in $(function(){ ... }
so should be run every time the page loads? (confession: I know too little about jQuery...)
Googling, I found that jQuery made exploiting code like this more difficult after this article from 2011:
http://blog.mindedsecurity.com/2011/07/jquery-is-sink.html
But attacks are still possible, one that stills works is at http://www.mjcblog.net/2011/06/jquery-selector-injection/ .
Is my client still vulnerable? I think so, but I can't come up with an exploit because I don't know jQuery well enough to really get what's going on.
Edit - since the value passed to $()
always starts with #
I suspect that this blocks any exploit of this, and trying it on the Firefox and Chrome console seems to confirm this - but I'm still not sure there isn't another way :)