简体   繁体   English

Spring 安全中的条件 CSRF 保护

[英]Conditional CSRF protection in Spring security

We are developing a web API using Spring Boot that should support a React client alongside mobile apps.我们正在使用 Spring Boot 开发一个 Web API,它应该支持 React 客户端和移动应用程序。 For the web side of things we use session management with cookies for authorization and have CSRF enabled, the mobile application will be sending authorization info using bearer tokens.对于 Web 方面,我们使用带有 cookie 的会话管理进行授权并启用 CSRF,移动应用程序将使用不记名令牌发送授权信息。 Now let's say we have an endpoint for modifying user data that will be used both by the React client and the mobile app,is there a way to disable CSRF checks when the mobile application is trying to access it, since the mobile application shouldn't really be vulnerable to CSRF attacks?现在假设我们有一个用于修改用户数据的端点,它将被 React 客户端和移动应用程序使用,有没有办法在移动应用程序尝试访问它时禁用 CSRF 检查,因为移动应用程序不应该真的容易受到 CSRF 攻击吗?

Is there a way to disable CSRF checks when the mobile application is trying to access it有没有办法在移动应用程序尝试访问它时禁用 CSRF 检查

Yes, you can have the mobile version use a different URL.是的,您可以让移动版本使用不同的 URL。 And then you can configure the HttpSecurity bean like this.然后你可以像这样配置HttpSecurity bean。

     http
         .csrf()
             .ignoringAntMatchers("/my-csrf-disabled-uri-for-mobile/**")
             .and()

Does this solve your problem ?这能解决您的问题吗? Tell me in the comments.在评论中告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM