{"id":18232819,"url":"https://github.com/wgwz/flask-cookie-decode","last_synced_at":"2025-04-03T18:32:02.372Z","repository":{"id":57430234,"uuid":"163689774","full_name":"wgwz/flask-cookie-decode","owner":"wgwz","description":"Flask extension with tools for decoding the session cookie","archived":false,"fork":false,"pushed_at":"2024-09-03T23:03:31.000Z","size":178,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-18T03:33:47.041Z","etag":null,"topics":["flask"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wgwz.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null}},"created_at":"2018-12-31T18:25:29.000Z","updated_at":"2024-09-03T23:03:33.000Z","dependencies_parsed_at":"2024-03-17T02:56:40.009Z","dependency_job_id":null,"html_url":"https://github.com/wgwz/flask-cookie-decode","commit_stats":{"total_commits":88,"total_committers":1,"mean_commits":88.0,"dds":0.0,"last_synced_commit":"c8252b496042c7a11bbc1ac080b03d1291bbfbb3"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wgwz%2Fflask-cookie-decode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wgwz%2Fflask-cookie-decode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wgwz%2Fflask-cookie-decode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wgwz%2Fflask-cookie-decode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wgwz","download_url":"https://codeload.github.com/wgwz/flask-cookie-decode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223006587,"owners_count":17072199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask"],"created_at":"2024-11-04T14:03:53.497Z","updated_at":"2024-11-04T14:03:54.046Z","avatar_url":"https://github.com/wgwz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"flask-cookie-decode\n###################\n\n.. list-table::\n\n    * - .. image:: https://github.com/wgwz/flask-cookie-decode/actions/workflows/action.yml/badge.svg\n          :target: https://github.com/wgwz/flask-cookie-decode/actions\n          :alt: Github Build Status\n    \n    * - .. image:: https://readthedocs.org/projects/flask-cookie-decode/badge/?version=latest\n          :target: https://flask-cookie-decode.readthedocs.io/en/latest/?badge=latest\n          :alt: Documentation Status\n\n.. contents::\n\n.. section-numbering::\n\nPurpose\n=======\n\nAdds a ``cookie`` command to the built-in Flask CLI which will provide various\ntools for debugging the secure session cookie that Flask uses by default.\n\nCurrent available commands\n--------------------------\n\n1. `flask cookie decode`: decodes and verifies the signature of the session cookie\n\nBackground\n==========\n\nBy default the Flask session uses a signed cookie to store its data. The Flask\napplication signs the cookie using its ``SECRET_KEY``. This provides the Flask\napplication a way to detect any tampering to the session data. If the application\nis indeed using a secret key and secure hashing algorithm, the session signature\nwill be unique to application.\n\nFor more on the topic of the Flask session see these references:\n\n* `How Secure Is The Flask User Session?`_\n* `Quickstart for Flask Sessions`_\n* `API Docs for Flask Sessions`_\n\n.. _`How Secure Is The Flask User Session?`: https://blog.miguelgrinberg.com/post/how-secure-is-the-flask-user-session\n.. _`Quickstart for Flask Sessions`: http://flask.pocoo.org/docs/1.0/quickstart/#sessions\n.. _`API Docs for Flask Sessions`: http://flask.pocoo.org/docs/1.0/api/#sessions\n.. _`Flask Session Cookie Decoder`: https://www.kirsle.net/wizards/flask-session.cgi\n\nDisclaimer: Keep your SECRET_KEY, secret!\n-----------------------------------------\n\nIf you expose this key your application becomes vulnerable to session replay\nattacks. `Here is an example`_ where an application exposed the ``SECRET_KEY``\nduring 404 errors. The example also illustrates how session replay works.\n\nBy default Flask does not expose the ``SECRET_KEY`` anywhere. It is up to you\nthe developer to keep it that way!\n\n.. _`Here is an example`: https://terryvogelsang.tech/MITRECTF2018-my-flask-app/\n\nUsage\n=====\n\nInstallation\n------------\n\n.. code-block:: bash\n\n    $ pip install flask-cookie-decode\n\nExtracting the cookie using browser tools\n-----------------------------------------\n\n.. image:: https://raw.githubusercontent.com/wgwz/flask-cookie-decode/master/docs/cookie.png\n    :alt: Finding the cookie in browser tools\n    :width: 100%\n    :align: center\n\nExample Flask app\n-----------------\n\nSee `examples/app.py \u003chttps://github.com/wgwz/flask-cookie-decode/blob/master/examples/app.py\u003e`_:\n\n.. code-block:: python\n\n    from flask import Flask, jsonify, session, request\n    from flask_cookie_decode import CookieDecode\n\n    app = Flask(__name__)\n    app.config.update({'SECRET_KEY': 'jlghasdghasdhgahsdg'})\n    cookie = CookieDecode()\n    cookie.init_app(app)\n\n    @app.route('/')\n    def index():\n        a = request.args.get('a')\n        session['a'] = a\n        return jsonify(dict(session))\n\nExamples using the CLI:\n-----------------------\n\nThis 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.\n\nThe 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.\n\nCLI attached to application instance\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n1. A cookie with a valid signature:\n\n.. code-block:: bash\n\n    $ export FLASK_APP=app.py\n    $ flask cookie decode eyJhIjoiYXNkYXNkamtqYXNkIn0.XCkk1Q.tTPu2Zhvn9KxgkP35ERAgyd8MzA\n    TrustedCookie(contents={'a': 'asdasdjkjasd'}, expiration='2019-01-30T20:04:37')\n\n2. A cookie with an invalid signature:\n\n.. code-block:: bash\n\n    $ export FLASK_APP=app.py\n    $ flask cookie decode eyJhIjoiYXNkYXNkamtqYXNkIn0.XCkk1Q.tTPu2Zhvn9KxgkP35ERAgyd8MzA\n    UntrustedCookie(contents={'a': 'asdasdjkjasd'}, expiration='2019-01-30T20:04:37')\n\n3. An expired cookie:\n\n.. code-block:: bash\n\n    $ export FLASK_APP=app.py\n    $ flask cookie decode eyJhIjoiYXNkYXNkamtqYXNkIn0.XCkk1Q.tTPu2Zhvn9KxgkP35ERAgyd8MzA\n    ExpiredCookie(contents={'a': 'asdasdjkjasd'}, expiration='2019-01-30T20:04:37')\n\nCLI that ships with package which only decodes\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: bash\n\n    $ fcd decode eyJhIjoiYXNkYXNkamtqYXNkIn0\n    {\n      \"a\": \"asdasdjkjasd\"\n    }\n\nDocumentation\n=============\n\n`Docs \u003chttps://flask-cookie-decode.readthedocs.io/en/latest/\u003e`_\n\nLicense\n=======\n\n`MIT \u003chttps://github.com/wgwz/flask-cookie-decode/blob/master/LICENSE\u003e`_.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwgwz%2Fflask-cookie-decode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwgwz%2Fflask-cookie-decode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwgwz%2Fflask-cookie-decode/lists"}