flasksession

package
v0.807.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package flasksession decodes, verifies and forges Flask session cookies (the itsdangerous URLSafeTimedSerializer format). It is a web-pentest primitive directly parallel to the JWT tooling: a Flask session cookie is signed (not encrypted), so its payload is readable by anyone, and an app with a weak or leaked SECRET_KEY can be impersonated by forging an arbitrary session — the classic flask-unsign attack.

Wrap-vs-native judgement

Native. The format is base64url segments (payload[.compressed].timestamp.sig) signed with HMAC-SHA1 under a key derived as HMAC-SHA1(SECRET_KEY, "cookie-session"). It is a few dozen lines over crypto/hmac + crypto/sha1 + compress/zlib; there is nothing to wrap.

Verifiable / no confidently-wrong output

The signing derivation, the timestamp epoch, and the zlib compression were confirmed byte-for-byte against the reference itsdangerous library (the authoritative implementation) — the unit tests gate decode and verify against itsdangerous-produced cookies. The payload is signed-not-encrypted so decode asserts nothing secret; verify is constant-time and reports which candidate SECRET_KEY (if any) validates, never guessing.

Covered / deferred

Covered: decode (payload + timestamp, transparently zlib-inflating compressed payloads), verify against candidate SECRET_KEYs, and forge (sign an arbitrary payload). The TaggedJSONSerializer's type tags ({" b": …} etc.) are surfaced as the raw JSON they are rather than expanded.

Index

Constants

View Source
const DefaultSalt = "cookie-session"

DefaultSalt is Flask's SecureCookieSessionInterface salt.

Variables

This section is empty.

Functions

func Sign

func Sign(payloadJSON, secret, salt string, unixTime int64) (string, error)

Sign forges a Flask session cookie: it base64url-encodes the (compacted) payload JSON, appends the timestamp, and signs with secret/salt. The payload is not compressed (an uncompressed cookie is equally valid), so a server with this SECRET_KEY will accept it.

func Verify

func Verify(cookie, secret, salt string) (bool, error)

Verify reports whether the cookie's signature is valid under secret/salt (salt "" defaults to Flask's "cookie-session").

Types

type Session

type Session struct {
	Payload     any    `json:"payload"`
	PayloadJSON string `json:"payload_json"`
	Compressed  bool   `json:"compressed"`
	UnixTime    int64  `json:"unix_time,omitempty"`
	Signature   string `json:"signature"`
}

Session is a decoded Flask session cookie.

func Decode

func Decode(cookie string) (*Session, error)

Decode parses a Flask session cookie. It does not require the SECRET_KEY (the cookie is signed, not encrypted).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL