Skip to content

Commit

Permalink
docs: fix csrf (#1551)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored and fengmk2 committed Oct 20, 2017
1 parent 7fb9bbf commit c508f9f
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions docs/source/zh-cn/core/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,21 +265,10 @@ CSRF 攻击会对网站发起恶意伪造的请求,严重影响网站的安全

##### 同步表单的 CSRF 校验

在同步渲染页面时,所有的表单请求中增加一个 name 为 `_csrf` 的隐藏域,值为 `ctx.csrf`,这样用户在提交这个表单的时候会将 CSRF token 提交上来:
在同步渲染页面时,在表单请求中增加一个 name 为 `_csrf` 的 url query,值为 `ctx.csrf`,这样用户在提交这个表单的时候会将 CSRF token 提交上来:

```html
<form method="POST" action="/upload" enctype="multipart/form-data">
title: <input name="title" />
file: <input name="file" type="file" />
<input type="hidden" name="_csrf" value="{{ ctx.csrf }}">
<button type="submit">upload</button>
</form>
```

CSRF token 也可以通过 url query 传递:

```html
<form method="POST" action="/upload?_csrf={{ ctx.csrf }}" enctype="multipart/form-data">
<form method="POST" action="/upload?_csrf={{ ctx.csrf | safe }}" enctype="multipart/form-data">

This comment has been minimized.

Copy link
@lidianhao123

lidianhao123 Oct 24, 2017

此处的 safe 变量是指什么?一直有疑惑,希望得到解答。我目前使用的是 egg 1.8.0 版本,该版本是否支持 safe

This comment has been minimized.

Copy link
@atian25

atian25 Oct 24, 2017

Author Member

模板引擎 (如 egg-view-nunjucks) 自带的 safe filter,渲染出来的时候。

cc @jtyjty99999 csrf 的字符串会有特殊字符么?

title: <input name="title" />
file: <input name="file" type="file" />
<button type="submit">upload</button>
Expand Down

0 comments on commit c508f9f

Please sign in to comment.