├── .gitignore ├── README.md └── README_zh.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Understanding CSRF 3 | 4 | The Express team's [csrf](https://github.com/pillarjs/csrf) and [csurf](https://github.com/expressjs/csurf) modules 5 | frequently have issues popping up concerned about our usage of cryptographic functions. 6 | These concerns are unwarranted due to a misunderstanding of how CSRF tokens work. 7 | So here's a quick run down! 8 | 9 | Read this and still have questions? Want to tell us we're wrong? Open an issue! 10 | 11 | ## How does a CSRF attack work? 12 | 13 | On their own (phishing site), an attacker could create an AJAX button or form that creates a request against your site: 14 | 15 | ```html 16 |
19 | ``` 20 | 21 | This is worse with AJAX as the attacker could use other methods like `DELETE` as well as read the result. 22 | This is particularly important when the user has some sort of session with very personal details on your site. 23 | If this is in the context of a technologically illiterate user, 24 | there might be some inputs for credit card and social security info. 25 | 26 | ## How to mitigate CSRF attacks? 27 | 28 | ### Use only JSON APIs 29 | 30 | AJAX calls use JavaScript and are CORS-restricted. 31 | There is no way for a simple `