In another question, I asked if it was possible to do this:
<script type = "text/javascript" src = "/js/myScipt.js?v=3"></script>
and then get the value of v within myScipt.js using jQuery or JavaScript. Apparently, yes it can be done like so:
var getV = document.currentScript.src.split("?v=")[1]; // JS
var getV = $('script').last().attr("src").split("?v=")[1]; // jQuery
My new question - Am I creating any kind of security risk that can be exploited by doing this? If so, is there a way to sanitize the value of the queryString to eliminate the risk?
In case it matters, myScript.js uses jQuery to insert some HTML it constructs (some divs and an image) based on some conditionals into the page.
eval()then clearly you've got a cross-site-script problem. If you write it into HTML markup (eg withinnerHTML,$el.html()ordocument.write()) then you've got an HTML-injection problem also leading to cross-site-scripting. If you construct HTML safely using DOM text and attribute properties then you're fine.