{"id":1018,"cve":"CVE-2014-3429","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2014-3429","cwe":"CWE-94","cwe_number":94,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/94","cvss_score":6.8,"published":"2014-08-07","owasp":"A07 Identification and Authentication Failures","odc":"Interface","cdc":"Incorrect Interface","category":"Configuration Issues","subcategory":"Cross-Site Request Forgery (CSRF)","scope":"Remote","impact":"Arbitrary Code Execution","summary":"IPython Notebook 0.12-1.x WebSocket Origin Validation Bypass","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2014-3429\/","description":"IPython Notebook 0.12 through 1.x before 1.2 does not validate the origin of websocket requests, which allows remote attackers to execute arbitrary code by leveraging knowledge of the kernel id and a crafted page.","solution":"Update to IPython Notebook version 1.2 or higher","affected_component":"IPython","fixed_by_upgrading":true,"vulnerable_code":"import tornado.web\nimport tornado.websocket\nimport json\n\nclass WebSocket(tornado.websocket.WebSocketHandler):\n    def open(self):\n        print(\"WebSocket opened\")\n\n    def on_message(self, message):\n        data = json.loads(message)\n\n    def on_close(self):\n        print(\"WebSocket closed\")\n\napplication = tornado.web.Application([\n    (r'\/websocket', WebSocket),\n])\n\nif __name__ == \"__main__\":\n    application.listen(8888)\n    tornado.ioloop.IOLoop.current().start()","patched_code":"import tornado.web\nimport tornado.websocket\nimport tornado.ioloop\nimport json\nimport logging\n\nclass WebSocket(tornado.websocket.WebSocketHandler):\n    def open(self):\n        print(\"WebSocket opened\")\n\n    def on_message(self, message):\n        try:\n            data = json.loads(message)\n\n            if not isinstance(data, dict) or \"type\" not in data:\n                self.close(reason=\"Invalid message format\")\n                return\n\n        except json.JSONDecodeError:\n            self.close(reason=\"Invalid JSON format\")\n        except Exception as e:\n            logging.error(f\"Error while processing message: {e}\")\n            self.close(reason=\"Internal server error\")\n\n    def on_close(self):\n        print(\"WebSocket closed\")\n\n    def check_origin(self, origin):\n        allowed_origins = [\"http:\/\/your-allowed-origin.com\"]\n        if origin not in allowed_origins:\n            return False\n        return True\n\napplication = tornado.web.Application([\n    (r'\/websocket', WebSocket),\n])\n\nif __name__ == \"__main__\":\n    application.listen(8888)\n    tornado.ioloop.IOLoop.current().start()\n","payload_needed":false,"payload":null,"payload_status":"none","published_fix":[{"repository":"ipython\/ipython","commit_url":"https:\/\/github.com\/ipython\/ipython\/commit\/f15b821de4c43269012c87e49bc1bcd1fbe9bc6a","commit_subject":"Add Origin Checking.","units":[{"file":"IPython\/html\/base\/zmqhandlers.py","function":null}]}],"references":null}