T09 · Insecure Skill Coding Practices
- Location
rag_memory.py:174- Finding
Unnecessary and Undisclosed Transmission of Memory Data in SQLite Mode
- Content
View full analysis
str: """Automatically detect the host URL""" import socket try: socket.gethostbyname("host.docker.internal") return f"http://host.docker.internal:{default_port}" except: pass try: with open("/etc/resolv.conf", "r") as f: for line in f: if line.startswith("nameserver"): gateway = line.split()[1].strip() return f"http://{gateway}:{default_port}" except: pass return f"http://localhost:{default_port}" OLLAMA_URL = os.getenv("OLLAMA_URL", _get_host_url(11434)) ``` ```python def get_embedding(self, text: str) -> Optional[List[float]]: """Get embeddings through the Ollama service""" try: response = requests.post( f"{self.ollama_url}/api/embed", json={"model": "bge-m3", "input": text}, timeout=30 ) if response.status_code == 200: data = response.json() return data["embeddings"][0] except Exception as e: print(f"Embedding generation failed: {e}") return None def store_memory(self, content: str, metadata: Dict = None) -> int: """Store a memory""" embedding = self.get_embedding(content) memory_id = self.backend.store(content, metadata, embedding) self._backup_to_file(content, metadata, memory_id) print(f"Memory stored: {content[:50]}...") return memory_id def search_memories(self, query: str, top_k: int = 5) -> List[Dict]: """Search memories""" embedding = self.get_embedding(query) if self.backend_name == "milvus" and embedd ...[truncated 2428 chars]- Remediation
View remediation
int: embedding = None if self.backend_name == "milvus": embedding = self.get_embedding(content) memory_id = self.backend.store(content, metadata, embedding) self._backup_to_file(content, metadata, memory_id) return memory_id ``` 2. Require explicit opt-in before sending data to an embedding service. Network transmission should be disabled by default. 3. Require users to configure `OLLAMA_URL` explicitly instead of discovering a host from DNS or `/etc/resolv.conf`. 4. Validate the configured destination against an administrator-controlled allowlist. 5. Use authenticated HTTPS for non-loopback endpoints and verify TLS certificates. 6. Clearly document that memory content and search queries are sent to the configured embedding provider. 7. Consider a local in-process embedding option for deployments that require strict data locality. 8. Add tests confirming that SQLite storage and search generate no outbound network requests. ]]>
