Code Monkey home page Code Monkey logo

Comments (6)

simasch avatar simasch commented on June 19, 2024 1

Makes sense!
Thank you

from spring-security-samples.

marcusdacoregio avatar marcusdacoregio commented on June 19, 2024

Hi @simasch,

CSRF protection is unnecessary in this scenario because we are using stateless authentication. In other words, we are not dealing with Session Cookies, which are added to the request automatically by the browser, this way avoiding the majority of CSRF exploits. When using an Authorization header, we have to add the header manually using JavaScript.

The HTTP Basic authentication mechanism is also stateless, so no need for CSRF protection either.

from spring-security-samples.

simasch avatar simasch commented on June 19, 2024

Hi @marcusdacoregio
That's what I thought :-)

Will https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/jwt/login/src/main/java/example/RestConfig.java be change accordingly?

from spring-security-samples.

marcusdacoregio avatar marcusdacoregio commented on June 19, 2024

Hi @simasch,

What changes specifically do you expect to see in the configuration?

from spring-security-samples.

simasch avatar simasch commented on June 19, 2024
csrf(AbstractHttpConfigurer::disable)

instead of

csrf((csrf) -> csrf.ignoringRequestMatchers("/token"))

Because it was very confusing that CSRF is configured but not used and now token was generated.

from spring-security-samples.

marcusdacoregio avatar marcusdacoregio commented on June 19, 2024

It is a little tricky for sure, but I think keeping .csrf((csrf) -> csrf.ignoringAntMatchers("/token")) makes sense. If the user happens to add some authentication mechanism that relies on a session cookie they do not have to remember to change the CSRF configuration to now include those endpoints.

It is a recommended secure posture to "deny" everything unless they are authorized, it's the same train of thought as spring-projects/spring-security#11958

from spring-security-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.