T09 · Insecure Skill Coding Practices
- Location
scripts/search.py:18- Finding
Persistent Plaintext Memory Index Uses Process-Default File Permissions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search.py, lines 18–24, 316–317, and 422–449
Vulnerability Type: Plaintext storage of potentially sensitive memory data with insufficient access-control enforcement
Risk Level: MediumVulnerable Code
python WORKSPACE = os.path.expanduser("~/.openclaw/workspace") MEMORY_PATHS = [ f"{WORKSPACE}/MEMORY.md", f"{WORKSPACE}/memory/*.md", ] INDEX_PATH = os.path.expanduser("~/.openclaw/memory_bm25_index.json") TOKEN_CACHE_PATH = os.path.expanduser("~/.openclaw/memory_bm25_token_cache.json")python try: with open(filepath, 'r', encoding='utf-8') as f: content = f.read() except Exception: return []python with open(TOKEN_CACHE_PATH, 'w', encoding='utf-8') as f: json.dump({f"{k[0]}|||{k[1]}": v for k, v in token_cache.items()}, f, ensure_ascii=False) N, doc_freqs, avg_dl = get_all_terms(chunks) index = [] for chunk in chunks: term_freqs = Counter(chunk['terms']) index.append({ 'text': chunk['text'], 'file': chunk['file'], 'start_line': chunk['start_line'], 'end_line': chunk['end_line'], 'chunk_idx': chunk['chunk_idx'], 'heading_hit': chunk['heading_hit'], 'tf': dict(term_freqs), 'terms_set': list(set(chunk['terms'])), }) data = { 'N': N, 'doc_freqs': dict(doc_freqs), 'avg_dl': avg_dl, 'chunks': index, } with open(INDEX_PATH, 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False)Technical Analysis
The index builder reads the complete contents of the configured memory files and stores each chunk's plaintext in
~/.openclaw/memory_bm25_index.json. It also creates a token cache containing source paths and derived memory data.Both output files are opened with ordinary write mode and no explicit restrictive permissions. Their resulting access mo ...[truncated 2018 chars]
- Remediation
View remediation
Remediation Suggestions
- Ensure
~/.openclawis owned by the current user and has mode0700before writing. - Create the index and token-cache files with mode
0600, rather than relying on the caller'sumask. Useos.open()withO_CREAT | O_EXCL | O_WRONLYand mode0o600, or explicitly applyos.chmod(path, 0o600). - Write data to securely created temporary files in the same protected directory, flush and synchronize them, and publish them with
os.replace()to avoid partial or corrupted indexes. - Reject symbolic links and unexpected file types. Use
lstat(),O_NOFOLLOWwhere supported, and verify directory ownership and permissions. - Minimize stored data. If full chunk text is unnecessary for retrieval, avoid duplicating it in the index or store only the minimum required metadata.
- Document retention and deletion behavior, and remove or rebuild stale indexes when source memory is deleted or materially changed.
- Consider encryption at rest if the threat model includes other privileged local processes or storage-media disclosure.
- Ensure
