Works with all modern web-browsers, which support SameSite cookies.
(Firefox 60, Google Chrome 51, Opera 39 and later)
Checks request for CSRF token.
If CSRF is absent or invalid:
If it's a get request - installs new token in cookie and redirects to same page.
In other cases - raises 403 exception (forbidden).
Requires some session middleware to be installed.
That session plugin must use such interface:
```python
request['session'].get('variable') or request['session']['variable']
request['session']['variable'] = 4
```
For example, this ones will fit:
- 'sanic_session' (https://github.com/subyraman/sanic_session);
- 'sanic_session' (https://github.com/vlad1777d/sanic_session)
(fork of previous, more convenient middleware installation,
can be used without package installation);
## Example
A simple example:
```python
from sanic import Sanic
from sanic.response import text
import sanic_session
import sanic_csrf
app = Sanic()
sanic_session.install_middleware(app, 'InMemorySessionInterface')
sanic_csrf.install_middleware(app)
@app.route("/")
async def index(request):
# interact with the session like a normal dict
if not request['session'].get('foo'):
request['session']['foo'] = 0
request['session']['foo'] += 1
return text(request['session']['foo'])
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, debug=True)
```
Metadata
Release files for sanic_csrf 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sanic_csrf-0.1.3.tar.gz | 2.3 kB | Without provenance | Details for sanic_csrf-0.1.3.tar.gz |
Release files / sanic_csrf-0.1.3.tar.gz
| Download URL | sanic_csrf-0.1.3.tar.gz |
|---|---|
| Size | 2.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba4d52f5de664e67ed21e0a59c1980e339d90a6b5412b522d6e5145ffecc90dd
|
|
BLAKE2b-256 checksum How to use checksums |
bd6626367389ad7b0b7197b075195a061317c6505f4d192721ba982241d872c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.6
|
Security for sanic_csrf 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.