个人的奋斗还是历史的进程?
by
Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts are injected into otherwise benign and trusted websites.
Cross-site scripting (XSS) is a type of coding vulnerability. It is usually found in web applications. XSS enables attackers to inject malicious into web pages viewed by other users. XSS may allow attackers to bypass access controls such as the same-origin policy may. This is one of the most common vulnerabilities found accordingly with OWASP Top 10. Symantec in its annual threat report found that XSS was the number two vulnerability found on web servers.
将用户输入作为代码执行,最终导致请求到恶意脚本
XSS 攻击可以分为 3 类:存储型(持久型)、反射型(非持久型)、DOM 型。
注入型脚本永久存储在目标服务器上。当浏览器请求数据时,脚本从服务器上传回并执行。
当用户点击一个恶意链接,或者提交一个表单,或者进入一个恶意网站时,注入脚本进入被攻击者的网站。Web 服务器将注入脚本,比如一个错误信息,搜索结果等 返回到用户的浏览器上。由于浏览器认为这个响应来自”可信任”的服务器,所以会执行这段脚本。
通过修改原始的客户端代码,受害者浏览器的 DOM 环境改变,导致有效载荷的执行。也就是说,页面本身并没有变化,但由于 DOM 环境被恶意修改,有客户端代码被包含进了页面,并且意外执行。
获取Cookie、会话令牌或其他敏感信息。重写HTML页面的内容。
Cross-site scripting faws can be difcult to identify and remove from a web application. The best practice to search for faws is to perform an intense code review and search for all places where user input through a HTTP request could possibly make its way into the HTML output.
untrusted data可能是通过以下api被引入DOM
a. Node.textContent
b. document.createTextNode
c. Element.setAttribute (second parameter only)
v-bind示例
<body>
<div id="app">
<a v-bind:href="message">aaa</a>
<video src="#" v-bind:onclick="message" v-bind:onerror="message">bbb</video>
<img src="1" v-bind:onerror="message" />
<form v-bind:action="message"><input type="submit" />ccc</form>
<input type="text" v-bind:onchange="message"></input>
<img src="img/HBuilder.png" v-bind:onload="message"/>
</div>
<script>
new Vue({
el: '#app',
data: {
message: 'javascript:alert(4)'
}
})
</script>
</body>
穷举是不可能的,需要把握原则
针对js框架需要持续关注框架的CVE,并确保框架一直保持在最新的稳定版本
通过扫描工具,扫描工具并不能穷尽XSS漏洞,所以代码检视依然很重要,当然代码检视也不能排查出所有的漏洞,但是这是一种基于现有风险的纵深防御方式,是一种最佳实践
OWASP也提供了Zed Attack Proxy(ZAP)工具
微软的Anti-XSS库(面向.net)
tags:参考
https://developer.mozilla.org/zh-CN/docs/Glossary/Cross-site_scripting
开放式 Web 应用安全项目(OWASP)https://owasp.org/www-community/attacks/xss/#