如何在 Rails 2.1 中的会话 cookie 上设置 HttpOnly?
我注意到 Rails 2.2(当前是边缘)支持 在会话 cookie 上设置 HttpOnly。
有没有一种方法可以在 Rails 2.1 应用程序上设置它,而无需移动到 Edge/2.2?
I notice that Rails 2.2 (currently edge) supports setting HttpOnly on the session cookie.
Is there a way of setting it on a Rails 2.1 application without moving to edge/2.2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如您所指出的,它不受支持,但您当然可以 monkey-patch Rails做你想做的事。 实际上,在这种情况下,直接修补 Rails 与猴子修补之间的区别非常小,因为当您升级到 2.2 时,两者都会被删除/恢复。
在这两种情况下,您都会将应用的差异视为自己修补 2.1 的指南 - 通过直接应用补丁(对任何 2.1/边缘差异求模),或者通过在环境加载后从您自己的代码重新打开这些类来应用变化。
Well it isn't supported, as you note, but you can of course monkey-patch Rails to do what you want. Actually, the difference between directly patching your Rails v. monkey-patching in this case is very little, as either would be removed/reverted when you upgrade to 2.2.
In both cases you would look at that applied diff as a guide for patching 2.1 yourself - either through applying the patch directly (modulo any 2.1/edge differences), or by reopening those classes from your own code post-environment-loading to apply the changes.
我已经编写了一个猴子补丁,从 Rails 2.2 的补丁中将此支持添加到 Rails 2.1。
除了 Rails 2.1 之外,我没有在任何其他平台上进行过测试,您的体验可能会有所不同!
I have written a monkey patch to add this support to Rails 2.1, from the patch for Rails 2.2.
I've not tested on anything other than Rails 2.1, and your mileage may vary!
在 Cookie 的选项哈希中将
http_only
选项设置为 true:Set the
http_only
option to true in the cookie's options hash: