T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/embed_memories.py:16
- Finding
- Environment-controlled embedding endpoint can receive sensitive agent memory<![CDATA[ ## Vulnerability Details **File Location**: `scripts/embed_memories.py:16-18, 22, 31-43, 80-84, 89-108`; `scripts/search_memory.py:20-22, 145-149, 226-245` **Vulnerability Type**: Unrestricted transmission of sensitive data to a configurable network endpoint **Risk Level**: High ### Vulnerable Code From `scripts/embed_memories.py`: ```python MEMORY_DIR = os.environ.get('MEMORY_DIR', os.path.join(os.path.dirname(__file__), '..', '..', '..', 'memory')) VECTORS_FILE = os.path.join(MEMORY_DIR, 'vectors.json') OLLAMA_URL = os.environ.get('OLLAMA_URL', 'http://localhost:11434/api/embed') MODEL = os.environ.get('EMBED_MODEL', 'nomic-embed-text') # Core workspace files to also index (relative to workspace root) CORE_FILES = ['MEMORY.md', 'AGENTS.md', 'USER.md', 'SOUL.md', 'research.md'] def get_md_files(memory_dir): """Collect all .md files from memory directory and core workspace files.""" files = [] for root, _, fnames in os.walk(memory_dir): for f in fnames: if f.endswith('.md'): files.append(os.path.join(root, f)) workspace = os.path.abspath(os.path.join(memory_dir, '..')) for name in CORE_FILES: path = os.path.join(workspace, name) if os.path.exists(path): files.append(os.path.abspath(path)) return files ``` ```python def embed_batch(texts): """Get embeddings for a batch of texts from Ollama.""" data = json.dumps({'model': MODEL, 'input': texts}).encode() req = urllib.request.Request(OLLAMA_URL, data=data, headers={'Content-Type': 'application/json'}) with urllib.request.urlopen(req, timeout=60) as resp: return json.loads(resp.read())['embeddings'] ``` ```python def main(): memory_dir = sys.argv[1] if len(sys.argv) > 1 else MEMORY_DIR memory_dir = os.path.abspath(memory_dir) workspace_root = os.path.abspath(os.path.join(memory_dir, '..')) files = get_md_files(memory_dir) all_chunks = [] for f in files: a ...[truncated 4635 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Restrict the embedding endpoint to loopback addresses by default. Parse the configured URL and reject hosts other than `localhost`, `127.0.0.1`, and `::1`. 2. Require a separate, explicit option such as `--allow-remote-embedding` before permitting a non-loopback endpoint. 3. Require HTTPS for every non-loopback endpoint and retain normal certificate validation. 4. Display the destination hostname and the files selected for indexing before transmitting content to a remote service, then require explicit confirmation. 5. Do not automatically index sensitive core files. Replace `CORE_FILES` with an explicit allowlist selected by the user. 6. Provide exclusion controls for private files, directories, and content patterns. 7. Clearly document that embedding requests contain source text rather than only derived vectors. 8. Consider separate configuration variables for trusted local Ollama and remote providers, with remote providers disabled by default. 9. Minimize pseudo-relevance feedback disclosure by performing expansion locally or requiring explicit consent before sending memory-derived terms. 10. Add tests verifying that malformed URLs, non-HTTP schemes, remote HTTP endpoints, credential-bearing URLs, and unexpected hosts are rejected. ]]>
