From 281e297db7ad040687ca10f45b5ffcc3c46fafb4 Mon Sep 17 00:00:00 2001 From: gbell27 Date: Wed, 25 Feb 2026 05:57:02 +0100 Subject: [PATCH] docs: add security warnings for WebFetch and FileSystem --- datapizza-ai-tools/filesystem/README.md | 22 ++++++++++++++++++++++ datapizza-ai-tools/web_fetch/README.md | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/datapizza-ai-tools/filesystem/README.md b/datapizza-ai-tools/filesystem/README.md index 0c8c7542..cf1ca7ea 100644 --- a/datapizza-ai-tools/filesystem/README.md +++ b/datapizza-ai-tools/filesystem/README.md @@ -196,3 +196,25 @@ Agent Response: Successfully deleted directory '/tmp/tmp_XXXXXX/initial_dir'. Cleaned up temporary directory: /tmp/tmp_XXXXXX (actual path will vary) ``` + +> ⚠️ **Warning**: Paths are not automatically normalized. Malicious inputs like `../../../../etc/passwd` may bypass `paths_to_include`/`paths_to_exclude` filters, leading to **path traversal vulnerabilities**. + +**Best Practices**: +- Normalize paths using `os.path.normpath` before any operation. +- Restrict access to known-safe directories using `paths_to_include`. + +**Example: Safe Path Handling in Python** +```python +import os + +def safe_path(base_dir, user_path): + # Ensure the user-provided path stays within the base directory. + norm_path = os.path.normpath(os.path.join(base_dir, user_path)) + if not norm_path.startswith(base_dir): + raise ValueError("Path traversal attempt detected") + return norm_path + +# Usage: +base_dir = "/safe/directory" +safe_user_path = safe_path(base_dir, user_input_path) +``` \ No newline at end of file diff --git a/datapizza-ai-tools/web_fetch/README.md b/datapizza-ai-tools/web_fetch/README.md index 7657292c..7a364705 100644 --- a/datapizza-ai-tools/web_fetch/README.md +++ b/datapizza-ai-tools/web_fetch/README.md @@ -82,3 +82,25 @@ The output will vary depending on the live content of the URL. For `https://lore --- Running agent for: 'Summarize the main points of the article at https://loremipsum.io/' --- Agent Response: The article on **loremipsum.io** provides a comprehensive overview of "Lorem Ipsum," which is a placeholder text commonly used in the graphic, print, and publishing industries. Here are the main points: ``` + +> ⚠️ **Warning**: This tool accepts unsanitized URLs. If exposed to untrusted input, it could be exploited for **Server-Side Request Forgery (SSRF)**, such as accessing internal services or cloud metadata endpoints (e.g., `http://169.254.169.254/`). + +**Best Practices**: +- Always validate URLs before processing (e.g., allowlist trusted domains). +- Avoid exposing this tool to uncontrolled input in production environments. +- Use `paths_to_include` and `paths_to_exclude` to restrict access to sensitive resources. + +**Example: URL Validation in Python** +```python +from urllib.parse import urlparse + +def is_safe_url(url, allowed_domains): + # Check if a URL belongs to a list of allowed domains. + parsed = urlparse(url) + return parsed.netloc in allowed_domains + +# Usage: +allowed_domains = ["api.trusted-service.com", "public-data.example.org"] +if not is_safe_url(user_input_url, allowed_domains): + raise ValueError("URL not allowed") +``` \ No newline at end of file