iframe 为我的 Domino XPages 解决方案提供服务时出现问题(使用 Nginx 代理)添加 JS 代码以使用 http 进行重定向(而网站是 https)

Problem with iframe serving my Domino XPages solution (with Nginx proxy) adds JS code to redirect using http (while site is https)

如果这有点冗长,请提前道歉 - 但我已经深入研究了很多,所以我想提供我所知道的:-)

我有一个为客户提供的解决方案(在 IBM XPages 中开发),例如通过 iframe。我们现在开始发现 iframe 不加载内容的问题。这发生在 Safari 和 Chrome 私有 session 中。原因是这个 Javascript 被注入到 iframe 页面的 header 中:

<head>
<script type="text/javascript">if(!navigator.cookieEnabled)window.location.href="http://fangstjournalen.dtu.dk/fangst.nsf/iframe.xsp?open\u0026assoc=49F1767931B31CD0C1258398007953C0\u0026type=1\u0026SessionID=77610D163AE659EC8C2C63FAF5E8BBA05E8C120D";
</script>
</head>

它自己的 iframe 如下所示:

<iframe src="https://fangstjournalen.dtu.dk/fangst.nsf/iframe.xsp?open&amp;assoc=02F2DD0AA9133BDCC1258618004A6B48&amp;type=1" width="100%" height="2100"></iframe>

如您所见,iframe link 与 Javascript 中的存在差异(使用 http 而不是 https).

在浏览器的控制台中,我看到这条消息:

[blocked] The page at https://fangstjournalen.dtu.dk/fangst.nsf/iframe.xsp?open&assoc=49F1767931B31CD0C1258398007953C0&type=1 was not allowed to display insecure content from http://fangstjournalen.dtu.dk/fangst.nsf/iframe.xsp?open&assoc=49F1767931B31CD0C1258398007953C0&type=1&SessionID=9C21D5AF363C262E3CC37D0CDFBDFBCB35528ECC.

这显然是一个合理的理由。

但什么是添加“错误”的内容 - 我该如何解决这个问题?

我们的测试系统并非 100% 等同于我们的生产系统。生产中的 Nginx 在同一台服务器上(测试中的不同服务器),在测试中我们使用 LetsEncrypt 进行 SSL - 但在生产中我们获得了证书。从托管中心。我们仅在生产环境中设置了 ssl_session_cache - 以及其他一些(我认为)细微差别...

生产环境中 nginx 服务器的配置如下所示(省略了其他服务器的一些细节):

server {
        listen 443;
        server_name fangstjournalen.dtu.dk;
 
        client_max_body_size 25m;
 
        ssl on;
        ssl_certificate /etc/nginx/ssl/fangstjournalen.dtu.dk.pem;
        ssl_certificate_key /etc/nginx/ssl/fangstjournalen.dtu.dk.key;
        ssl_session_cache shared:le_nginx_SSL:1m;
        ssl_session_timeout 1440m;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "ECDHE-....";
        ssl_stapling on;
        ssl_stapling_verify on;
        add_header Strict-Transport-Security max-age=15768000;

        # 2020.05.20/Jda - added Sync Gateway
        # Use a specific url pattern to identify sync requests - and remove that part before redirecting to the db server
        location /_sync {
              rewrite                 /_sync/(.*) /  break;
              proxy_pass              http://sync_gateway;
              :
              :
        }

        # 2019.11.04/Jda - Added keepalive_timeout, proxy_read_timeout: 600 --> 900
        # 2020.08.12/Jda - Added SameSite=none; Secure to cookies...
        location / {
                proxy_pass              http://fangstjournalen.dtu.dk:8088;
                proxy_redirect          off;
                proxy_buffering         off;
                proxy_http_version      1.1;
                keepalive_timeout       720s;
                proxy_read_timeout      900s;
                proxy_set_header        X-Forwarded-Port     8088;
                proxy_set_header        X-Forwarded-Host     $host;
                proxy_set_header        X-Forwarded-Server   $host;
                proxy_set_header        X-Real-IP            $remote_addr;
                proxy_set_header        Host                 $host;
                proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
                proxy_set_header        X-Forwarded-Proto    $scheme;
                proxy_set_header        $WSRA                $remote_addr;
                proxy_set_header        $WSRH                $remote_addr;
                proxy_set_header        $WSSN                $host;
                proxy_set_header        $WSIS                True;
                proxy_cookie_path       /                    "/; SameSite=none; Secure";
        }
}

非常感谢任何想法!

提前致谢;-)

/约翰

编辑: 测试页的 link 已被删除,因为该页面现在也已被删除:-)

您可以尝试使用sub_filter模块改写内容:

sub_filter_once on;
sub_filter_types text/html;
sub_filter '<script type="text/javascript">if(!navigator.cookieEnabled)window.location.href="http://' '<script type="text/javascript">if(!navigator.cookieEnabled)window.location.href="https://';

我遇到了同样的问题。使用反编译器,我在代码中找到了添加的地方。 您可以在 ExternalContextEx 上设置 属性 以避免添加脚本标签。

我在我的应用程序的自定义 ViewHandler(重载 createView 方法)中执行此操作,但您也可以在 XPage 的 beforePageLoad 事件中执行此操作。

在我的代码中,我仅在未设置 SessionID-cookie 时覆盖它,以防它执行我不知道的其他操作。到目前为止没有任何问题。

HttpServletRequest httpServletRequest = (HttpServletRequest) facesContext.getExternalContext().getRequest();
if( !httpServletRequest.isRequestedSessionIdFromCookie() ) {
    ExternalContextEx externalContext = (ExternalContextEx) facesContext.getExternalContext();
    externalContext.setDonotEncodeUrl( false );
}