🌐
GitHub
github.com › noraj › flask-session-cookie-manager
GitHub - noraj/flask-session-cookie-manager: :cookie: Flask Session Cookie Decoder/Encoder · GitHub
$ python{2,3} flask_session_cookie_manager{2,3}.py encode -s '.{y]tR&sp&77RdO~u3@XAh#TalD@Oh~yOF_51H(QV};K|ghT^d' -t '{"number":"326410031505","username":"admin"}' eyJudW1iZXIiOnsiIGIiOiJNekkyTkRFd01ETXhOVEExIn0sInVzZXJuYW1lIjp7IiBiIjoiWVdSdGFXND0ifX0.DE2iRA.ig5KSlnmsDH4uhDpmsFRPupB5Vw · Note: the session cookie structure must be a valid python dictionary ... $ python{2,3} flask_session_cookie_manager{2,3}.py decode -c 'eyJudW1iZXIiOnsiIGIiOiJNekkyTkRFd01ETXhOVEExIn0sInVzZXJuYW1lIjp7IiBiIjoiWVdSdGFXND0ifX0.DE2iRA.ig5KSlnmsDH4uhDpmsFRPupB5Vw' -s '.{y]tR&sp&77RdO~u3@XAh#TalD@Oh~yOF_51H(QV};K|ghT^d' {u'username': 'admin', u'number': '326410031505'}
Starred by 774 users
Forked by 93 users
Languages   Python 88.9% | Shell 11.1%
🌐
Degoogle
kirsle.net › wizards › flask-session.cgi
Flask Session Cookie Decoder
This is a simple Python script to decode Flask session cookies. Flask, by default, uses the URL-safe signed serializer "itsdangerous" to encode its client-side session cookies.
🌐
Noraj
noraj.github.io › flask-session-cookie-manager
Flask Session Cookie Decoder/Encoder | flask-session-cookie-manager
usage: flask_session_cookie_manager{2,3}.py encode [-h] -s <string> -t <string> optional arguments: -h, --help show this help message and exit -s <string>, --secret-key <string> Secret key -t <string>, --cookie-structure <string> Session cookie structure · usage: flask_session_cookie_manager{2,3}.py decode [-h] [-s <string>] -c <string> optional arguments: -h, --help show this help message and exit -s <string>, --secret-key <string> Secret key -c <string>, --cookie-value <string> Session cookie value
🌐
Pentesttools
pentesttools.net › flask-session-cookie-manager-flask-session-cookie-decoder-encoder
Flask-Session-Cookie-Manager – Flask Session Cookie Decoder/Encoder – PentestTools
August 12, 2020 - usage: flask_session_cookie_manager.py decode [-h] [-s <string>] -c <string> optional arguments: -h, --help show this help message and exit -s <string>, --secret-key <string> Secret key -c <string>, --cookie-value <string> Session cookie value ... $ python{2,3} flask_session_cookie_manager{2,3}.py ...
🌐
Kali Linux
kalilinuxtutorials.com › home › kali linux › flask session cookie manager : flask session cookie decoder/encoder
Flask Session Cookie Manager : Flask Session Cookie Decoder/Encoder
August 19, 2020 - $ python{2,3} flask_session_cookie_manager{2,3}.py encode -s ‘.{y]tR&sp&77RdO~u3@XAh#TalD@Oh~yOF_51H(QV};K|ghT^d’ -t ‘{“number”:”326410031505″,”username”:”admin”}’ eyJudW1iZXIiOnsiIGIiOiJNekkyTkRFd01ETXhOVEExIn0sInVzZXJuYW1lIjp7IiBiIjoiWVdSdGFXND0ifX0.DE2iRA.ig5KSlnmsDH4uhDpmsFRPupB5Vw · Note: the session cookie structure must be a valid python dictionary ... $ python{2,3} flask_session_cookie_manager{2,3}.py decode -c ‘eyJudW1iZXIiOnsiIGIiOiJNekkyTkRFd01ETXhOVEExIn0sInVzZXJuYW1lIjp7IiBiIjoiWVdSdGFXND0ifX0.DE2iRA.ig5KSlnmsDH4uhDpmsFRPupB5Vw’ -s ‘.{y]tR&sp&77RdO~u3@XAh#TalD@Oh~yOF_51H(QV};K|ghT^d’ {u’username’: ‘admin’, u’number’: ‘326410031505’}
🌐
saruberoz' site
saruberoz.github.io › flask-session-cookie-decoder-slash-encoder
Flask session cookie manager – saruberoz' site
""" Flask Session Cookie Decoder/Encoder """ __author__ = 'Wilson Sumanang' # standard imports import sys import zlib from itsdangerous import base64_decode # external Imports from flask.sessions import SecureCookieSessionInterface class MockApp(object): def __init__(self, secret_key): self.secret_key = secret_key def session_cookie_encoder(secret_key, session_cookie_structure): """ Encode a Flask session cookie Example: cookie_structure = dict( gplus_id = 1285135705050360459231, email = john.doe@gmail.com, user_info = dict( full_name = john doe, ) ) session_cookie_encoder(b'development key',
🌐
PyPI
pypi.org › project › flask-cookie-decode
flask-cookie-decode · PyPI
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. flask cookie decode: decodes and verifies the signature of the session cookie
      » pip install flask-cookie-decode
    
