XSS filter to remove all scripts

前端 未结 2 1218
北恋
北恋 2021-01-23 07:54

I am implementing an XSS filter for my web application and also using the ESAPI encoder to sanitise the input.

The patterns I am using are as given below,



        
2条回答
  •  不思量自难忘°
    2021-01-23 08:36

    This isn't the right approach. It's mathematically impossible to write a regex capable of correctly punting XSS. (Regex is "regular" but HTML and Javascript are both context-free grammars.)

    You can however guarantee that when you switch contexts, (hand off a piece of data that is going to be interpreted) that the data is correctly escaped for that context switch. So, when sending data to a browser, escape it for HTML if its being handled as HTML or as Javascript if its being handled by javascript.

    If you DO need to allow HTML/javascript into your application, then you'll want a web-application firewall or a framework like HDIV.

提交回复
热议问题