Application Security: Common Programming Flaws
Input Validation Errors
What: Program fails to validate or sanitize user input before processing.
Attack types:
| Attack | Mechanism | Impact |
|---|---|---|
| SQL Injection | Malicious SQL inserted into login form (e.g., ' OR '1'='1) |
Authentication bypass; data exfiltration/deletion |
| Cross-Site Scripting (XSS) | Malicious JavaScript injected into web pages | Session hijacking; credential theft; website defacement |
Prevention: - Parameterized queries and prepared statements (eliminates SQL injection) - Output encoding and HTML sanitization (prevents XSS) - Input allow-listing — validate against expected format, type, and range - OWASP ESAPI libraries for standardized secure input handling
Inadequate Error Handling
What: Unhandled exceptions expose system internals through overly detailed error messages.
Attack types:
- Information disclosure — Stack traces reveal frameworks, database types, and version numbers, enabling targeted follow-on attacks
- Directory traversal — Error messages expose directory structures; crafted paths (../../etc/passwd) access restricted files
Prevention: - Log detailed errors internally; return generic messages to users ("An error occurred") - Implement global exception handling mechanisms - Validate and sanitize all file paths server-side - Never expose database error messages to end users