Published   Mar 09, 2025
Version   0.4.3
Find elsewhere
🌐
LinkedIn
linkedin.com › pulse › pentesting-ethical-hacking-tool-series-flask-session-cookie-vanegas
Pentesting and Ethical Hacking Tool Series: Flask Session Cookie Decoder/Encoder/BruteForce
June 1, 2023 - We can try to decode that cookie by extracting the first part of the value until the first point and decoding it using Base64. echo "eyJ2ZXJ5X2F1dGgiOiJzbmlja2VyZG9vZGxlIn0" | base64 -d 2>/dev/null;echo · As a result, we have: {"very_auth"...
Top answer
1 of 2
11

As Elias has already mentioned, the cookie can be decoded without the secret key, but it cannot be manipulated without it for obvious security reasons. If cookie tampering was as easy as that, nobody would use Flask sessions. Therefore, your task is to find the secret key, and since the SHA-1 hash function is non-reversible, you should turn your attention to the human factor.

That being said, you'll have to "guess" the secret key of the contest's careless programmer using brute force, and fortunately, Flask-Unsign can assist you with that.

You can install it via pip by using the following command:

pip3 install flask-unsign

but before using it, you will need a wordlist like rockyou, which you can download from the Kali Linux GitLab repository by using a command like the one below:

curl -JO https://gitlab.com/kalilinux/packages/wordlists/-/raw/kali/master/rockyou.txt.gz && gunzip rockyou.txt.gz
  • -J, --remote-header-name: Uses the server-specified Content-Disposition filename instead of extracting a filename from the URL when saving the file locally.
  • -O, --remote-name: Writes the output to a local file named like the remote file obtained, using the server-specified filename.

Now you can perform the brute force attack using the following command:

flask-unsign --unsign --cookie '.eJwtjkGKAzEMBL-S9TkHy5Yte96wP1jCIEvyJmxIYDxzCvn7-pBTUw1N18ut_c7jasMtPy932me4cYjYGO7svp-_t8fpw_24f7nL-3Kem83G1S37dtikm7rFQUJBRSOL1GKWVCoRC3ED7VAz9FKsVi9aO2RgJmgSi88VuQCmXghjaRZjSCqBDTm3qE1LAh8bGnuG3jAHCV4iZlAoPkhiAGghT9v1GLZ9bCbK2Pq6P__sMQuev2ZcKQFkMinJWhRSqB4hYyWv2oWre_8D5vtQyA.ZTUbZQ.erv_yZmYg44tiaJ0u8fqKailHUc' --no-literal-eval -w rockyou.txt   
  • The --no-literal-eval argument was used because Flask-Unsign assumes by default that each word in a given wordlist is enclosed in quotes. However, this is not the case with the rockyou wordlist.

and find the secret key after a few thousand attempts:

[*] Session decodes to: {'_flashes': [('success', 'Login successful!')], '_fresh': True, '_id': '154c4d4e7e37b36c58977ac7ab1df1961f88e990cd9f161aa71bc380694a8145f87438be3325dc2ae4a6b3dbd85103b4ea0a1fb462c20c3461d1802c5a111b26', '_user_id': '1', 'csrf_token': 'acd9eea9751167ec85eb3c7d1904164970ddfca9'}                       
[*] Starting brute-forcer with 8 threads..                                                                                                     
[+] Found secret key after 175360 attempts                                                                                                     
b'Galaxy'

Finally, having found the secret key, you can use it to sign your own cookie with modified session data according to your needs:

flask-unsign --sign --cookie "modified session data here" --secret 'Galaxy'
2 of 2
1

What you described is the expected behavior by design - the cookie can be decoded without the secret key, but it cannot be modified without it.

from documentation:

If you have set Flask.secret_key (or configured it from SECRET_KEY) you can use sessions in Flask applications. A session makes it possible to remember information from one request to another. The way Flask does this is by using a signed cookie. The user can look at the session contents, but can’t modify it unless they know the secret key, so make sure to set that to something complex and unguessable.

🌐
Modernnetsec
modernnetsec.io › home › python › python3
Flask-Session-Cookie-Manager – Flask Session Cookie Decoder/Encoder | ModernNetSec.io | Cyber Security News | Threat intel
August 10, 2020 - Flask Session Cookie Decoder/EncoderDepencencies InstallationBlackArch Linux# pacman -S flask-session-cookie-manager{3,2} GitArchLinuxBoth python3 etn python2
🌐
Xin Fu
imfing.com › til › decode-flask-session-cookie
Decode Flask session cookie | Xin Fu
January 4, 2023 - Here’s a short Python snippet that decodes the session cookie using zlib and base64.urlsafe_b64decode. import zlib import base64 def decode(cookie): """Decode a Flask cookie.""" try: compressed = False payload = cookie if payload.startswith('.'): compressed = True payload = payload[1:] data = payload.split(".")[0] data = base64.urlsafe_b64decode(data) if compressed: data = zlib.decompress(data) return data.decode("utf-8") except Exception as e: return "[Decoding error: are you sure this was a Flask session cookie?
🌐
Stack Overflow
stackoverflow.com › questions › 70026269 › how-to-forge-and-encode-session-cookie
flask - How to forge and encode session cookie - Stack Overflow
cs = s.get(url + "control-robot", cookies = {"session":"new cookie"}) ... .eJwljktqBDEMRO_idRaWZf3mMo0tS8wQSKB7ZhVy93HIsgrq1fspR55x3cvteb7ioxyPVW5lOKSvyObSsJFop2UgcwWxatPJUNlGtiqrsggKB5pMwzqkcqWmXLUbZndj8ole2av4Wg07zdFtuBNHThhsRLD5DhCOfXOjbJHXFee_Dezo15nH8_szvv6K5P1ludh0WuyVkrqCJklrAjhw-_dRft9jlD5c.YZax6g.tS__qotCbmnLiJgutCjo5R-q3o0 · I assume this is in jwt format, thus I used flask decode which gives me following output:
🌐
Readthedocs
flask-cookie-decode.readthedocs.io › en › latest › readme.html
1 flask-cookie-decode — flask-cookie-decode 0.4.3 documentation
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. flask cookie decode: decodes and verifies the signature of the session cookie
🌐
GitHub
github.com › noraj › flask-session-cookie-manager › blob › master › flask_session_cookie_manager2.py
flask-session-cookie-manager/flask_session_cookie_manager2.py at master · noraj/flask-session-cookie-manager
""" Flask Session Cookie Decoder/Encoder """ __author__ = 'Wilson Sumanang, Alexandre ZANNI' · # standard imports · import sys · import zlib · from itsdangerous import base64_decode · import ast · · # Abstract Base Classes (PEP 3119) if sys.version_info[0] <= 2 and sys.version_info[1] < 6: # < 2.6 ·
Author   noraj
🌐
picoCTF Solutions
picoctfsolutions.com › tools › flask-session-decoder
Flask Session Cookie Decoder | picoCTF Solutions
Forge a new cookie with flask-unsign on the command line: flask-unsign --sign --cookie "{'is_admin': True}" --secret '...'. When the cookie includes auth-relevant fields (admin role, user id, CSRF token), look at related tools: the JWT Decoder for token-based auth, URL Encoder for cookies that wrap percent-encoded data, and the Checksum Calculator if the secret is leaked as a hash. Old SessionspicoCTF 2026 ·
🌐
GitHub
gist.github.com › babldev › 502364a3f7c9bafaa6db
Decode a Flask Session cookie, given the cookie and secret key · GitHub
Decode a Flask Session cookie, given the cookie and secret key - decode_flask_cookie.py
🌐
Hyperskill
hyperskill.org › learn › step › 33914
Flask Sessions - Decoding
Hyperskill is an educational platform for learning programming and software development through project-based courses, that helps you secure a job in tech. Master Python, Java, Kotlin, and more with real-world coding challenges.