Unsanitized user input in deserialization method
- Rule ID: python_lang_deserialization_of_user_input
- Languages: python
- Source: deserialization_of_user_input.yml
Description
Deserializing data from untrusted sources, like user inputs or request parameters, without proper verification is a security risk. Attackers can embed malicious code or payloads within serialized data. When your application deserializes this data without checks, it becomes vulnerable to attacks.
Remediations
- Do not deserialize data from untrusted sources directly. This can lead to security vulnerabilities.
- Do validate and sanitize all data before deserializing it. Ensure that the data is coming from a trusted source and is in the expected format.
- Do use data formats that are purely data-oriented and not tied to a specific programming language, such as JSON or XML, for serialization and deserialization. This approach minimizes the risk of executing malicious code during deserialization.
- Do use recommended safer alternatives wherever possible. For example, instead of PyYAML's
load
function, use thesafe_load
function which limits results to simple Python objects like integers or lists.yaml.safe_load(some_input) # safer alternative to PyYAML load
References
Associated CWE
OWASP Top 10
Configuration
To skip this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --skip-rule=python_lang_deserialization_of_user_input
To run only this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --only-rule=python_lang_deserialization_of_user_input