GVKun编程网logo

React 门户和 HTML 通过危险的SetInnerHTML 注入(react htmlfor)

6

这篇文章主要围绕React门户和HTML通过危险的SetInnerHTML注入和reacthtmlfor展开,旨在为您提供一份详细的参考资料。我们将全面介绍React门户和HTML通过危险的SetIn

这篇文章主要围绕React 门户和 HTML 通过危险的SetInnerHTML 注入react htmlfor展开,旨在为您提供一份详细的参考资料。我们将全面介绍React 门户和 HTML 通过危险的SetInnerHTML 注入的优缺点,解答react htmlfor的相关问题,同时也会为您带来c# – Html Agility Pack – 删除元素,但不删除innerHtml、HTML.innerHTML vs Jquery.html() – Javascript执行、innerhtml-SELECT控件通过innerHTML插入,接下来该如何传值的问题(PHP)、innerHTML/outerHTML; innerText/outerText; textContent_html/css_WEB-ITnose的实用方法。

本文目录一览:

React 门户和 HTML 通过危险的SetInnerHTML 注入(react htmlfor)

React 门户和 HTML 通过危险的SetInnerHTML 注入(react htmlfor)

应该用于修改外部 HTML 元素而不是 React 应用程序内部的元素

这并不完全正确。当你想在反应树之外的某个地方渲染反应树的元素(意思是,进入不受反应控制的 DOM)时,使用 React 门户。并且使用 to_type == 'int' 设置的 DOM 元素不受 React 控制。我认为您的解决方案,在特定情况下,是可以的。在删除“消息”之前,您绝对应该小心并删除门户,因此 React 不会尝试将某些内容渲染到 dangerouslySetInnerHTML 中,否则它应该可以工作。

c# – Html Agility Pack – 删除元素,但不删除innerHtml

c# – Html Agility Pack – 删除元素,但不删除innerHtml

我可以通过note.Remove()来轻松删除元素:

HtmlDocument html = new HtmlDocument();

html.Load(Server.MapPath(@"~\Site\themes\default\index.cshtml"));

foreach (var item in html.DocumentNode.SelectNodes("//removeMe"))
{
    item.Remove();
}

但这也删除了innerHtml.
如果我只想删除标签并保留innerHtml怎么办?

例:

<ul>
    <removeMe>
        <li>
            <a href="#">Keep me</a>
        </li>
    </removeMe>
</ul>

任何帮助,将不胜感激 :)

解决方法

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);

var node = doc.DocumentNode.SelectSingleNode("//removeme");
node.ParentNode.RemoveChild(node,true);

HTML.innerHTML vs Jquery.html() – Javascript执行

HTML.innerHTML vs Jquery.html() – Javascript执行

参考:html() vs innerHTML jquery/javascript & XSS attacks

从这一点,我可以推断,Jquery提取< script>标签并在DOM中单独执行,它不会出现在DOM中.

请考虑以下HTML代码:

a =< iframe>< iframe //>< script> alert(1)< / script>

b =< iframe>< iframe> //&LT脚本&GT警报(1) – ; /脚本&GT

截至a中的代码,body.innerHTML = a;不执行脚本,但$(“body”).html(a);确实.

为什么? Jquery的.html()在//之后执行内容但是.innerHTML =不执行?

如果是这样,为什么b.内部.innerHTML =或.html()不会被执行?

更新:对于演示,打开控制台,然后执行:

> document.body.innerHTML =“< iframe>< iframe //>< script> alert(1)< / script>”
> $(“body”).html(“< iframe>< iframe //>< script> alert(1)< / script>”);

1将不执行alert(),但2将执行.用b替换HTML值.两者都不会被执行.

更新2:从我可以确定HTML代码将在Jquery的body()中执行但不在.innerHTML =?

解决方法:

如果在jQuery源代码中更深入一点,我们可以找到html方法.

在这种方法中存在于line

this.empty().append( value );

如果现在转到append,我们可以找到下一个

append: function() {
    return domManip( this, arguments, function( elem ) {
        if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
            var target = manipulationTarget( this, elem );
            target.appendChild( elem );
        }
    } );
}

所以,现在找到domManip.这个函数来自html-string构建的fragmen,如果片段有脚本标签执行next code

DOMEval( node.textContent.replace( rcleanScript, "" ), doc );

在哪里DOMEval

function DOMEval( code, doc ) {
    doc = doc || document;

    var script = doc.createElement( "script" );

    script.text = code;
    doc.head.appendChild( script ).parentNode.removeChild( script );
}

所以,至少,我们找到执行脚本的地方.

那么,为什么在某些情况下html运行脚本,否则不行?

这取决于输入字符串和返回buildFragment function.

在buildFragment中我们可以找到next line

tmp.innerHTML = wrap[ 1 ] + jQuery.htmlPrefilter( elem ) + wrap[ 2 ];

其中elem是输入字符串,jQuery.htmlPrefilter是下一个函数

htmlPrefilter: function( html ) {
    return html.replace( rxhtmlTag, "<$1></$2>" );
}

所以,输入字符串刚刚替换为某些regular exporession rxhtmlTag.

rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|Meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi,

