T09 · Insecure Skill Coding Practices
- Location
SKILL.md:94- Finding
Path Traversal in MCP Filesystem Integration Example
- Content
View full analysis
- Remediation
View remediation
Path: requested = Path(path) if requested.is_absolute(): raise ValueError("Absolute paths are not permitted") resolved = (DOCUMENT_ROOT / requested).resolve() if resolved != DOCUMENT_ROOT and DOCUMENT_ROOT not in resolved.parents: raise ValueError("Path escapes the document directory") return resolved @server.resource("file://documents/{path}") async def read_document(path: str): safe_path = resolve_document_path(path) return safe_path.read_text() @server.tool("write_document") async def write_document(path: str, content: str): safe_path = resolve_document_path(path) safe_path.write_text(content) return {"status": "written"} ``` ]]>
