XSS 攻击是“跨站脚本”,它不直接作用于服务器,而是通过一些正常的站内交互途径,例如发布评论,提交含有 JavaScript 的内容文本。这时服务器端如果没有过滤或转义掉这些脚本,作为内容发布到了页面上,其他用户访问这个页面的时候就会运行这些脚本。
CSRF 攻击是“跨站请求伪造”,它也不直接作用于服务器,主要手段是伪造请求,冒充正常用户在网站进行操作和交互。 XSS 是实现 CSRF 的诸多途径中的一条,但绝对不是唯一的一条。一般习惯上把通过 XSS 来实现的 CSRF 称为 XSRF。