Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.openrewrite.java.security.spring.CsrfProtection generates deprecated WebSecurityConfigurerAdapter #119

Open
philippe-granet opened this issue Dec 24, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@philippe-granet
Copy link

When using org.openrewrite.java.security:OwaspTopTen recipe, it call org.openrewrite.java.security.spring.CsrfProtection recipe that use deprecated WebSecurityConfigurerAdapter Spring class.
When -Werror is activated on Java compiler, it break build.

[WARNING] /builds/src/main/java/.../SecurityConfig.java:[9,30] org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter in org.springframework.security.config.annotation.web.configuration has been deprecated
...
[ERROR] COMPILATION ERROR : 
[ERROR] /builds/src/main/java/.../SecurityConfig.java: warnings found and -Werror specified

Documentation for migration: https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter/

In Spring Security 5.7.0-M2 we deprecated the WebSecurityConfigurerAdapter, as we encourage users to move towards a component-based security configuration.

@philippe-granet philippe-granet added the bug Something isn't working label Dec 24, 2023
@timtebeek
Copy link
Contributor

Hi @philippe-granet thanks for reporting your concern! Am I correct in deducing that you ran OwaspTopTen, which ran CsrfProtection, which generated a fully new SecurityConfig class that uses the outdated WebSecurityConfigurerAdapter?
Did it at least correctly fix the security issue in your case?

It seems like GenerateWebSecurityConfigurerAdapter indeed predates the deprecation by about half a year. We do separately have a recipe to move you away from WebSecurityConfigurerAdapter: https://docs.openrewrite.org/recipes/java/spring/security5/websecurityconfigureradapter

The way I see it now we have a couple of options.

  1. Change the OwaspA10 recipeList use of CsrfProtection to add onlyIfSecurityConfig = true.
    This would for the moment at least stop it from adding outdated classes, but would like to applications without any security config not getting patched.

    type: specs.openrewrite.org/v1beta/recipe
    name: org.openrewrite.java.security.OwaspA10
    displayName: Remediate OWASP A10:2021 Server-side request forgery (SSRF)
    description: >
    OWASP [A10:2021](https://owasp.org/Top10/A10_2021-Server-Side_Request_Forgery_%28SSRF%29/) Server-Side Request Forgery (SSRF)
    recipeList:
    - org.openrewrite.java.security.spring.CsrfProtection

  2. Follow up any iuse of GenerateWebSecurityConfigurerAdapter with org.openrewrite.java.spring.security5.WebSecurityConfigurerAdapter to upgrade the generated class to the newer version.
    Some care would be needed to ensure we are at least on Spring Security 5.7+, or the configuration would not be picked up.

  3. Alter GenerateWebSecurityConfigurerAdapter to look for and correctly insert either WebSecurityConfigurerAdapter or a SecurityConfiguration that does not extend WebSecurityConfigurerAdapter.

All of those issues would require some work. Which would suit your particular situation best?

@timtebeek timtebeek moved this to Backlog in OpenRewrite Dec 24, 2023
@timtebeek timtebeek changed the title org.openrewrite.java.security.spring.CsrfProtection - Deprecated WebSecurityConfigurerAdapter org.openrewrite.java.security.spring.CsrfProtection generates deprecated WebSecurityConfigurerAdapter Dec 24, 2023
@philippe-granet
Copy link
Author

Thanks for your reply, solutions 2 or 3 suit me.

@timtebeek timtebeek self-assigned this Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants