auto commit
This commit is contained in:
@ -13,6 +13,8 @@
|
||||
|
||||
跨站脚本攻击(Cross-Site Scripting, XSS),可以将代码注入到用户浏览的网页上,这种代码包括 HTML 和 JavaScript。
|
||||
|
||||
## 攻击原理
|
||||
|
||||
例如有一个论坛网站,攻击者可以在上面发布以下内容:
|
||||
|
||||
```html
|
||||
@ -43,40 +45,23 @@
|
||||
|
||||
例如将 `<` 转义为 `<`,将 `>` 转义为 `>`,从而避免 HTML 和 Jascript 代码的运行。
|
||||
|
||||
## 富文本编辑器
|
||||
|
||||
富文本编辑器允许用户输入 HTML 代码,就不能简单地将 `<` 等字符进行过滤了,极大地提高了 XSS 攻击的可能性。
|
||||
|
||||
富文本编辑器通常采用 XSS filter 来防范 XSS 攻击,通过定义一些标签白名单或者黑名单,从而不允许有攻击性的 HTML 代码的输入。
|
||||
|
||||
以下例子中,form 和 script 等标签都被转义,而 h 和 p 等标签将会保留。
|
||||
|
||||
> [XSS 过滤在线测试](http://jsxss.com/zh/try.html)
|
||||
|
||||
```html
|
||||
<h1 id="title">XSS Demo</h1>
|
||||
|
||||
<p class="text-center">
|
||||
Sanitize untrusted HTML (to prevent XSS) with a configuration specified by a Whitelist.
|
||||
</p>
|
||||
<p>123</p>
|
||||
|
||||
<form>
|
||||
<input type="text" name="q" value="test">
|
||||
<button id="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
<pre>hello</pre>
|
||||
|
||||
<p>
|
||||
<a href="http://jsxss.com">http</a>
|
||||
</p>
|
||||
|
||||
<h3>Features:</h3>
|
||||
<ul>
|
||||
<li>Specifies HTML tags and their attributes allowed with whitelist</li>
|
||||
<li>Handle any tags or attributes using custom function</li>
|
||||
</ul>
|
||||
|
||||
<script type="text/javascript">
|
||||
alert(/xss/);
|
||||
</script>
|
||||
@ -85,32 +70,21 @@ alert(/xss/);
|
||||
```html
|
||||
<h1>XSS Demo</h1>
|
||||
|
||||
<p>
|
||||
Sanitize untrusted HTML (to prevent XSS) with a configuration specified by a Whitelist.
|
||||
</p>
|
||||
<p>123</p>
|
||||
|
||||
<form>
|
||||
<input type="text" name="q" value="test">
|
||||
<button id="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
<pre>hello</pre>
|
||||
|
||||
<p>
|
||||
<a href="http://jsxss.com">http</a>
|
||||
</p>
|
||||
|
||||
<h3>Features:</h3>
|
||||
<ul>
|
||||
<li>Specifies HTML tags and their attributes allowed with whitelist</li>
|
||||
<li>Handle any tags or attributes using custom function</li>
|
||||
</ul>
|
||||
|
||||
<script type="text/javascript">
|
||||
alert(/xss/);
|
||||
</script>
|
||||
```
|
||||
|
||||
> [XSS 过滤在线测试](http://jsxss.com/zh/try.html)
|
||||
|
||||
# 二、跨站请求伪造
|
||||
|
||||
## 概念
|
||||
@ -119,6 +93,8 @@ alert(/xss/);
|
||||
|
||||
XSS 利用的是用户对指定网站的信任,CSRF 利用的是网站对用户浏览器的信任。
|
||||
|
||||
## 攻击原理
|
||||
|
||||
假如一家银行用以执行转账操作的 URL 地址如下:
|
||||
|
||||
```
|
||||
|
Reference in New Issue
Block a user