所以,试试这个来检查字符串:

console.log(jQuery.htmlPrefilter("<iframe><iframe //><script>alert(1)</" + "script>"));
console.log(jQuery.htmlPrefilter("<iframe><iframe> // <script>alert(1)</" + "script>"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>

因此,在第一种情况下,结果是

<iframe><iframe /></iframe><script>alert(1)</script>

在tmp div中将其作为innerHTML插入后,div内部创建了两个元素:iframe和script.所以在此脚本可用于查找和执行之后

在第二种情况:

<iframe><iframe> // <script>alert(1)</script>

字符串未更改,并且在tmp div中将其作为innerHTML插入后,div内部只创建一个带编码内容的iframe元素.这就是为什么在这种情况下脚本不能执行.

innerhtml-SELECT控件通过innerHTML插入,接下来该如何传值的问题(PHP)

innerhtml-SELECT控件通过innerHTML插入,接下来该如何传值的问题(PHP)

innerhtmlphpjquery

前台页面如图
图片说明
需求:兑换码输完以后,会得到一个折扣,需要与原价相乘,得到最终的实际价格
票价处代码如图
图片说明
票价的select是使用innerhtml,代码如下
图片说明
我是打算在兑换码输入框的焦点离开时,去判断兑换码的有效性(已解决),并且去算这个最终价格(未解决),焦点离开代码如下
图片说明
请问:如何在焦点离开时,把select(innerhtml)选中的值传出去,具体应该怎么传?谢谢各位!!!

innerHTML/outerHTML; innerText/outerText; textContent_html/css_WEB-ITnose

innerHTML/outerHTML; innerText/outerText; textContent_html/css_WEB-ITnose

innerHTML v.s. outerHTML

  • Element.innerHTML
  •   Reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML
  •   Functionality
  •   Get serialized HTML code describing its descendants.
  •   Set : Remove all the children, parse the content string and assign the resulting nodes as the children of the element. 
  • Element.outerHTML
  •   Reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/outerHTML
  •   Functionality
  •   Get serialized HTML fragment describling the element and its descendants.
  •   Set : Replace the element with the nodes generated by parsing the content string with parent of the element as the context node for the fragment parsing algorithm.
  •   NOTE
  •   If element has no parent element, set outerHTML will throw DOMException.
  •   e.g. [Chrome Dev Console]  document.documentElement.outerHTML=''a'';   Uncaught DOMException: Failed to set the ''outerHTML'' property on ''Element'': This element''s parent is of type ''#document'', which is not an element node.
  •   Considering below code.

    // HTML:// <div id="container"><div id="d">This is a div.</div></div>container = document.getElementById("container");d = document.getElementById("d");console.log(container.firstChild.nodeName); // logs "DIV"d.outerHTML = "<p>this paragraph replaced the original div.</p>";console.log(container.firstChild.nodeName); // logs "P"// The #d div is no longer part of the document tree,// the new paragraph replaced it.
    登录后复制

    While the element will be replaced in the document, the variable whose outerHTML property was set will still hold a reference to the original element!

  • innerText and outerText
  • Node.innerText
  •   Non-standard: DO NOT use it on production site.
  • HTMLElement.outerText
  •   Non-standard: DO NOT use it on production site.
  • Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
    Basic support 4 45 (45) 6 9.6 (probably earlier) 3
    textContent v.s innerText
  • Node.textContent
  • Get: different node types gets different result
  •   null: document, notation (use document.documentElement.textContent instead).
  •   text inside the node: CDATA, comment, text node, processing instruction. (nodeValue)
  •   concatenation of children nodes (excluding comment, processing instruction nodes) text: other types node
  • Set: Remove node children and replace it with a text node.
  • Difference from innerText
  •   many... : refer to MDN.
  • Why we still need innerText sometime?
  •   Browser compatibility!
  •   IE has better support for innerText than for textContent. Only IE9+ supports textContent, but IE6+ supports innerText.
  •   Common usage:
  •   set

    t[t.innerText ? ''innerText'' : ''textContent''] = v.n
    登录后复制

    立即学习“前端免费学习笔记(深入)”;

  • 立即学习“前端免费学习笔记(深入)”;

  •  get

    it = currHeaderChildNodes[i].innerText || currHeaderChildNodes[i].textContent;
    登录后复制

     

    立即学习“前端免费学习笔记(深入)”;

  •  

    立即学习“前端免费学习笔记(深入)”;

    textContent v.s. innerHTML
  • It''s recommand to use textContent!
  • innerHTML parse text as HTML (except "script" element) -> poor performance!
  • innerHTML has security problem!
  • 今天关于React 门户和 HTML 通过危险的SetInnerHTML 注入react htmlfor的介绍到此结束,谢谢您的阅读,有关c# – Html Agility Pack – 删除元素,但不删除innerHtml、HTML.innerHTML vs Jquery.html() – Javascript执行、innerhtml-SELECT控件通过innerHTML插入,接下来该如何传值的问题(PHP)、innerHTML/outerHTML; innerText/outerText; textContent_html/css_WEB-ITnose等更多相关知识的信息可以在本站进行查询。

    本文标签: