Skip to content

Commit 30a8903

Browse files
committed
fix: pickle deserialization RCE in session manager (CWE-502) (#9901)
CWE-502 in FileBackedSessionManager.get(): pickle.load was called on the session file before the HMAC integrity check. Any file dropped in the sessions directory was deserialized unconditionally, allowing an authenticated user with sessions-dir write access to achieve OS-level RCE. Fix: prepend a 64-byte hex SHA-256 HMAC header over the pickle body, computed with the SECRET_KEY, and verify it via hmac.compare_digest before any deserialization. Also raises (not asserts) on empty SECRET_KEY so -O does not strip the check, and narrows the post-deserialize except clause to surface programming errors instead of masking them. Tests: 13 new session-format tests covering round-trip, malicious- pickle rejection, header tampering, empty/truncated files, cookie-HMAC mismatch, unsafe sids, empty SECRET_KEY, MFA-shaped data, and SERVER_MODE=False direct upload. Includes docs/proposals/2026-04-30-eliminate-rce-and-symlink-escape.md, the shared design doc covering this fix and the symlink-traversal fix in the following commit. Reported-by: Fernando Bortotti <fernando.bortotti@bsd.com.br>
1 parent 24485fe commit 30a8903

3 files changed

Lines changed: 1398 additions & 20 deletions

File tree

0 commit comments

Comments
 (0)