T09 · Insecure Skill Coding Practices
- Location
scripts/weibo_core.py:61- Finding
Unsafe Cookie Deserialization Allows Arbitrary Code Execution
- Content
View full analysis
Vulnerability Details
File Location:
scripts/weibo_core.py, lines 61–63
Vulnerability Type: Unsafe Python pickle deserialization
Risk Level: HighVulnerable Code
python with open(COOKIE_FILE, "rb") as f: jar = pickle.load(f) session.cookies.update(jar)Technical Analysis
The application automatically deserializes
storage/weibo_cookies.pklusingpickle.load(). Python pickle data is executable serialization: specially constructed objects can invoke attacker-selected callables during deserialization.The file is loaded without validating its integrity, ownership, permissions, type, or contents. Consequently, the fact that the resulting object is expected to be a cookie jar does not prevent code execution because the malicious operation occurs inside
pickle.load()beforesession.cookies.update()is reached.Attack Path
- An attacker gains the ability to create or replace
storage/weibo_cookies.pkl. This could occur through shared-directory access, another compromised process, a malicious archive overlay, or modification of a writable project checkout. - The attacker generates a pickle payload whose reduction operation invokes arbitrary Python or operating-system functionality.
- A user runs the downloader when the session does not already contain the required cookie.
_ensure_cookies()calls_load_cookies()._load_cookies()invokespickle.load()on the attacker-controlled file.- The embedded callable executes with the privileges of the user running the downloader.
Impact Assessment
Successful exploitation provides arbitrary code execution under the downloader process's operating-system account. The attacker could read or modify any files accessible to that account, steal local credentials, alter downloaded content, invoke network services, or install additional user-level persistence.
This does not inherently provide administrator or root priv ...[truncated 260 chars]
- An attacker gains the ability to create or replace
- Remediation
View remediation
Remediation Suggestions
- Remove pickle-based cookie persistence entirely.
- Serialize only required primitive cookie attributes, such as name, value, domain, path, expiry, and secure flags, using JSON.
- Validate every decoded field against an explicit schema before reconstructing the cookie jar.
- Create the storage directory and cookie file with restrictive permissions, such as directory mode
0700and file mode0600on supported systems. - Reject cookie files that are symbolic links, are not regular files, have unexpected ownership, or are writable by other users.
- If integrity must be protected against unauthorized local modification, authenticate the serialized data with a securely managed MAC key. A signature does not make pickle safe; it should only supplement a non-executable format.
- Remove or safely migrate any existing
.pklcookie file rather than deserializing it during migration.
