Giter Site home page Giter Site logo

Comments (3)

tomchristie avatar tomchristie commented on May 3, 2024

Seriously thanks so much for this one. The API stuff I have at the moment is un-authenticated so I woulda never have had the same hiccup with that. Yup totally right about referencing the AJAX CSRF docs. The error message stuff is a little more involved that in might seem at first sight seeing as there might be 0, 1 or many authenticators, and an authentication on one, many or all of the authenticators may not mean that the user doesn't have permission, plus the failed authentication responses might be either 401's or 403's, including the WWW-Authenticate header in the case of the 401's. Anyhoo, some of this has been in the (far) back of my head for a while, so I might try to pick up a bit of it this weekend.

from django-rest-framework.

tomchristie avatar tomchristie commented on May 3, 2024

Question is - what behavior do we expect here. Other authentication classes may also be present on the resource, and just because a request isn't CSRF validated it doesn't mean one of those other class might authenticate the request.

I guess the right thing to do is probably to check if request.user is authenticated, and throw a "CSRF failed!" response if it is.

from django-rest-framework.

dbrgn avatar dbrgn commented on May 3, 2024

I'm not sure about the inner workings of the CSRF validation and your code, but as long as a CSRF validation error (and only such an error) results in the correct error message, that would be OK for me :)

from django-rest-framework.

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.