-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.html
463 lines (322 loc) · 12.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="Vodka - Fast and unfancy HTTP server framework for Golang">
<meta property="og:site_name" content="vodka">
<meta property="og:og:description" content="">
<title>
CSRF Middleware | Vodka - Fast and unfancy HTTP server framework for Golang
</title>
<link rel="stylesheet" href="../../styles/doc.css">
</head>
<body>
<nav class="navbar">
<a href="../../index.html"><img class="logo" src="../../images/logo.png" alt="Vodka"></a>
<span class="w3-hide-small w3-hide-medium">
<input id="search-box" type="text" class="w3-input" placeholder="Search...">
<i class="fa fa-search"></i>
</span>
<a class="github-button" href="https://github.com/insionng/vodka" data-icon="octicon-star" data-style="mega" data-count-href="../../insionng/vodka/stargazers/index.html" data-count-api="/repos/insionng/vodka#stargazers_count" data-count-aria-label="# stargazers on GitHub" aria-label="Star insionng/vodka on GitHub">
Star
</a>
<span class="w3-xxlarge w3-hide-large" onclick="openSidenav()">☰</span>
</nav>
<nav id="sidenav" class="w3-sidenav w3-collapse w3-animate-left">
<span class="w3-closenav w3-xxlarge w3-hide-large" onclick="closeSidenav()">
×
</span>
<a class="support w3-btn w3-white w3-border w3-border-theme w3-round-xlarge" href="https://github.com/vodka-contrib">
Vodka Contrib
</a>
<h4>> Guide</h4>
<a href="../../guide/installation/index.html">
Installation
</a>
<a href="../../guide/migrating/index.html">
Migrating
</a>
<a href="../../guide/customization/index.html">
Customization
</a>
<a href="../../guide/static-files/index.html">
Static Files
</a>
<a href="../../guide/templates/index.html">
Templates
</a>
<a href="../../guide/routing/index.html">
Routing
</a>
<a href="../../guide/context/index.html">
Context
</a>
<a href="../../guide/cookies/index.html">
Cookies
</a>
<a href="../../guide/request/index.html">
Request
</a>
<a href="../../guide/error-handling/index.html">
Error Handling
</a>
<a href="../../guide/testing/index.html">
Testing
</a>
<a href="../../guide/faq/index.html">
FAQ
</a>
<h4>> Middleware</h4>
<a href="../overview/index.html">
Overview
</a>
<a href="../basic-auth/index.html">
BasicAuth
</a>
<a href="../body-limit/index.html">
BodyLimit
</a>
<a href="../cors/index.html">
CORS
</a>
<a class="active" href="#">
CSRF
</a>
<a href="../gzip/index.html">
Gzip
</a>
<a href="../jwt/index.html">
JWT
</a>
<a href="../logger/index.html">
Logger
</a>
<a href="../method-override/index.html">
MethodOverride
</a>
<a href="../recover/index.html">
Recover
</a>
<a href="../redirect/index.html">
Redirect
</a>
<a href="../secure/index.html">
Secure
</a>
<a href="../static/index.html">
Static
</a>
<a href="../trailing-slash/index.html">
TrailingSlash
</a>
<h4>> Recipes</h4>
<a href="../../recipes/hello-world/index.html">
Hello World
</a>
<a href="../../recipes/crud/index.html">
CRUD
</a>
<a href="../../recipes/cors/index.html">
CORS
</a>
<a href="../../recipes/http2/index.html">
HTTP/2
</a>
<a href="../../recipes/middleware/index.html">
Middleware
</a>
<a href="../../recipes/streaming-response/index.html">
Streaming Response
</a>
<a href="../../recipes/websocket/index.html">
WebSocket
</a>
<a href="../../recipes/jsonp/index.html">
JSONP
</a>
<a href="../../recipes/file-upload/index.html">
File Upload
</a>
<a href="../../recipes/subdomains/index.html">
Subdomains
</a>
<a href="../../recipes/jwt/index.html">
JWT
</a>
<a href="../../recipes/google-app-engine/index.html">
Google App Engine
</a>
<a href="../../recipes/graceful-shutdown/index.html">
Graceful Shutdown
</a>
<a href="../../recipes/embed-resources/index.html">
Embed Resources
</a>
<h4>> Godoc</h4>
<a href="https://godoc.org/github.com/insionng/vodka">
vodka
</a>
<a href="https://godoc.org/github.com/insionng/vodka/middleware">
middleware
</a>
<a href="https://godoc.org/github.com/insionng/vodka/engine">
engine
</a>
<a href="https://godoc.org/github.com/insionng/vodka/engine/standard">
engine/standard
</a>
<a href="https://godoc.org/github.com/insionng/vodka/engine/fasthttp">
engine/fasthttp
</a>
</nav>
<div id="search-menu"></div>
<div class="w3-main w3-padding-128">
<div class="ad">
<script async type="text/javascript" src="https://cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=vodkainsionngcom" id="_carbonads_js"></script>
</div>
<div class="w3-row-padding">
<div class="w3-col m9 l9">
<div class="w3-panel w3-red notice">
<h3>
YOUGAM V4 WILL USE <a href="https://github.com/insionng/vodka">VODKA V2</a>
</h3>
<p>
Vodka是一个强大Go语言中间件式的模块化web框架,是基于Echo二次开发的加强版本
</p>
</div>
<article class="content">
<section>
<h2 id="csrf-middleware">CSRF Middleware</h2>
<p>Cross-site request forgery, also known as one-click attack or session riding and
abbreviated as CSRF (sometimes pronounced sea-surf) or XSRF, is a type of malicious
exploit of a website where unauthorized commands are transmitted from a user that
the website trusts.</p>
<p><em>Usage</em></p>
<p><code>e.Use(middleware.CSRF())</code></p>
<h3 id="custom-configuration">Custom Configuration</h3>
<p><em>Usage</em></p>
<pre><code class="language-go">e := vodka.New()
e.Use(middleware.CSRFWithConfig(middleware.CSRFConfig{
TokenLookup: "header:X-XSRF-TOKEN",
}))
</code></pre>
<p>Example above uses <code>X-XSRF-TOKEN</code> request header to extract CSRF token.</p>
<h3 id="accessing-csrf-token">Accessing CSRF Token</h3>
<h4 id="server-side">Server-side</h4>
<p>CSRF token can be accessed from <code>Vodka#Context</code> using <code>ContextKey</code> and passed to
the client via template.</p>
<h4 id="client-side">Client-side</h4>
<p>CSRF token can be accessed from CSRF cookie.</p>
<h3 id="configuration">Configuration</h3>
<pre><code class="language-go">// CSRFConfig defines the config for CSRF middleware.
CSRFConfig struct {
// Skipper defines a function to skip middleware.
Skipper Skipper
// TokenLength is the length of the generated token.
TokenLength uint8 `json:"token_length"`
// Optional. Default value 32.
// TokenLookup is a string in the form of "<source>:<key>" that is used
// to extract token from the request.
// Optional. Default value "header:X-CSRF-Token".
// Possible values:
// - "header:<name>"
// - "form:<name>"
// - "query:<name>"
TokenLookup string `json:"token_lookup"`
// Context key to store generated CSRF token into context.
// Optional. Default value "csrf".
ContextKey string `json:"context_key"`
// Name of the CSRF cookie. This cookie will store CSRF token.
// Optional. Default value "csrf".
CookieName string `json:"cookie_name"`
// Domain of the CSRF cookie.
// Optional. Default value none.
CookieDomain string `json:"cookie_domain"`
// Path of the CSRF cookie.
// Optional. Default value none.
CookiePath string `json:"cookie_path"`
// Max age (in seconds) of the CSRF cookie.
// Optional. Default value 86400 (24hr).
CookieMaxAge int `json:"cookie_max_age"`
// Indicates if CSRF cookie is secure.
// Optional. Default value false.
CookieSecure bool `json:"cookie_secure"`
// Indicates if CSRF cookie is HTTP only.
// Optional. Default value false.
CookieHTTPOnly bool `json:"cookie_http_only"`
}
</code></pre>
<p><em>Default Configuration</em></p>
<pre><code class="language-go">DefaultCSRFConfig = CSRFConfig{
Skipper: defaultSkipper,
TokenLength: 32,
TokenLookup: "header:" + vodka.HeaderXCSRFToken,
ContextKey: "csrf",
CookieName: "_csrf",
CookieMaxAge: 86400,
}
</code></pre>
</section>
<footer style="margin-top: 40px;">
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'insionng';
(function() {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
</footer>
</article>
</div>
</div>
</div>
<footer class="w3-container w3-padding-48 w3-center footer">
<p>
<strong>Vodka</strong> by <a href="https://insionng.com">InsionNg</a> © 2016 InsionNg. All Rights Reserved.
</p>
<p>
<a class="icon" href="https://blog.insionng.com">
<i class="fa fa-rss" aria-hidden="true"></i>
</a>
<a class="icon" href="https://github.com/insionng">
<i class="fa fa-github" aria-hidden="true"></i>
</a>
<a class="icon" href="https://facebook.com/insionng">
<i class="fa fa-facebook" aria-hidden="true"></i>
</a>
<a class="icon" href="https://twitter.com/insionng">
<i class="fa fa-twitter" aria-hidden="true"></i>
</a>
<a class="icon" href="https://plus.google.com/+insionng">
<i class="fa fa-google-plus" aria-hidden="true"></i>
</a>
</p>
</footer>
<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script>
<script type="text/javascript">
docsearch({
apiKey: '69dfc65b57ccba29ec34b68aa5b274ed',
indexName: 'insionng',
inputSelector: '#search-box',
autocompleteOptions: {
dropdownMenuContainer: '#search-menu'
}
});
</script>
<script async defer id="github-bjs" src="https://buttons.github.io/buttons.js"></script>
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-85059636-2', 'auto');
ga('send', 'pageview');
</script>
<script async src="https://www.google-analytics.com/analytics.js"></script>
<script src="../../scripts/prism.js"></script>
<script src="../../scripts/vodka.js"></script>
</body>
</html>