Skip to main content

What is Flask-Mitten?

Adds security functions to Flask applications for preventing some of the basic threats.

Features

Flask-Mitten supports Flask applications to prevent following threats.

  • Clickjacking

  • CSRF

  • Information disclosure through banner grabbing

  • JSON hijacking

  • Session fixation

It bundles functions of following Flask extensions.

More details, see the implementation.

Usage

Installation

Install the extension with the following commands:

pip install Flask-Mitten

Configuration

Apply the extention to your app:

from flaskext.mitten import Mitten
app = Flask(__name__)
mitten = Mitten(app)

Request headers are overridden to prevent clickjacking and information disclosure.

If you want to set your own banner, you can do it:

mitten.banner = "My Nice Banner!"

Preventing Session Fixation

After login, call a regenerate method of session object:

session.regenerate()

The session ID is regenerated, and it prevents session fixation.

To discard a session, call a destroy method:

session.destroy()

Preventing CSRF

To embed CSRF token, add following line to your template:

<input type="hidden" name="_csrf_token" value="{{ csrf_token() }}" />

A POST request is protected against CSRF automatically.

If you want to exclude a route from CSRF protection, use a csrf_exempt decorator:

@mitten.csrf_exempt
@app.route('/public_api/', methods=['POST'])
def public_api():
    return "result", 200

Preventing JSON Hijacking

If you send a JSON response, you could use a json decorator to avoid JSON hijacking or rendering JSON responses by direct browsing:

@mitten.json
@app.route('/json_api/')
def json_api():
    return jsonify(result='success')

More

For more details, see an example app.

Metadata

Release files for Flask-Mitten 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-Mitten 0.2.1
File Size Uploaded
Flask-Mitten-0.2.1.zip 12.2 kB Details

Release files / Flask-Mitten-0.2.1.zip

Download URL Flask-Mitten-0.2.1.zip
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1fed723371796abb9c0678d1566fde643b3c180cc86ca598949566ab72c09892
BLAKE2b-256 checksum
How to use checksums
375968b7b29da71160fc247904a7c166c7f27ba34cd82c6e6ab0391d958c604c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.1 This release

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page