You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* cookie attribute options, closes#25
* Make test more stable in face of code changes
* Configuring the cookie docs, refs #25
* Tests for cookie options, closes#25
---------
Co-authored-by: Kevin Abraham <[email protected]>
Co-authored-by: Simon Willison <[email protected]>
The middleware can be configured with several options to control how the CSRF cookie is set:
70
+
71
+
```python
72
+
app = asgi_csrf(
73
+
app,
74
+
signing_secret="secret-goes-here",
75
+
cookie_name="csrftoken",
76
+
cookie_path="/",
77
+
cookie_domain=None,
78
+
cookie_secure=False,
79
+
cookie_samesite="Lax"
80
+
)
81
+
```
82
+
83
+
-`cookie_name`: The name of the cookie to set. Defaults to `"csrftoken"`.
84
+
-`cookie_path`: The path for which the cookie is valid. Defaults to `"/"`, meaning the cookie is valid for the entire domain.
85
+
-`cookie_domain`: The domain for which the cookie is valid. Defaults to `None`, which means the cookie will only be valid for the current domain.
86
+
-`cookie_secure`: If set to `True`, the cookie will only be sent over HTTPS connections. Defaults to `False`.
87
+
-`cookie_samesite`: Controls how the cookie is sent with cross-site requests. Can be set to `"Strict"`, `"Lax"`, or `"None"`. Defaults to `"Lax"`.
88
+
67
89
## Other cases that skip CSRF protection
68
90
69
91
If the request includes an `Authorization: Bearer ...` header, commonly used by OAuth and JWT authentication, the request will not be required to include a CSRF token. This is because browsers cannot send those headers in a context that can be abused.
@@ -101,7 +123,7 @@ app = asgi_csrf(
101
123
)
102
124
```
103
125
104
-
###send_csrf_failed
126
+
##Custom errors with send_csrf_failed
105
127
106
128
By default, when a CSRF token is missing or invalid, the middleware will return a 403 Forbidden response page with a short error message.
0 commit comments