简体   繁体   English

将CSRF令牌传递给客户端应用程序

[英]Passing csrf token to client application

I have web application which is splitted into two separate modules (client and server side). 我有一个Web应用程序,它分为两个单独的模块(客户端和服务器端)。 Server has REST services definded and client call REST services to get data. 服务器定义了REST服务,客户端调用了REST服务来获取数据。 I want to have server protected against CSRF attacks. 我想让服务器免受CSRF攻击。 So any client POST/PUT/DELETE requires to pass csrf token in header and token value should be equal to csrfToken saved in session. 因此,任何客户端POST / PUT / DELETE都要求在标头中传递csrf令牌,并且令牌值应等于会话中保存的csrfToken。 My question is since csrf token is generated by the server how can client app obtain token value? 我的问题是,由于CSRF令牌是由服务器生成的,客户端应用程序如何获取令牌值?

Should client after login send GET request, server generates csrf token store it as session attribute and send it back to client in response or is any better solution? 登录后客户端应该发送GET请求,服务器生成csrf令牌并将其存储为会话属性,然后作为响应将其发送回客户端吗,还是有更好的解决方案?

its upto you what you want if you want to csrf token client side or not? 由您决定是否要使用csrf令牌客户端吗?

csrf token always created on landing page or first ajax request of user at serverside backend black box logic... csrf令牌始终在服务器端后端黑匣子逻辑上的用户的着陆页或用户的第一个ajax请求上创建...

client side means if jsp then you can easy write code because jsp is in serverside and all its benifits as programer we know... 客户端意味着如果使用jsp,那么您就可以轻松编写代码,因为jsp在服务器端,并且它作为程序员知道它的所有优点。

if in applicaiton we use js or js based framework [like extjs,dojo took kit ,angularjs ,yui or any other] and our view is as .html file then i feel we go with landing page .... 如果在应用程序中,我们使用基于js或js的框架(例如extjs,dojo套件,angularjs,yui或其他任何文件),并且我们的视图为.html文件,那么我觉得我们可以使用着陆页....

landing page means first page ... or if we use ajax then first ajax request by user to server when user hit to our server... 登陆页面表示首页...或者如果我们使用ajax,则当用户点击我们的服务器时,用户向服务器请求的第一个ajax ...

by first ajax request or landing page you can generate one token and save in session as csrf token after that whole session of that user you have to check csrf token by writing filter ... 通过第一个ajax请求或登录页面,您可以生成一个令牌并将该会话保存为csrf令牌,在该用户的整个会话之后,您必须通过编写过滤器来检查csrf令牌...

in filter must check user session is not null and user is login user and permission base on your application and session have csrf token... 在过滤器中必须检查用户会话不为空,并且用户是登录用户,并且基于您的应用程序和会话的权限具有csrf令牌...

so as every new user must have to pass with your landing page[login page] and got one session at server side so any bogus request is not allow and one security layer you have 因此,由于每个新用户都必须通过您的登录页面[登录页面]并在服务器端进行一次会话,因此任何虚假请求都不允许,并且您拥有一个安全层

Enjoy :) 请享用 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM