"Microsoft ASP.NET Request Filtering Bypass Cross-Site Scripting Vulnerability"
Following high security vulnerability is being detected for one of my web site in the production. We need to fix the issue immediately. When I went through the Fix section of the report, it say to handle it in the code using HttpUtility.HtmlEncode() function. Will using HttpUtility.HtmlEncode() remove the Vulnerability or will it just ensure safety and still Vulnerability will persist? Is there any other way of handling it? Here is the piece of code that is throwing this exception. What is the best way to handle it?
function fnModelDetails(varId) { var filepath = 'ModalBox.aspx?modelfileid=' + varId +'&mod=30&page=Associated Model Names'; var screenSettings = 'help:off;status:off;resizable:no;dialogHeight:' + 400 + 'px;dialogWidth:' + 400 + 'px;'; window.showModalDialog(filepath,'',screenSettings); return false; }
Any help on this will be be great.
Thanks in advance.
Manjunath
Manjunath--
If I understand your question completely, you have a few options with what you could do here.
I can't stress enough that you don't want to black-list (that is, remove "dangerous" characters), as that is never a complete solution. See tons of Google results for discussions on white-list vs black-list filtering, if you need more information.
HP Web Security Research Group
I would definitely say whitelist and reject rather and try to filter. Plus, as already said, HTML encode HTML output if it came from user input, database, or a file and URL encode any URL strings that are returned. Microsoft has a good [sic] article on this titled, "How To: Prevent Cross-Site Scripting in ASP.NET":
http://msdn.microsoft.com/en-us/library/ms998274.aspx
Keep in mind that care needs to be taken when escaping outputs depending on the output context. The OWASP XSS prevention cheatsheet explains this very well:
http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
As you can see, ESAPI provides a few methods to adequately encode for various output contexts:
encodeForHtml
encodeForHtmlAttribute
encodeForJavaScript
encodeForCSS
encodeForURL
In your case (as per the code you provided), you are not just outputting into HTML but into a URL within HTML.
There's an alpha release available of OWASP ESAPI for Classic ASP: http://www.owasp.org/index.php/Category:OWASP_Enterprise_Security_API#tab=Classic_ASP