我已经设置了Web应用程序以通过在faces-config,protected-views中列出各个页面来防御CSRF。
这在本地运行时效果很好,但是在部署到服务器后,我在打开页面链接时最终遇到以下错误:
javax.faces.application.ProtectedViewException: JSF1099: Referer [sic] header value http://[redacted]/finance/commitmentregister/search.xhtml?javax.faces.Token=1534344211116 does not appear to be a protected view. Preventing display of viewId /finance/commitmentregister/view.xhtml
at com.sun.faces.lifecycle.RestoreViewPhase.maybeTakeProtectedViewAction(Unknown Source)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(Unknown Source)
at com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(Unknown Source)
at com.sun.faces.lifecycle.LifecycleImpl.execute(Unknown Source)
我们正在本地和测试服务器上运行Apache Tomcat 7。
编辑:
我注意到链接上生成的网址看起来像这样:
http://.../page.xhtml?token=123&p=4
其中令牌是CSRF javax.faces.Token,而p是发送的url参数。
错误消息显示带有令牌但没有p的URL。就像期望带有令牌的url是faces-config中列出的受保护的页面url。
也就是说,faces-config具有:
<protected-views>
<url-pattern>/page.xhtml</url-pattern>
</protected-views>
但是期望page.xhtml?token = 123
进一步编辑:
我们刚刚注意到只有在新标签页中打开页面时才会发生此错误。通过使用target =“ _ blank”属性生成的链接。将网址复制到剪贴板中并将其粘贴到新的标签页地址栏中,即可正确加载页面。
答案 0 :(得分:0)
注意到它仅在新选项卡上中断,这给了我更多信息来研究问题。
将此内容添加到链接即可对其进行修复:
rel="noopener noreferrer"