Giter Club home page Giter Club logo

Comments (6)

stephenmathieson avatar stephenmathieson commented on May 4, 2024 1

Yes, the token is set whether or not you send it. This library asserts that the token was provided by the user.

It's clear that a "real" example is necessary here. I'll see if I can throw something together in shortly.

from csrf.

joegalley avatar joegalley commented on May 4, 2024

@stephenmathieson Awesome, thank you

from csrf.

joegalley avatar joegalley commented on May 4, 2024

When you say this library asserts that the token "was provided by the user", this validation is happening when you compare the submitted csrf token to the ctx.session.secret, right? So is a new csrf token generated for every context, and validated against the session secret?

If this is the case, I don't see why we need to store the token client-side (in a hidden form field)

from csrf.

stephenmathieson avatar stephenmathieson commented on May 4, 2024

The token is salted with the secret. The token is unique per request/session. You need to pass the token to your client so it can send it back. The token validates that the user is who the user is claiming to be.

I think there's a misunderstanding of what this module helps you do. Are you familiar with what CSRF is? A good read/silly read is https://dev.to/rtfeldman/defense-against-the-dark-arts-csrf-attacks. I think it does a pretty good job at explaining what CSRF is/why you should protect against it.

from csrf.

joegalley avatar joegalley commented on May 4, 2024

I understand what CSRF protection does, I think I'm confused as to how long one particular csrf token is supposed to last. Should I be sending a new token with every request, or could I save a token when first loading the site, and keep sending that token back with each request (for as long as the user's session lasts)?

from csrf.

stephenmathieson avatar stephenmathieson commented on May 4, 2024

The token is valid for the duration of the user’s session in SPAs and for each request otherwise. Basically any time we can create a new token, we will.

from csrf.

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.