【问题标题】:JQuery modal dialog form that send data over https通过 https 发送数据的 JQuery 模式对话框表单
【发布时间】:2011-05-25 08:45:51
【问题描述】:

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

我不能在我的情况下使用 JSONP,因为登录数据是通过 POST AJAX 请求传递到服务器的。

有什么想法吗?

【问题讨论】:

    标签: javascript jquery ajax jsonp


    【解决方案1】:

    出于好奇,您为什么不从一开始就强制用户访问安全页面?为什么不久前有类似的问题,所以现在,我们强制用户在访问我们的页面后立即使用 https(通过重定向)。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

        请注意,根据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验证过,所以它是有效的。

        如果不是,您可以尝试将您的证书添加到 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]
        

        另见:

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-12-21
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多