试图在最新的Spring Boot上实现CSRF保护。 互联网上的所有例子都基于用户登录和身份验证,我不需要这些。Spring Boot CSRF
我的网站没有任何要求验证的部分。 我想
1) Rest requests come from within site. No direct request from outside with wget to be allowed.
2) All pages (routes) must be requested from the index page (/)
包括在pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
的安全性依赖 - 定义用户application.properties
(虽然,我并不需要)
- 应用程序创建_csrf.token
。
- 创建的类扩展WebSecurityConfigurerAdapter
与“配置”方法覆盖。
在“配置”中尝试了所有建议的过滤器。它没有工作,最后留下空白。
问题是Wget可以直接获取api页面。 如何防止它?
我敢肯定你不能这样做,你在说什么这里没有一些身份验证,所以你就必须有隐含的授权。我假设您已阅读此http://docs.spring.io/spring-security/site/docs/current/reference/html/csrf.html以确保事情是正确的。在一个应用程序中,我们必须专门禁用非浏览器项目的CSRF,以便它能正常工作。请发布您认为应该工作的最佳配置和类。 GitHub的例子可能是最简单的。 –