T09 · Insecure Skill Coding Practices
- Location
storage/local.py:19- Finding
Path Traversal in Local Memory Storage
- Content
View full analysis
Path: return self.base_path / f"{entry_id}.json" # storage/local.py:23-51 def save(self, entry: MemoryEntry) -> bool: try: path = self._get_entry_path(entry.id) with open(path, 'w', encoding='utf-8') as f: json.dump(entry.to_dict(), f, ensure_ascii=False, indent=2) return True except Exception as e: print(f"Error saving entry {entry.id}: {e}") return False def load(self, entry_id: str) -> Optional[MemoryEntry]: try: path = self._get_entry_path(entry_id) if not path.exists(): return None with open(path, 'r', encoding='utf-8') as f: data = json.load(f) return MemoryEntry.from_dict(data) except Exception as e: print(f"Error loading entry {entry_id}: {e}") return None def delete(self, entry_id: str) -> bool: try: path = self._get_entry_path(entry_id) if path.exists(): path.unlink() return True return False except Exception as e: print(f"Error deleting entry {entry_id}: {e}") return False ``` ```python # storage/base.py:40-42 @classmethod def from_dict(cls, data: Dict[str, Any]) -> 'MemoryEntry': return cls(**data) ``` ```python # memory_manager.py:545-558 if filepath: with open(filepath, 'r', encoding='utf-8') as f: data = json.load(f) elif json_str: data = json.loads(json_str) else: raise ValueError("Must provide filepath or json_str") count = 0 for entry_data in data.get('entries', []): entry = MemoryEntry.from_dict(entry_data) # Don't regenerate embedding during import self.s ...[truncated 1867 chars]- Remediation
View remediation
Path: if not re.fullmatch(r"[a-f0-9]{16}", entry_id): raise ValueError("Invalid memory entry ID") root = self.base_path.resolve() target = (root / f"{entry_id}.json").resolve() if target.parent != root: raise ValueError("Entry path escapes storage directory") return target ``` 4. Validate imported data against a strict schema before constructing `MemoryEntry`. 5. Consider opening files with protections against symbolic-link attacks when the storage directory may be writable by another principal. 6. Add regression tests for `../`, absolute paths, backslash traversal, encoded separators, and malicious imported IDs. ]]>
