T09 · Insecure Skill Coding Practices
- Location
moodle_connector.py:514- Finding
Moodle Authentication Token Exfiltration Through Unrestricted Download URLs
- Content
View full analysis
Path: """ Download a Moodle file (PDF, doc, etc.) with local caching. Returns the local path. """ # Build a stable filename from the URL url_hash = hashlib.sha256(file_url.encode()).hexdigest()[:16] # Try to get a meaningful name from the URL url_name = file_url.split("/")[-1].split("?")[0] or "file" filename = f"{url_hash}_{url_name}" if dest is None: dest = CACHE_DIR / "files" / filename dest.parent.mkdir(parents=True, exist_ok=True) if dest.exists(): log.debug("File already cached: %s", dest) return dest # Append token if not already present sep = "&" if "?" in file_url else "?" url_with_token = f"{file_url}{sep}token={self.token}" log.info("Downloading: %s → %s", file_url, dest.name) try: with self.session.get(url_with_token, stream=True, timeout=60) as r: ``` The unrestricted URL is exposed through MCP: ```python Tool( name="download", description="Download a file from Moodle", inputSchema={ "type": "object", "properties": { "url": { "type": "string", "description": "File URL to download" }, "output": { "type": "string", "description": "Optional: output file path (defaults to cache)" } }, "required": ["url"] } ) ``` ```python elif name == "download": url = arguments.get("url") output = arguments.get("output") result = connector.download(url, output) ``` ### Technical Analysis The downloader accepts an unrestricted URL and uncondit ...[truncated 2025 chars]- Remediation
View remediation
