Preventing CSRF?

半腔热情 提交于 2019-12-04 08:52:49

The easiest way I found to prevent CSRF issues is:

  1. On the server side, assign an HttpOnly cookie to the client with a random (unguessable) token

  2. Place a hidden field on the form with that cookie value

  3. Upon form submit, ensure the hidden field value equals the cookie value (on the server side of things)

If you make the following changes then I think you're safe

  • no data updates should be allowed through GET (or better POST as well) (since both can be used through HTML forms)
  • disable CORS on your server (or at least on endpoints that are critical and/or make changes to data)
  • allow JSON-only APIs (ie. only accept input through JSON on critical endpoints at least)

Just to add to above: Do not use method overrides and do not support old browsers.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!