Code Review Examples
Common Culprits
Vulnerability | Language | Vulnerable Code | Reason for Vulnerability | Fixed Code | Reason for Fix |
---|---|---|---|---|---|
RCE | PHP |
| Directly executing user input |
| Whitelist of allowed commands |
SQLi | PHP |
| Direct inclusion of user input in SQL |
| Parameterized query |
SQLi | Java |
| String concatenation in SQL |
| Use of PreparedStatement |
SQLi | Python |
| String formatting in SQL |
| Parameterized query |
XSS | PHP |
| Direct output of user input |
| Encoding special characters |
XSS | Java |
| Unescaped data in HTML |
| Using encoding library |
XSS | Python |
| Unescaped data in HTML |
| Using escape function |
CSRF | PHP |
| No CSRF token check |
| Validating CSRF token |
CSRF | Java |
| No CSRF protection |
| Using CSRF protection annotation |
CSRF | Python |
| No CSRF protection |
| Using CSRF protection decorator |
Insecure Deserialization | PHP |
| Deserializing user input |
| Using JSON instead of serialized data |
Insecure Deserialization | Java |
| Deserializing without checks |
| Implementing a custom ObjectInputStream with class whitelist |
Insecure Deserialization | Python |
| Using pickle for deserialization |
| Using JSON instead of pickle |
XXE | PHP |
| No entity restriction | `$dom = new DOMDocument(); $dom->loadXML($xml, LIBXML_NOENT | LIBXML_DTDLOAD);` |
XXE | Java |
| Default DocumentBuilderFactory settings |
| Enabling secure processing feature |
XXE | Python |
| Default XML parsing |
| Disabling entity resolution |
SSRF | PHP |
| No URL validation |
| Whitelist of allowed hosts |
SSRF | Java |
| No URL validation |
| Validating host against whitelist |
SSRF | Python |
| No URL validation |
| Custom URL validation function |
Path Traversal | PHP |
| No path validation |
| Using basename to remove directory traversal |
Path Traversal | Java |
| No path normalization |
| Path normalization and validation |
Path Traversal | Python |
| No path validation |
| Path normalization and validation |
Command Injection | PHP |
| Unsanitized input in system command |
| Escaping shell arguments |
Command Injection | Java |
| Unsanitized input in command |
| Using ProcessBuilder with arguments |
Command Injection | Python |
| Unsanitized input in system command |
| Using subprocess with arguments |
IDOR | PHP |
| No access control check |
| Implementing access control |
IDOR | Java |
| No access control check |
| Implementing access control |
IDOR | Python |
| No access control check |
| Implementing access control |
NoSQL Injection | PHP |
| Direct use of user input in query |
| Using regex for exact match |
NoSQL Injection | Java |
| Direct use of user input in query |
| Using regex for exact match |
NoSQL Injection | Python |
| Direct use of user input in query |
| Using regex for exact match |
Buffer Overflow | C |
| No bounds checking |
| Using bounded string copy |
Programming Language | Function | Possible Vulnerability | Vulnerable Scenarios | Remediation |
---|---|---|---|---|
PHP |
| Code Injection | When user-controlled input is directly passed to | Avoid using |
| Code Injection | When user-controlled input is directly passed to | Avoid using | |
| Command Injection | When user-controlled input is directly passed to these functions | Use proper input validation and parameterization. Sanitize user input | |
| File Inclusion | When user-controlled input is used without proper validation | Validate and sanitize user input for the included/required file path | |
| Deserialization Vulnerabilities | When untrusted data is deserialized without proper validation | Implement proper input validation and utilize safe unserialization methods | |
Python |
| Deserialization Vulnerabilities | When untrusted YAML data is deserialized without proper validation | Implement proper input validation and utilize safe deserialization methods |
JavaScript |
| Cross-Site Scripting (XSS) | When user-controlled input is used without proper sanitization | Properly sanitize and validate user input before using it in |
Ruby |
| Command Injection | When user-controlled input is directly passed to these functions | Use proper input validation and parameterization. Sanitize user input |
| Deserialization Vulnerabilities | When untrusted data is deserialized without proper validation | Implement proper input validation and utilize safe deserialization methods | |
| Deserialization Vulnerabilities | When untrusted YAML data is deserialized without proper validation | Implement proper input validation and utilize safe deserialization methods |
Last updated