zoukankan      html  css  js  c++  java
  • 网上流行的JS HTMLDecode不安全

    网上很多文档提到一个JS利用DOM特性作HTMLDecode的方法:

    function HTMLDecode(strEncodeHTML)
    {
        
    var div = document.createElement('div');
        div.innerHTML 
    = strEncodeHTML;
        
    return div.innerText;
    }

    这个函数是不安全的,如果参数带有用户输入,就可能导致执行JS代码:

    function HTMLDecode(strEncodeHTML)
    {
        
    var div = document.createElement('div');
        div.innerHTML 
    = strEncodeHTML;
        
    return div.innerText;
    }

    HTMLDecode(
    "<img src=1 onerror=alert(1) />");


    有人很傻很天真的以为,这个没有被appendChild到dom树的元素,应该不会执行。

  • 相关阅读:
    投票练习
    多条件查询
    PHP 购物车
    PHP TP模型
    PHP smarty函数
    PHP smarty复习
    PHP smarty缓存
    PHP phpcms
    php smarty查询分页
    PHP Smarty变量调节器
  • 原文地址:https://www.cnblogs.com/luoluo/p/1414123.html
Copyright © 2011-2022 走看看