HTTP 站点通过 HTTPS 提供 JSONP API?
鉴于 FireSheep 获得的所有报道,我一直在尝试找出平衡我管理的某些网站(例如博客网站、带有用户贡献评论的杂志网站)的 HTTP / HTTPS 使用情况的最佳实践。
对我来说,如果用户登录,通过 HTTPS 传送所有页面就太过分了。如果页面是公共的(例如博客),那么加密公共页面就没有什么意义了。我想做的就是通过 HTTP 通道嗅探 cookie 来防止会话劫持。
因此,一种计划是:
- 登录表单通过 HTTPS
- 发出两个 cookie: 一个 cookie 是“公共”的,并标识该用户的只读方面(例如“欢迎鲍勃!”)。第二个 cookie 是私有的并且“仅限 HTTPS”。这是每当用户进行更改(例如添加评论、删除帖子)时都会验证的 cookie。
这意味着所有“更改”请求都必须通过 HTTPS 发出。
我们大量使用 AJAX。事实上,许多评论表单都使用 AJAX 来发布内容。
显然,我无法直接使用 AJAX 将内容从 HTTP 前端发布到 HTTPS 后端。
我的问题是:我可以使用脚本注入(我认为这通常称为“JSONP”?)来访问 API 吗?因此,在这种情况下,将有一个 HTTP 公共页面,通过注入通过 HTTPS 访问的脚本将数据发送到私有后端(以便私有 cookie 在请求中可见)。
HTTP 页面中可以包含 HTTPS 内容吗?我知道您会收到相反的警告,但我认为 HTTP 内的 HTTPS 并不是安全漏洞。
那行得通吗?它似乎可以在 chrome 和 FF 中工作,但 IE 会是最糟糕的!
Given all the coverage FireSheep has been getting, I have been trying to work out the best practices for balancing HTTP / HTTPS usage for some sites I manage (e.g. blogging sites, magazine sites with user contributed comments).
To me, its over kill to deliver all pages over HTTPS if the user is logged in. If a page is public (e.g. a blog) there is little point encrypting the public page. All I want to do is prevent session hijacking by sniffing cookies over HTTP channels.
So, one plan is:
- Login form is over HTTPS
- Issue two cookies: One cookie is 'public' and identifies there user for read only aspects (e.g. 'welcome bob!'). The second cookie is private and 'HTTPS only'. This is the cookie that is verified whenever the user makes a change (e.g. adds a comment, deletes a post).
This means that all 'changing' requests must be issued over HTTPS.
We use a lot of AJAX. Indeed, many comment forms use AJAX to post the content.
Obviously, I cant use AJAX directly to post content to a HTTPS backend from a HTTP frontend.
My question is: Can I use script injection (I think this is commonly called 'JSONP'?) to access the API? So in this case there would be a HTTP public page that sends data to the private backend by injecting a script accessed via HTTPS (so that the private cookie is visible in the request).
Can you have HTTPS content inside a HTTP page? I know you get warnings the other way around, but I figure that HTTPS inside HTTP is not a security breach.
Would that work? It seems to work in chrome and FF, but its IE that would be the party pooper!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
另一种方法是使用一个指向 https 页面的 iframe,该页面可以通过 https(与 https 上的 iframe 相同的域)对服务器进行各种类型(GET、POST、PUT 等)Ajax 调用。一旦响应返回到 iframe 内,您就可以使用 HTML5 postMessage API 将消息发布回主窗口。
这适用于除 IE <= 7 之外的所有现代浏览器,您必须诉诸 JSONP 或使用 Flash 进行跨域通信。
Another way is to have an iframe which points to a https page that can make all kinds (GET, POST, PUT etc) of Ajax calls to the server over https (same domain as iframe is on https too). Once the response is back inside the iframe, you can post a message back to the main window using HTML5 postMessage API.
This works in all modern browsers except IE <= 7 for which you'll have to either resort to JSONP or cross domain communication using Flash.
JSONP 的问题在于您只能将其用于 GET。
在常规 HTTP 页面中包含 HTTPS 内容不会在任何浏览器中引发任何警报。
但是,我认为 JSONP 不会帮助您解决这个问题。使用 GET 来发布内容和修改数据是一个非常糟糕的主意,并且容易受到其他攻击,例如 CSFR
The problem with JSONP is that you can only use it for GETs.
Including HTTPS content inside a regular HTTP page won't raise any alerts in any browser.
However, I don't think JSONP will help you out of this one. Using GETs to post content and modify data is a very bad idea, and prone to other attacks like CSFR