Rails 3.1 强制常规 HTTP
之前,我一直在使用 ssl_requirement 来对哪些页面通过 ssl 提供服务以及哪些页面通过 ssl 进行精细控制。通过纯 http 提供服务。
根据 ssl_requirement 自己的 wiki,它已被 Rails 3.1 的 强制 SSL。然而,情况似乎并非如此。 Force SSL 似乎没有提供相反方向的选项,没有办法强制页面通过常规 http 发送。
强制页面以纯 http 显示的正确 Rails 3.1 方法是什么? Force SSL 真的能取代 ssl_requirement 吗?
Previously, I had been using ssl_requirement to give us fine grained control over which pages were served over ssl and which were served over plain http.
According to the ssl_requirement's own wiki, it has been superseded by rails 3.1's Force SSL. However this does not seem to be the case. Force SSL doesn't seem to expose an option to go in the opposite direction, there is no way to force a page to sent via regular http.
What is the correct Rails 3.1 way to force a page to be displayed in plain http? Does Force SSL truly supersede ssl_requirement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
正义所说。有些人强烈推荐使用 SSL 浏览所有内容。现在,监听非 SSL 会话已经变得轻而易举,因此您应该竭尽全力为想要使用它的人提供便利。
然而。
使用 before_filter 应该很容易完成:
What Justice said. Some people feel strongly about browsing with SSL for everything. It's now trivial to snoop non-SSL sessions, so you should go out of your way to accomodate people who want to use it.
However.
It should be fairly easy to accomplish using a before_filter:
Force SSL 的代码非常容易阅读。
https://github.com/rails/rails /blob/master/actionpack/lib/action_controller/metal/force_ssl.rb
它似乎没有做相反的事情并强制使用http。它提供了 only 和 except 选项来控制哪些操作和控制器需要 SSL,但没有提供强制使用 HTTP 而不是 https 的方法。
The code for Force SSL is pretty easy to read.
https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/force_ssl.rb
It doesn't seem to do the reverse and force http to be used. It provides the only and except options to control which actions and controllers SSL is to be required for, but doesn't provide a way to force HTTP to be used instead of https.
要以与
force_ssl
完全相同的方式使用force_non_ssl
,请检查此 Rails 问题:https://gist.github.com/joost/6989118接受以下选项:
To use
force_non_ssl
the exact same way asforce_ssl
check this Rails Concern: https://gist.github.com/joost/6989118Accepts options like:
我将 joost 的代码简化为我需要的一切。谢谢乔斯特
I simplified joost's code to all I needed. Thanks joost
对于那些像我一样只需要在本地计算机上短时间禁用整个应用程序的
force_ssl
行为的人,您可以简单地在您的 ApplicationController 中执行此操作:只需确保不要将其提交到您的代码库。
For those who just need to disable
force_ssl
behaviour on their whole app for a short time on local machine like me, you can simply do this in your ApplicationController:Just make sure not to commit it to your codebase.
为什么您想要强制使用 HTTP 而不是 HTTPS?
我们中的许多人到处都使用 SSL 进行浏览。请不要仅仅因为您不喜欢帮助我们解决自身安全问题而将我们其他人置于危险之中。
对于我们大多数人来说,安全性很重要,即使我们大多数人不了解其重要性或不知道如何获得它。对于我们中的一些人来说,安全是生死攸关的。
某些页面必须通过 SSL 提供服务。尽管在我看来,如果您网站的任何部分需要通过 SSL 提供服务,那么整个网站都需要它(MITM 可以将 SSL 页面的链接更改为它在非 SSL 页面上呈现以指向 MITM 控制的非 SSL 代理)。 从来没有任何页面需要使用 SSL 来提供服务。
Why would you ever want to force HTTP over HTTPS?
A lot of us out here browse with SSL everywhere. Please don't put the rest of us at risk simply because you don't like helping us out with our own security.
For most of us, security is important, even if most of us don't understand its importance or know how to obtain it. For some of us, security is life and death critical.
Some pages must be served over SSL. Although, in my view, if any part of your site requires being served over SSL, then the entire site requires it (a MITM can change the link to the SSL page as it is rendered on the non-SSL page to point to a non-SSL proxy that the MITM controls). No page ever requires being served without SSL.