Apache反向代理和Wicket CsrfPreventionRequestCycleListener

时间:2017-09-21 06:50:56

标签: 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一起使用吗?

1 个答案:

答案 0 :(得分:1)

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

您可能希望调查网络转储以验证问题。对我来说,apache将请求发送到本地运行的服务(您的情况为http://localhost:8754),而某些请求标头仍在引用公用名https://example.com。这被检测为安全风险,基础服务拒绝了连接。

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

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

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

您可能需要根据您的设置采用(也许您需要纠正多个标头或类似的东西)。我目前无法尝试。