Spring 安全中的条件 CSRF 保护
Conditional CSRF protection in Spring security
我们正在使用 Spring Boot 开发 Web API,它应该支持 React 客户端和移动应用程序。对于 Web 端,我们使用会话管理和 cookie 进行授权并启用 CSRF,移动应用程序将使用不记名令牌发送授权信息。现在假设我们有一个端点用于修改将由 React 客户端和移动应用程序同时使用的用户数据,有没有办法在移动应用程序尝试访问它时禁用 CSRF 检查,因为移动应用程序不应该真的容易受到 CSRF 攻击吗?
Is there a way to disable CSRF checks when the mobile application is trying to access it
是的,您可以让移动版使用不同的 URL。
然后你可以像这样配置 HttpSecurity bean。
http
.csrf()
.ignoringAntMatchers("/my-csrf-disabled-uri-for-mobile/**")
.and()
这是否解决了您的问题?评论告诉我吧。
我们正在使用 Spring Boot 开发 Web API,它应该支持 React 客户端和移动应用程序。对于 Web 端,我们使用会话管理和 cookie 进行授权并启用 CSRF,移动应用程序将使用不记名令牌发送授权信息。现在假设我们有一个端点用于修改将由 React 客户端和移动应用程序同时使用的用户数据,有没有办法在移动应用程序尝试访问它时禁用 CSRF 检查,因为移动应用程序不应该真的容易受到 CSRF 攻击吗?
Is there a way to disable CSRF checks when the mobile application is trying to access it
是的,您可以让移动版使用不同的 URL。 然后你可以像这样配置 HttpSecurity bean。
http
.csrf()
.ignoringAntMatchers("/my-csrf-disabled-uri-for-mobile/**")
.and()
这是否解决了您的问题?评论告诉我吧。