Coder Social home page Coder Social logo

Comments (7)

steebchen avatar steebchen commented on June 8, 2024 4

I'm not sure if that's true for what @robojones suggests.
If your API just accepts POST requests, it looks like checking for the origin header seems to be sufficient in 2020 onward; assuming you use it in combination with SameSite=Strict cookies.

Also see:

https://security.stackexchange.com/questions/158045/is-checking-the-referer-and-origin-headers-enough-to-prevent-csrf-provided-that

I'm not saying CSRF is not useful anymore, I just think that SameSite=Strict plus checking the origin header is probably sufficient for most people, and doesn't need any storage on the server.

from csrf.

robojones avatar robojones commented on June 8, 2024 2

@ScottyFillups

why is using SameSite=Strict cookies a requirement? Isn't reading the Origin header enough?

SameSite=Strict on cookies just provides an additional layer of security.
I did look into this and checking the Origin header should be sufficient to prevent CSRF.

Doesn't that mean the Origin header is sent for all cross-domain POSTs over HTTPS? As for GET and HEAD, as long as you ensure those methods don't mutate state, you should be fine to skip the origin check, right?

Yup

from csrf.

philipjscott avatar philipjscott commented on June 8, 2024 1

@steebchen why is using SameSite=Strict cookies a requirement? Isn't reading the Origin header enough?

@elithrar regarding:

which may not be present in all cases, and certainly not for a cross-domain POST over HTTPS

According to https://fetch.spec.whatwg.org/#cors-request,

A CORS request is an HTTP request that includes an Origin header. It cannot be reliably identified as participating in the CORS protocol as the Origin header is also included for all requests whose method is neither GET nor HEAD.

Doesn't that mean the Origin header is sent for all cross-domain POSTs over HTTPS? As for GET and HEAD, as long as you ensure those methods don't mutate state, you should be fine to skip the origin check, right?

from csrf.

elithrar avatar elithrar commented on June 8, 2024

from csrf.

stale avatar stale commented on June 8, 2024

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

from csrf.

robojones avatar robojones commented on June 8, 2024

Thanks for clarifying that @elithrar 👍

from csrf.

stale avatar stale commented on June 8, 2024

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

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.