Open your browser's dev tools on almost any Flask app that uses the built-in session, and you'll find a cookie that looks like random noise:
session=eyJyb2xlIjoiZWRpdG9yIiwidXNlcl9pZCI6NDJ9.aw5RVg.6RzRlPX-o-hiOKp2Li-B87K_pWY It isn't noise, and it isn't encrypted. The Flask docs say so directly: the session "signs the cookies cryptographically. What this means is that the user could look at the contents of your cookie but not modify it, unless they know the secret key used for signing." (Flask 3.1.x quickstart, "Sessions", checked 1 Dec 2026.)
This post takes a real cookie apart, piece by piece, so you know exactly what your users (and anyone who grabs the cookie) can read.
The setup (illustrative)
Everything below came from a tiny app run locally with Flask 3.1.3 and itsdangerous 2.2.0. The secret key is a throwaway value for this article. Never use a key like this in production.
from flask import Flask, session app = Flask(__name__) app.secret_key = "demo-secret-key-for-article" # illustrative only @app.route("/login") def login(): session["user_id"] = 42 session["role"] = "editor" return "ok" @app.route("/cart") def cart(): session["cart"] = ["SKU-1001"] * 40 return "ok" print(app.test_client().get("/login").headers["Set-Cookie"]) print(app.test_client().get("/cart").headers["Set-Cookie"]) Output (your timestamp and signature will differ):
session=eyJyb2xlIjoiZWRpdG9yIiwidXNlcl9pZCI6NDJ9.aw5RVg.6RzRlPX-o-hiOKp2Li-B87K_pWY; HttpOnly; Path=/ session=.eJyrVkpOLCpRsopWCvYO1TU0MDBU0hllDh1mbC0AutdgfQ.aw5RVg.zRBPV0qxk-Q2DotfnIgM9kBRAqE; HttpOnly; Path=/ Three parts, split on the dots
A Flask session cookie is an itsdangerous URLSafeTimedSerializer token:
<payload>.<timestamp>.<signature> All three parts are Base64URL without padding: - and _ instead of + and /, and no trailing =.
1. The payload
eyJyb2xlIjoiZWRpdG9yIiwidXNlcl9pZCI6NDJ9 Decode it as UTF-8 and you get:
{"role":"editor","user_id":42} That's 40 Base64 characters for 30 bytes of JSON (40 ÷ 4 × 3 = 30). Anyone holding the cookie can read the role and user ID. They just can't change them without breaking the signature.
2. The timestamp
aw5RVg Six characters, four bytes. Decoded as hex: 6B 0E 51 56. Read as a big-endian integer, that's 1796100438, a Unix timestamp: 1 Dec 2026, 04:47:18 UTC. It's when the cookie was signed, and it's what max_age checks against when the cookie is loaded.
import base64 raw = base64.urlsafe_b64decode("aw5RVg" + "==") print(int.from_bytes(raw, "big")) # 1796100438 3. The signature
6RzRlPX-o-hiOKp2Li-B87K_pWY 27 characters, 20 bytes: E9 1C D1 94 F5 FE A3 E8 62 38 AA 76 2E 2F 81 F3 B2 BF A5 66. Twenty bytes is the size of a SHA-1 digest, and that matches Flask's defaults in flask/sessions.py: digest_method is SHA-1, key_derivation is "hmac", and the salt is "cookie-session". Without the secret key you can see these bytes, but you can't produce valid ones for a modified payload.
Why the second cookie starts with a dot
The cart cookie begins with .eJy…. That leading dot is a flag: the payload is zlib-compressed.
In itsdangerous 2.2.0, URLSafeSerializerMixin.dump_payload compresses the JSON and keeps the compressed version only when it's shorter than the original by more than one byte. If it uses compression, it puts a . in front of the Base64.
A cart with forty identical SKUs compresses very well, so the dot appears. Decode eJyrVkpOLCpRsopWCvYO1TU0MDBU0hllDh1mbC0AutdgfQ as hex and the first bytes are:
78 9C AB 56 4A 4E 2C 2A ... 78 9C is the standard zlib header. Decoding the same string as UTF-8 gives you garbage, which is the usual "my Base64 decoder is broken" moment. The decoder is fine. You're looking at compressed bytes. Inflate them:
import base64, zlib p = "eJyrVkpOLCpRsopWCvYO1TU0MDBU0hllDh1mbC0AutdgfQ" data = base64.urlsafe_b64decode(p + "=" * (-len(p) % 4)) print(len(data)) # 34 print(zlib.decompress(data)) # b'{"cart":["SKU-1001","SKU-1001", ...]}' 34 bytes of Base64-decoded data inflate to the full JSON with all forty items. So compression doesn't hide anything either.
Gotchas when decoding by hand
- Strip the leading dot before decoding a compressed payload. The dot isn't Base64.
- Missing padding. Python's
urlsafe_b64decoderejects unpadded input. Add=until the length is a multiple of 4, as in the snippet above. - Don't decode the whole cookie in one go. The dots aren't Base64 characters. Split first.
-
HttpOnlyisn't secrecy. It keeps JavaScript from reading the cookie, but the user can still see it in dev tools, and so can anything that logs request headers.
What this means for your app
- Never put secrets in the default session. No API tokens, password hashes, or internal notes. Treat everything in it as visible to the user.
- Keep
SECRET_KEYsecret and long. The signature is your only integrity guarantee. A leaked key means anyone can mint{"role":"admin"}. - Need confidentiality? Use server-side sessions (store an opaque ID in the cookie and the data on the server), or encrypt the data yourself.
- Watch the size. Browsers cap cookies at roughly 4 KB. If your cookies start getting the dot prefix, that's a hint you're storing more than you should.
Doing it in the browser instead
If you'd rather not open a Python shell, our URL-safe Base64 tool decodes these segments in the browser. The page UI is in English:
- Open https://base64decodetool.com/url-safe/ and choose Decode Base64.
- Paste one segment (payload, timestamp or signature, without the dots and without the leading
.). - Set Character Set to UTF-8 for the plain payload, or Hexadecimal for the timestamp, signature or a compressed payload, then press Convert if Live Conversion is off.
We ran all three segments above through the page's own decoding code. It accepted them without padding and returned the same JSON and the same hex bytes shown here. Decoding runs client-side, but treat real production cookies as credentials anyway.
Summary
- A Flask session cookie is
payload.timestamp.signature, all Base64URL without padding. - The payload is plain JSON, sometimes zlib-compressed, and a leading
.marks the compressed form. - The timestamp is a 4-byte Unix time. The signature is a 20-byte HMAC-SHA1 by default.
- Signed is not encrypted: never store anything in the session that the user shouldn't see.
Disclosure: base64decodetool.com is from Mind vs Drive, the team behind this blog.
