Apache 反向代理和 Wicket CsrfPreventionRequestCycleListener

标签 apache wildfly wicket csrf reverse-proxy

自整合以来CsrfPreventionRequestCycleListener在我们的 Apache Wicket (7.6.0) 应用程序中,我们在运行 Apache 反向代理后面的应用程序时遇到问题。

我们的配置在 Apache 处终止 SSL,反向代理通过 http 将请求传递到我们的 Wildfly 10 应用程序服务器。这使我们能够卸载 TLS/SSL 等。

但是自从添加 CsrfPreventionRequestCycleListener 后,我们在 server.log 文件中看到以下内容,并且连接被中止:

[org.apache.wicket.protocol.http.CsrfPreventionRequestCycleListener] 
(default task-12) Possible CSRF attack, request URL: 
 http://example.com/example/portal/wicket/page, 
 Origin: https://example.com, action: aborted with error 
 400 Origin does not correspond to request

有问题的 Apache 配置:

<VirtualHost example.com:443>
ServerName example.com
LogLevel debug
SSLEngine On
SSLCertificateFile             /var/example/example.com/signed.crt
SSLCertificateKeyFile          /var/example/example.com/domain.key
SSLCACertificateFile           /var/example/example.com/intermediate.pem

SSLProtocol +TLSv1.2 +TLSv1.1 +TLSv1
SSLOpenSSLConfCmd DHParameters "/usr/local/apache2/1024dhparams.pem"

SSLProxyEngine on
ProxyPass        / http://localhost:8390/ timeout=600
ProxyPassReverse / http://localhost:8390/ timeout=600
ProxyPreserveHost On

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Credentials "true"
Header edit Location ^http(\:\/\/.*)$ https$1

我们找到了一种使用 http2 的解决方案,但更喜欢不使用 http2 的解决方案(原因请参阅 https://http2.pro/doc/Apache)。

使用 http2 的工作 Apache 配置

<VirtualHost example.com:443>
ServerName example.com
LogLevel debug
SSLEngine On
SSLCertificateFile             /var/example/example.com/signed.crt
SSLCertificateKeyFile          /var/example/example.com/domain.key
SSLCACertificateFile           /var/example/example.com/intermediate.pem
SSLProtocol +TLSv1.2 +TLSv1.1 +TLSv1
SSLOpenSSLConfCmd DHParameters "/usr/local/apache2/1024dhparams.pem"

SSLProxyEngine On
ProxyPreserveHost On

# Settings for http2 communication
Protocols h2 http/1.1
ProxyPass   / https://localhost:8754/ timeout=600
ProxyPassReverse    / https://localhost:8754/ timeout=600
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off 

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Credentials "true"
# Header edit Location ^http(\:\/\/.*)$ https$1
</VirtualHost>

任何人都可以帮助我们创建一个有效的 apache 反向代理配置,该配置可以在不使用 http2 模块的情况下与 CsrfPreventionRequestCycleListener 一起使用吗?

最佳答案

我想我在这里遇到了类似的问题,并且刚刚解决了。我认为您现在可能已经解决了您的问题,但也许其他人正在讨论这个话题。

您可能需要查看网络转储来验证问题。对我来说,apache 向本地运行的服务发送请求(您的情况是 http://localhost:8754),而某些请求 header 仍然引用公共(public)名称 https://example.com 。这被检测为安全风险,并且底层服务拒绝连接。

我确定在 apache 中启用了 mod_headers 并添加了该行

RequestHeader edit Referer "https://example.com" "http://localhost:8754"

此后,我的 tcp 转储中不再引用与 example.com 相关的任何内容,并且连接已成功打开。

您可能需要根据您的设置进行采用(也许您需要更正多个 header 或类似的内容)。我现在无法尝试。

关于Apache 反向代理和 Wicket CsrfPreventionRequestCycleListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46337253/

相关文章:

java - Apache FOP : failed to load and use custom font

jakarta-ee - 使用 Wildfly 服务器和基本身份验证避免 401 弹出窗口

java - 读取类的 jar 版本

java - 按按钮关闭 Wicket 模式窗口

java - Wicket - 在延迟加载期间隐藏 AjaxButton 上的元素

regex - Htaccess 重写显示 404 未找到

apache - 如何在apache服务器上运行cgi脚本

linux - 如何编辑@INC 条目以包含模块的新目录

java - 在 Wildfly 8.1 中设置 javax.xml.transform.TransformerFactory

java - Wicket 口更换 "only on component added to parent"