gpt4 book ai didi

javascript - 处理嵌入式 SVG 脚本标签中的字符引用

转载 作者:太空狗 更新时间:2023-10-29 13:30:31 25 4
gpt4 key购买 nike

这是一个xss脚本:

<svg><script>&#x61;&#x6c;&#x65;&#x72;&#x74;&#x28;&#x31;&#x29;</script></svg>

<script>之间的代码标签将被翻译成 alert(1)由浏览器执行。

但如果我不使用 <svg>标记代码不会被翻译成脚本。谁能告诉我为什么会这样? <svg>如何标记工作?

最佳答案

character references的使用根据 HTML 5 规范,HTML 解析器明确不允许在脚本标记内使用。

HTML5 有一个 separate script parsing mode作为随上下文变化的多种标记化模式之一。脚本解析不允许字符引用,其他一些解析模式允许。

SVG 基于 XML,其中的规则更加简单直接。基本上任何地方都允许使用字符引用,因为有 aren't different context sensitive parsing modes .

对于 HTML 中的 SVG,HTML 规范 says

The svg element from the SVG namespace falls into the embedded content, phrasing content, and flow content categories for the purposes of the content models in this specification.

换句话说,将所有 SVG 文本解析为短语内容。所有 SVG 都是 HTML 5 解析器的单一自定义标记化模式。

关于javascript - 处理嵌入式 SVG 脚本标签中的字符引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30952737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com