使用 GWT 的 RequestFactory 时防止 CSRF
我刚刚开始将 GWT-RPC 代码移植到新的 RequestFactory
机制。
为了防止跨站点请求伪造 (CSRF),我的 GWT-RPC 代码获取了存储在 cookie 中的会话 ID,并将其包含在请求的有效负载中。 RequestFactory
可以实现这一点吗?
据我所知,有四种强制定位器方法,包括 findEntity(id_type id)
;所以我在想:哦,天哪:我该把我的会话 ID 放在哪里?
I've just started porting my GWT-RPC code to the new RequestFactory
mechanism.
In order to prevent cross-site request forgery (CSRF), my GWT-RPC code grabbed the session id that had been stored in a cookie, and included it in the payload of the request. Is that possible with RequestFactory
?
I understand that there are four mandatory Locator methods, including findEntity(id_type id)
; so I'm thinking: oh dear: where do I put my session id?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您将扩展
DefaultRequestTransport
以将令牌添加到请求中(例如自定义标头,但您也可以将其添加到请求正文中)并将其传递给initRequestFactory
的 code>。在服务器端,您可以使用 servlet 过滤器,也可以扩展RequestFactoryServlet
来在处理 RequestFactory 请求之前处理令牌。您可以在此处自由定义自己的“协议”:例如返回 403 或 401 状态(或其他状态),然后在RequestTransport
中对其进行处理,以将结果传达给您的应用。Generally, you'll extend
DefaultRequestTransport
to add the token to the request (such as a custom header, but you could also add it to the request body) and pass it to theinit
of yourRequestFactory
. On the server-side, you'll either use a servlet filter or you'll extendRequestFactoryServlet
to process the token before even processing the RequestFactory request. You're free to define your own "protocol" here: e.g. returning a 403 or 401 status (or whatever) and then process it in theRequestTransport
to communicate the result to your app.