T09 · Insecure Skill Coding Practices
- Location
scripts/indexer.py:553- Finding
Arbitrary Code Execution Through Untrusted Pickle Cache Deserialization
- Content
View full analysis
Vulnerability Details
File Location:
scripts/indexer.py:147-155,scripts/indexer.py:553-562
Vulnerability Type: Unsafe deserialization of an attacker-controlled cache
Risk Level: HighVulnerable Code
python def __init__(self, root_path: str, cache_dir: Optional[str] = None): self.root = Path(root_path).resolve() self.cache_dir = Path(cache_dir) if cache_dir else self._get_default_cache_dir() self.cache_file = self.cache_dir / 'codebase_index.pkl' self.ignore_patterns = self.DEFAULT_IGNORE # Load or create index self.index: Optional[CodebaseIndex] = Nonepython def _get_default_cache_dir(self) -> Path: """Get default cache directory""" # Store cache in project's .codebase-intelligence directory cache_dir = self.root / '.codebase-intelligence' cache_dir.mkdir(exist_ok=True) return cache_dirpython def _load_cache(self) -> Optional[CodebaseIndex]: """Load index from cache""" try: if self.cache_file.exists(): with open(self.cache_file, 'rb') as f: return pickle.load(f) except Exception as e: print(f" ⚠️ Could not load cache: {e}") return NoneTechnical Analysis
The index cache is stored by default in
.codebase-intelligence/codebase_index.pklinside the project being analyzed. Consequently, the cache file can be supplied or modified by the author of an untrusted repository.Python pickle is an executable serialization format. During
pickle.load(), specially constructed objects can invoke arbitrary callables through reconstruction methods such as__reduce__. Catching exceptions aroundpickle.load()does not prevent execution because the malicious callable can run before deserialization returns or raises an exception.The documented
analyze,index, andaskworkflows construct anIndexerand callbuild_index(). That ...[truncated 1559 chars]- Remediation
View remediation
Remediation Suggestions
- Remove pickle deserialization and use a non-executable format such as JSON.
- Validate the deserialized JSON against a strict schema before constructing
CodebaseIndexandFileIndexobjects. - Store caches outside the analyzed repository, such as under a user-owned platform cache directory keyed by a hash of the canonical project path.
- Create cache directories and files with restrictive permissions.
- Do not automatically migrate or load legacy pickle files found inside repositories.
- If legacy cache migration is necessary, require an explicit trusted-cache migration operation and clearly warn that pickle files must not originate from untrusted projects.
- Treat cache parse failures as invalid cache data and rebuild the index from source.
