PageRenderTime 53ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/config/csrf.js

https://gitlab.com/n4utilius/formas
JavaScript | 64 lines | 0 code | 4 blank | 60 comment | 0 complexity | 3da9bb249fd92bdd65dd6a36f9384c4e MD5 | raw file
  1. /**
  2. * Cross-Site Request Forgery Protection Settings
  3. * (sails.config.csrf)
  4. *
  5. * CSRF tokens are like a tracking chip. While a session tells the server that a user
  6. * "is who they say they are", a csrf token tells the server "you are where you say you are".
  7. *
  8. * When enabled, all non-GET requests to the Sails server must be accompanied by
  9. * a special token, identified as the '_csrf' parameter.
  10. *
  11. * This option protects your Sails app against cross-site request forgery (or CSRF) attacks.
  12. * A would-be attacker needs not only a user's session cookie, but also this timestamped,
  13. * secret CSRF token, which is refreshed/granted when the user visits a URL on your app's domain.
  14. *
  15. * This allows us to have certainty that our users' requests haven't been hijacked,
  16. * and that the requests they're making are intentional and legitimate.
  17. *
  18. * This token has a short-lived expiration timeline, and must be acquired by either:
  19. *
  20. * (a) For traditional view-driven web apps:
  21. * Fetching it from one of your views, where it may be accessed as
  22. * a local variable, e.g.:
  23. * <form>
  24. * <input type="hidden" name="_csrf" value="<%= _csrf %>" />
  25. * </form>
  26. *
  27. * or (b) For AJAX/Socket-heavy and/or single-page apps:
  28. * Sending a GET request to the `/csrfToken` route, where it will be returned
  29. * as JSON, e.g.:
  30. * { _csrf: 'ajg4JD(JGdajhLJALHDa' }
  31. *
  32. *
  33. * Enabling this option requires managing the token in your front-end app.
  34. * For traditional web apps, it's as easy as passing the data from a view into a form action.
  35. * In AJAX/Socket-heavy apps, just send a GET request to the /csrfToken route to get a valid token.
  36. *
  37. * For more information on CSRF, check out:
  38. * http://en.wikipedia.org/wiki/Cross-site_request_forgery
  39. *
  40. * For more information on this configuration file, including info on CSRF + CORS, see:
  41. * http://beta.sailsjs.org/#/documentation/reference/sails.config/sails.config.csrf.html
  42. *
  43. */
  44. /****************************************************************************
  45. * *
  46. * Enabled CSRF protection for your site? *
  47. * *
  48. ****************************************************************************/
  49. // module.exports.csrf = false;
  50. /****************************************************************************
  51. * *
  52. * You may also specify more fine-grained settings for CSRF, including the *
  53. * domains which are allowed to request the CSRF token via AJAX. These *
  54. * settings override the general CORS settings in your config/cors.js file. *
  55. * *
  56. ****************************************************************************/
  57. // module.exports.csrf = {
  58. // grantTokenViaAjax: true,
  59. // origin: ''
  60. // }