T09 · Insecure Skill Coding Practices
- Location
scripts/chunk_db.py:42- Finding
Unsafe Pickle Deserialization Enables Arbitrary Code Execution
- Content
View full analysis
Vulnerability Details
File Location:
scripts/chunk_db.py, lines 42–51
Vulnerability Type: Unsafe deserialization
Risk Level: HighVulnerable Code
python def load_checkpoint(): if os.path.exists(CKPT_PATH): try: with open(CKPT_PATH, "rb") as f: data = pickle.load(f) log.info("Checkpoint loaded: last_idx=%d total_written=%d", data.get("last_idx", -1), data.get("total_written", 0)) return data except Exception as e: log.warning("Checkpoint unreadable (%s), starting fresh", e)Technical Analysis
The application automatically deserializes the checkpoint at the predictable path
D:\edata.lance\temp\telegram.ckptusingpickle.load().Python pickle is an executable serialization format. A crafted pickle can invoke attacker-selected callables through reduction operations during deserialization. Consequently, this file does not need to contain valid checkpoint data to execute code. The surrounding exception handler does not prevent exploitation because the payload can execute before deserialization returns or raises an exception.
Exploitation requires the attacker to be able to create, replace, or modify the checkpoint file. This may be possible for another process running as the same user, a user with write access to the checkpoint directory, or an attacker who has gained limited local file-write capability.
Attack Path
- The attacker obtains write access to
D:\edata.lance\temp\telegram.ckptor its parent directory. - The attacker creates a malicious pickle whose deserialization routine invokes an arbitrary Python callable or operating-system command.
- A user runs the documented Telegram import command.
load_checkpoint()opens the attacker-controlled checkpoint.pickle.load(f)executes the embedded reduction operation with the privileges of the importing ...[truncated 688 chars]
- The attacker obtains write access to
- Remediation
View remediation
Remediation Suggestions
- Replace pickle with a non-executable format such as JSON.
- Serialize
seen_keysas a JSON array and reconstruct it as a set only after validation. - Validate that
last_idxandtotal_writtenare non-negative integers and that everyseen_keysentry is a string. - Reject unknown fields, excessive checkpoint sizes, and malformed values.
- Create the checkpoint directory with permissions restricted to the importing user.
- Where supported, verify file ownership and reject symbolic links before reading the checkpoint.
- Continue using atomic replacement for checkpoint writes, but create the temporary file securely in the destination directory and apply restrictive permissions.
- Do not attempt to make pickle safe through content inspection; migrate existing checkpoints through a trusted, one-time conversion process instead.
