Is Access-Control-Allow-Origin sufficient in preventing XSRF attacks?

雨燕双飞 提交于 2019-12-06 03:27:51
SilverlightFox

No, this is not sufficient. Even though the browser gives the 'Access-Control-Allow-Origin' error, the request has still been made by the browser. If withCredentials is specified by the attacking page:

$http.post(url, {withCredentials: true, ...})

then this request will be sent to your domain with the victim's authentication cookies, meaning that the request to http://www.example.com:8080/user/delete will succeed.

Also, this request could also be made without XHR using a standard HTML form:

<form method="post" action="http://www.example.com:8080/user/delete">

and JavaScript would just be used to submit the form rather than making the request itself.

An easy way to protect your system against CSRF is to check for a custom header such as X-Requested-With or the Origin header. X-Requested-With cannot be sent cross domain without enabling CORS server-side. However, the Synchronizer Token Pattern is still the strongest method of CSRF prevention as this is not subject to flaws in browser plug-ins such as a previous flaw in Flash that allowed headers to be sent that weren't normally possible from a browser.

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