csrf.js
2.92 KB
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
/**
* Cross-Site Request Forgery Protection Settings
* (sails.config.csrf)
*
* CSRF tokens are like a tracking chip. While a session tells the server that a user
* "is who they say they are", a csrf token tells the server "you are where you say you are".
*
* When enabled, all non-GET requests to the Sails server must be accompanied by
* a special token, identified as the '_csrf' parameter.
*
* This option protects your Sails app against cross-site request forgery (or CSRF) attacks.
* A would-be attacker needs not only a user's session cookie, but also this timestamped,
* secret CSRF token, which is refreshed/granted when the user visits a URL on your app's domain.
*
* This allows us to have certainty that our users' requests haven't been hijacked,
* and that the requests they're making are intentional and legitimate.
*
* This token has a short-lived expiration timeline, and must be acquired by either:
*
* (a) For traditional view-driven web apps:
* Fetching it from one of your views, where it may be accessed as
* a local variable, e.g.:
* <form>
* <input type="hidden" name="_csrf" value="<%= _csrf %>" />
* </form>
*
* or (b) For AJAX/Socket-heavy and/or single-page apps:
* Sending a GET request to the `/csrfToken` route, where it will be returned
* as JSON, e.g.:
* { _csrf: 'ajg4JD(JGdajhLJALHDa' }
*
*
* Enabling this option requires managing the token in your front-end app.
* For traditional web apps, it's as easy as passing the data from a view into a form action.
* In AJAX/Socket-heavy apps, just send a GET request to the /csrfToken route to get a valid token.
*
* For more information on CSRF, check out:
* http://en.wikipedia.org/wiki/Cross-site_request_forgery
*
* For more information on this configuration file, including info on CSRF + CORS, see:
* http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.csrf.html
*
*/
/****************************************************************************
* *
* Enabled CSRF protection for your site? *
* *
****************************************************************************/
// module.exports.csrf = false;
/****************************************************************************
* *
* You may also specify more fine-grained settings for CSRF, including the *
* domains which are allowed to request the CSRF token via AJAX. These *
* settings override the general CORS settings in your config/cors.js file. *
* *
****************************************************************************/
// module.exports.csrf = {
// grantTokenViaAjax: true,
// origin: ''
// }