Front-end firewall for XSS vulnerabilities: Seamless Protection (1)

Source: Internet
Author: User

The previous article explains the attack and defense practices of the hook program, and implements a monitoring solution for the Framework page, which will protect all subpages.

So far, our protection depth is almost the same, but the breadth is still lacking.

For example, our property hook only considers setAttribute, but ignores the setAttributeNode. Although this method is never used, it does not mean that people cannot use it.

For example, createElement is used to create elements. In fact, createElementNS can also be used. You can even use the ready-made element cloneNode to achieve the goal. Therefore, these edge methods are worth considering.

Next we will review the previously discussed monitoring sites one by one.

Inline event execution eval

At the end of the first article, it is best to monitor eval, setTimeout ('... ') these functions can parse code to prevent execution of XSS code stored elsewhere.

Let's first list these functions:

evalsetTimeout(String) / setInterval(String)FunctionexecScript / setImmediate(String)

In fact, you can monitor all the hooks in the previous article. But the reality is not as simple as we think.

Is there a problem with eval rewriting?

Eval is not a function. Why can't I rewrite it?

 
 
  1. Var raw_fn = window. eval;
  2.  
  3. Window. eval = function (exp ){
  4. Alert ('execute eval: '+ exp );
  5. Return raw_fn.apply (this, arguments );
  6. };
  7.  
  8. Console. log (eval ('1 + 1 '));

No problem at all. This is because the code is too simple. The following Demo shows the defects of the Alibaba Cloud version eval:

 
 
  1. (function() {  
  2.     eval('var a=1');  
  3. })();  
  4.  
  5. alert(typeof a); 

Run

It should be undefined, but the result is number. All the local variables are global. What is the situation? In fact, eval is not really a function, but a keyword!


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.