Python Secure Coding
Language | Insecure Function/Practice | Vulnerability | Scenario | Remediation/Secure Function |
---|---|---|---|---|
Python |
| Code Injection | A web application executes user input as code using | Avoid using |
Python |
| Code Injection | A web application executes user input as code using | Avoid using |
Python | SQL queries without parameterized queries | SQL Injection | A web application constructs SQL queries using user input without parameterized queries. | Use parameterized queries with libraries like |
Python |
| Code Injection | In Python 2.x, | Use |
Python |
| Command Injection | A web application constructs shell commands using user input with | Use |
Python |
| Insecure Deserialization | A web application deserializes untrusted data using | Avoid using |
Python |
| Path Traversal | A web application opens files using paths derived from user input without validation. | Validate and sanitize file paths, use a whitelist of allowed paths |
Python |
| Insecure SSL Configuration | A web application makes HTTP requests without verifying SSL certificates. | Use |
Python | Logging sensitive information | Information Exposure | Sensitive information like passwords or tokens is logged. | Avoid logging sensitive information, use redaction if necessary |
Python |
| Cross-Site Scripting (XSS) | A Flask application returns user input directly in JSON responses without validation. | Validate and sanitize input, use proper encoding functions |
Python | Unrestricted file upload | Unrestricted File Upload | A web application allows users to upload files without validation, leading to remote code execution or malware injection. | Validate file types, use a whitelist of allowed file types, scan for malicious content |
Python |
| Insecure Deserialization | A web application deserializes untrusted data using | Use |
Python |
| Format String Vulnerability | A web application uses | Use f-strings or validate and sanitize input before using |
Python |
| JSON Injection | A web application processes untrusted JSON data without validation. | Validate and sanitize JSON input before processing |
Python | Using default | Weak Secret Key | A Flask application uses the default secret key for session management. | Generate and use a strong, unique secret key for each application |
Last updated