HTML Comment Behavior

旧巷老猫 提交于 2019-12-06 04:18:37

Formally, the comment syntax in HTML up to HTML 4.01 is complicated, following the SGML standard, but in practice HTML was never implemented as an SGML application. An old page HTML comments by WDG briefly explains the HTML comment syntax and makes some practical notes on it. In practice, a comment should start with <!-- and end with -->. This is made formal in XHTML and in HTML5.

But browsers have implemented comment syntax more liberally, so that you can start them with <! and end with > (even though this is not official and causes an error message from an HTML5 validator). This has been described and prescribed as required browser behavior in HTML5 parsing rules, see section 8.2.4.45 Markup declaration open state, which defines how “bogus comment state” will be entered.

Thus, <! foo > actually works (and creates a comment node in the DOM), but it is forbidden in XHTML and in HTML5.

This is talked about in a XSS demo by OWASP YoutubeVideo around the 18 minute mark. But basically its the way the browser handles the comment because it surrounds whatever you put with -- -- so if you put <!-> it goes to five <!----->.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!