Skip to main content

Simple package to protect against CSRF/XSRF attacks

Project description

simple-xsrf

A simple package to create CSRF/XSRF tokens and protect against CSRF/XSRF attacks.

Installation

pip install simple-xsrf

Usage

To use this package you will need a fernet key also known as a secret key. To create a key:

from cryptography.fernet import Fernet

key = Fernet.generate_key()

Make sure to store this key in a secure place like a database so that you can access it later. You will need it to create your tokens and decrypt them

Creating a token:

from simple_xsrf.token import create_xsrf

token = create_xsrf(key)

Checking if a token is valid:

from simple_xsrf.token import is_valid

is_token_valid = is_valid(key, token_from_request, token_from_storage)

You should store your token in a storage layer such as Redis or DynamoDB to be retrived later.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_xsrf-0.2.1.tar.gz (2.1 kB view hashes)

Uploaded Source

Built Distribution

simple_xsrf-0.2.1-py3-none-any.whl (2.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page