This is basic, ground-level XSS. As basic as it gets. It's not a 'security flaw' in javascript so much as it is the expected behavior of embedding javascript in an HTML page. And if you are trusting user input without filtering, you are doing it wrong.
I think you're wrong here. This has nothing to do with XSS. If you set the string via url parameters or an input it will work fine, because the string will contain the correct characters.
The problem is that the author isn't escaping his < and > characters as you should be when you don't want them to be interpreted as a tag.
It is XSS. If the 'string' that has the malicious script tag in it isn't escaped (the fault of the person who created the site) then it could be used to load javascript from another website - this is one way to achieve Cross-Site-Scripting. Take a look at r/xss for numerous other examples.
That's exactly it though, the 'string' is created by the person who created the site. You can't XSS your own site. If the string is sourced from user input then it doesn't exist while the HTML is being parsed, and there is no problem.
The article says that the problem arises when you add user controlled strings directly into the page, but that's simply because he isn't escaping the user input. You don't need to sanitise it. Infact you don't even need to escape it if you're using CDATA sections as you should be, or if you use an external JS file.
11
u/[deleted] Aug 10 '12
This is basic, ground-level XSS. As basic as it gets. It's not a 'security flaw' in javascript so much as it is the expected behavior of embedding javascript in an HTML page. And if you are trusting user input without filtering, you are doing it wrong.
Also, the title is misleading.