这些 html 标签和属性是否会使我的网站易受攻击?
Can these html tags and attribs make my site vulnerable?
我正在开发一个社交网站,希望用户在他们的帖子中只允许这些 html 标签和属性:
tags: <img>,<b>, <strong>, <blockquote>, <a>
attribs: 'src', 'alt', 'width', 'height', 'href','class'
任何其他标签都将在呈现的 html 中过滤掉。
我想知道这个有限的集合是否也可以打开一些 XXS 或其他漏洞利用的大门?
是的,如果您允许这些标签和属性,您将容易受到 XSS 攻击,例如:
<a href="javascript: code that sends users login cookie to hacker">click me!</a>
在 request(用户提交潜在的 XSS)中,使用 real HTML 解析器(如 JSoup)根据白名单验证你的HTML。
在 response(显示潜在的 XSS)中使用一个库来 HTML encode 用户输入。参见 https://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project
阅读https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
usandfriends 评论不正确,这与 CORS 无关
我正在开发一个社交网站,希望用户在他们的帖子中只允许这些 html 标签和属性:
tags: <img>,<b>, <strong>, <blockquote>, <a>
attribs: 'src', 'alt', 'width', 'height', 'href','class'
任何其他标签都将在呈现的 html 中过滤掉。 我想知道这个有限的集合是否也可以打开一些 XXS 或其他漏洞利用的大门?
是的,如果您允许这些标签和属性,您将容易受到 XSS 攻击,例如:
<a href="javascript: code that sends users login cookie to hacker">click me!</a>
在 request(用户提交潜在的 XSS)中,使用 real HTML 解析器(如 JSoup)根据白名单验证你的HTML。
在 response(显示潜在的 XSS)中使用一个库来 HTML encode 用户输入。参见 https://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project
阅读https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
usandfriends 评论不正确,这与 CORS 无关