Giter Club home page Giter Club logo

Comments (8)

simonw avatar simonw commented on June 6, 2024

Tricky thing is how this should interact with always_protect={set of paths}.

from asgi-csrf.

simonw avatar simonw commented on June 6, 2024

always_protect= solves a different case: it lets you specify that certain paths such as /login should ALWAYS be CSRF-protected even if they would not be otherwise (in that case to avoid login CSRF).

from asgi-csrf.

simonw avatar simonw commented on June 6, 2024

Relevant code (this is the only place that deals with always_protect at the moment):

asgi-csrf/asgi_csrf.py

Lines 118 to 130 in bb7178d

# If no cookies, skip check UNLESS path is in always_protect
if not headers.get(b"cookie"):
if always_protect is None or scope["path"] not in always_protect:
await app(scope, receive, wrapped_send)
return
# Authorization: Bearer skips CSRF check
if (
headers.get(b"authorization", b"")
.decode("latin-1")
.startswith("Bearer ")
):
await app(scope, receive, wrapped_send)
return

from asgi-csrf.

simonw avatar simonw commented on June 6, 2024

Maybe I'll go with skip_protection=lambda scope: ... instead. That makes it a bit more clear what this optional mechanism is intended to do.

Potential names for that keyword argument:

  • skip_protection=lambda scope: ..
  • skip_protection_if=lambda scope: ..
  • skip_protection_callback=lambda scope: ..
  • skip_callback=
  • skip_if_scope=
  • skip_protection_if_scope=

from asgi-csrf.

simonw avatar simonw commented on June 6, 2024

I wish always_protect= was called always_protect_paths=.

from asgi-csrf.

simonw avatar simonw commented on June 6, 2024

skip_callback= is shorter, but is it as clear?

from asgi-csrf.

simonw avatar simonw commented on June 6, 2024

I quite like skip_if_scope=.

from asgi-csrf.

simonw avatar simonw commented on June 6, 2024

I've been using this successfully in Datasette plugins for a while now.

from asgi-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.