首页 文章

Apache反向代理和Wicket CsrfPreventionRequestCycleListener

提问于
浏览
3

由于将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一起使用吗?

1 回答

  • 1

    我想我在这里遇到了类似的问题并且刚才解决了 . 我想你现在可能已经解决了你的问题,但也许其他任何人都在讨论这个话题 .

    您可能希望查看网络转储以验证问题 . 对我来说,apache发送请求到本地运行的服务(你的情况是 http://localhost:8754 ),而一些请求 Headers 仍然引用公共名称 https://example.com . 这被检测为安全风险,并且基础服务拒绝连接 .

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

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

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

    您可能需要根据您的设置采用(可能需要更正多个标头或类似的东西) . 我现在无法尝试 .

相关问题