通过https发送数据的JQuery模式对话框表单

时间:2010-12-14 15:43:16

标签: javascript jquery ajax jsonp

我已经在使用模态登录对话框了。问题是,如果通过http加载原始页面,我仍然希望通过https将凭据传递给服务器。当然,我想尽可能少地重写工作代码。

我无法使用JSONP,因为登录数据是通过POST AJAX请求传递给服务器的。

有什么想法吗?

3 个答案:

答案 0 :(得分:2)

同源策略使这不可能(至少在不支持跨域XHR的浏览器中,这已经足够了。)

(并且由于主机文档是通过HTTP提供的,因此它会受到网络上的拦截和更改,即使通过SSL传输也会使数据易受攻击)

答案 1 :(得分:0)

出于好奇,为什么不强迫用户开始使用安全页面?为什么会有类似的问题,所以现在,我们会在用户点击页面时强制用户进行https(通过重定向)。

答案 2 :(得分:0)

请注意,根据Same-origin policy,这应该是不可能的,因为您尝试将非安全凭据发布到安全页面。如果登录着陆页未使用SSL,则攻击者可以在将页面发送给用户时修改页面并更改表单提交位置或插入JavaScript,以便在键入时窃取用户名/密码。因此登录登录页面必须使用SSL。

为了说明这一点,下表概述了针对URL" http://www.example.com/dir/page.html"进行检查的典型结果。

Compared URL                              Outcome   Reason
http://www.example.com/dir/page2.html     Success   Same protocol and host
http://www.example.com/dir2/other.html    Success   Same protocol and host
http://u:pass@www.example.com/x/o.html    Success   Same protocol and host
http://www.example.com:81/dir/other.html  Failure   Same protocol and host but different port
https://www.example.com/dir/other.html    Failure   Different protocol
http://en.example.com/dir/other.html      Failure   Different host
http://example.com/dir/other.html         Failure   Different host (exact match required)
http://v2.www.example.com/dir/other.html  Failure   Different host (exact match required)
http://www.example.com:80/dir/other.html  Depends   Port explicit. Depends on implementation in browser.

与其他浏览器不同,Internet Explorer在原点计算中不包含端口,使用安全区域。


如何放宽同源政策

在某些情况下,同源政策限制性太强,对使用多个子域的大型网站造成问题。以下是放松它的四种技巧:


如果你真的该怎么做,这是可能的,但你需要确保public key certificate已经certification authority验证了你的网站的Is posting from HTTP to HTTPS a bad practice?,因此它是有效的。

如果不是,您可以尝试将证书添加到Web浏览器的白名单中。或尝试使用不同的网络浏览器。

另外,您可以确保用户在显示登录表单时始终位于安全页面上,或者禁用登录表单的模式表单。

其他解决方法包括通过将非安全流量转发到ssl来添加重写规则,例如

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  # Force <front> to ssl for modal use of secure log in module.
  RewriteRule http://www.example.net/^$ https://www.example.net [R=301,L]

另见:

相关问题