wgwz / flask-cookie-decode

Flask extension with tools for decoding the session cookie

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

flask-cookie-decode

Github Build Status
Documentation Status

Purpose

Adds a cookie command to the built-in Flask CLI which will provide various tools for debugging the secure session cookie that Flask uses by default.

Current available commands

  1. `flask cookie decode`: decodes and verifies the signature of the session cookie

Background

By default the Flask session uses a signed cookie to store its data. The Flask application signs the cookie using its SECRET_KEY. This provides the Flask application a way to detect any tampering to the session data. If the application is indeed using a secret key and secure hashing algorithm, the session signature will be unique to application.

For more on the topic of the Flask session see these references:

Disclaimer: Keep your SECRET_KEY, secret!

If you expose this key your application becomes vulnerable to session replay attacks. Here is an example where an application exposed the SECRET_KEY during 404 errors. The example also illustrates how session replay works.

By default Flask does not expose the SECRET_KEY anywhere. It is up to you the developer to keep it that way!

Usage

Installation

Finding the cookie in browser tools

Example Flask app

See examples/app.py:

Examples using the CLI:

This extension will ship two CLI interfaces for dealing with decoding cookies. One requires a Flask application instance for the application you are wanting to debug. This method has the added benefit that the signature of the cookie can be verified, as your application instance has the SECRET_KEY used to sign the cookie. This method returns decoded cookie objects which can be seen in the examples below. This method can return a few different types of cookie objects depending on the state of the cookie. Please keep in mind that this extension provides only a thin-wrapper around the logic Flask uses to deal with cookies.

The second CLI interface is a tool for decoding cookies without the app secret. It cannot validate the signatures on the cookies or check the expirations and does not require the application instance like the other CLI. Intended for debugging purposes only.

CLI attached to application instance

  1. A cookie with a valid signature:
  1. A cookie with an invalid signature:
  1. An expired cookie:

CLI that ships with package which only decodes

Documentation

Docs

License

MIT.

About

Flask extension with tools for decoding the session cookie

License:MIT License


Languages

Language:Python 84.1%Language:Makefile 15.9%