• Type: Language-Specification
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Impact:
      Unknown 'null' severity
    • Likelihood:
      Unknown 'null' severity


      User provided data such as URL parameters, POST data payloads or cookies should always be considered untrusted and tainted. Deserialization based on data supplied by the user could result in two types of attacks:

      • Remote code execution attacks, where the structure of the serialized data is changed to modify the behavior of the object being unserialized.
      • Parameter tampering attacks, where data is modified to escalate privileges or change for example quantity or price of products.

      The best way to protect against deserialization attacks is probably to challenge the use of the deserialization mechanism in the application. They are cases were the use of deserialization mechanism was not justified and created breaches (CVE-2017-9785).

      If the use of deserialization mechanisms is valid in your context, the problem could be mitigated in any of the following ways:

      • Since the pickle module is not secure, never use it to deserialize untrusted data.
      • Only use the PyYAML module with the default safe loader.
      • Instead of using a native data interchange format, use a safe, standard format such as untyped JSON or structured data approaches such as Google Protocol Buffers.
      • To ensure integrity is not compromised, add a digital signature (HMAC) to the serialized data that is validated before deserialization (this is only valid if the client doesn't need to modify the serialized data)
      • As a last resort, restrict deserialization to be possible only to specific, whitelisted classes.

      Noncompliant Code Example

      from flask import request
      import pickle
      import yaml
      def pickle_loads():
          file = request.files['pickle']
          pickle.load(file) # Noncompliant; Never use pickle module to deserialize user inputs
      def yaml_load():
          data = request.GET.get("data")
          yaml.load(data, Loader=yaml.Loader) # Noncompliant; Avoid using yaml.load with unsafe yaml.Loader 

      Compliant Solution

      from flask import request
      import yaml
      def yaml_load():
          data = request.GET.get("data")
          yaml.load(data) # Compliant;  Prefer using yaml.load with the default safe loader 




            • Assignee:
              pierre-loup.tristant Pierre-Loup Tristant
            • Votes:
              0 Vote for this issue
              1 Start watching this issue


              • Created: