{"id":152,"cve":"CVE-2014-4650","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2014-4650","cwe":"CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')","cwe_number":22,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/22","cvss_score":9.8,"published":"2020-02-20","owasp":"A08 Software and Data Integrity Failures","odc":"Algorithm","cdc":"Incorrect Algorithm","category":"Input Validation and Sanitization","subcategory":"Path Traversal","scope":"Remote","impact":"Information Disclosure","summary":"Path Traversal Vulnerability","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2014-4650\/","description":"The CGIHTTPServer module in Python 2.7.5 and 3.3.4 does not properly handle URLs in which URL encoding is used for path separators, which allows remote attackers to read script source code or conduct directory traversal attacks and execute unintended code via a crafted character sequence, as demonstrated by a %2f separator.","solution":"Upgrade to a patched version of Python.","affected_component":"Python","fixed_by_upgrading":true,"vulnerable_code":"import CGIHTTPServer\nimport BaseHTTPServer\n\n# VULNERABLE: CGIHTTPServer allows path traversal attacks\n# Attackers can access files outside the intended directory\nif __name__ == \"__main__\":\n    server = BaseHTTPServer.HTTPServer(('', 8000), CGIHTTPServer.CGIHTTPRequestHandler)\n    server.serve_forever()\n\n# Example attack: GET \/..\/..\/..\/etc\/passwd\n","patched_code":"import http.server\nimport socketserver\nimport os\nfrom urllib.parse import unquote\n\nclass SecureHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):\n    def translate_path(self, path):\n        # SECURE: Prevent path traversal by validating paths\n        path = unquote(path)\n        \n        # Remove query parameters\n        path = path.split('?', 1)[0]\n        path = path.split('#', 1)[0]\n        \n        # Normalize the path and check for traversal attempts\n        normalized = os.path.normpath(path)\n        if '..' in normalized or normalized.startswith('\/'):\n            # Block path traversal attempts\n            return None\n        \n        # Restrict to current directory only\n        safe_path = os.path.join(os.getcwd(), normalized.lstrip('\/'))\n        \n        # Ensure the path is within the allowed directory\n        if not safe_path.startswith(os.getcwd()):\n            return None\n            \n        return safe_path\n\nif __name__ == \"__main__\":\n    PORT = 8000\n    with socketserver.TCPServer((\"\", PORT), SecureHTTPRequestHandler) as httpd:\n        print(f\"Serving at port {PORT} with path traversal protection\")\n        httpd.serve_forever()\n","payload_needed":false,"payload":null,"payload_status":"none","published_fix":[],"references":null}