CVE-2021-33026
Flask-Caching 1.10.1 Pickle serialization RCE/privilege escalation if cache compromised
- CVSS 9.8
- CWE-502 Deserialization of Untrusted Data
- Authentication, Authorization, and Session Management
- Remote
** DISPUTED ** The Flask-Caching extension through 1.10.1 for Flask relies on Pickle for serialization, which may lead to remote code execution or local privilege escalation. If an attacker gains access to cache storage (e.g., filesystem, Memcached, Redis, etc.), they can construct a crafted payload, poison the cache, and execute Python code. NOTE: a third party indicates that exploitation is extremely unlikely unless the machine is already compromised; in other cases, the attacker would be unable to write their payload to the cache and generate the required collision.
- CVSS base score
- 9.8
- Published
- 2021-05-13
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Algorithm
- Code defect classification
- Incorrect Algorithm
- Category
- Authentication, Authorization, and Session Management
- Subcategory
- Privilege Escalation
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Fixed by upgrading
- Yes
Solution
Update Flask-Caching to version 1.10.2 or higher.
Vulnerable code sample
from flask import Flask
from flask_caching import Cache
import pickle
app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'simple', 'CACHE_DEFAULT_TIMEOUT': 300})
@app.route('/set_cache/<key>/<value>')
def set_cache(key, value):
# VULNERABLE: This code is susceptible to deserialization
cache.set(key, pickle.dumps(value))
if __name__ == '__main__':
app.run(debug=True)Patched code sample
from flask import Flask
from flask_caching import Cache
import json
app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'simple', 'CACHE_DEFAULT_TIMEOUT': 300})
@app.route('/set_cache/<key>/<value>')
def set_cache(key, value):
# SECURE: This version prevents deserialization
cache.set(key, json.dumps(value))
if __name__ == '__main__':
app.run(debug=True)Cite this entry
@misc{vaitp:cve202133026,
title = {{Flask-Caching 1.10.1 Pickle serialization RCE/privilege escalation if cache compromised}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2021},
note = {VAITP Python Vulnerability Dataset, entry CVE-2021-33026},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-33026/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
