๐ก๏ธ OWASP Top 10
Security is not a โfeatureโ to be added at the end; it is a fundamental quality of the system. A Programmer assumes the environment is hostile and implements Defense in Depth, ensuring that the failure of one security control does not lead to a total compromise.
๐๏ธ The Critical Risks (Selection)
Section titled โ๐๏ธ The Critical Risks (Selection)โ1. Broken Access Control
Section titled โ1. Broken Access ControlโThis is currently the #1 risk. It occurs when users can access resources outside of their intended permissions.
- IDOR (Insecure Direct Object Reference): Changing a URL from
/api/orders/100to/api/orders/101to see someone elseโs data. - Programmer Mitigation: Implement a centralized authorization layer. Never trust the client-side ID; always verify ownership on the server side using the session/token identity.
2. Cryptographic Failures
Section titled โ2. Cryptographic FailuresโExposure of sensitive data (PII, passwords, credit cards) due to weak encryption or lack thereof.
- Common Mistake: Using outdated algorithms like MD5 or SHA1 for passwords.
- Programmer Mitigation: Use Argon2 or bcrypt for password hashing. Ensure all data in transit is encrypted via TLS 1.3 and sensitive data at rest is encrypted with AES-256.
3. Injection (SQL, NoSQL, OS)
Section titled โ3. Injection (SQL, NoSQL, OS)โOccurs when untrusted data is sent to an interpreter as part of a command or query.
- Example:
SELECT * FROM users WHERE name = '+userInput+'. - Programmer Mitigation: Always use parameterized queries (Prepared Statements) or ORMs that handle this by default. Never concatenate strings to build queries.
๐งช Injection & Cross-Site Scripting (XSS)
Section titled โ๐งช Injection & Cross-Site Scripting (XSS)โXSS (Cross-Site Scripting)
Section titled โXSS (Cross-Site Scripting)โAn attacker injects malicious scripts into content sent to other users.
- Stored XSS: The script is saved in the DB (e.g., a comment) and executed for every user who views it.
- Reflected XSS: The script is part of a URL parameter.
- Programmer Mitigation:
- Escape by Default: Use frameworks like React or Vue that auto-escape content.
- Content Security Policy (CSP): A browser-level instruction that restricts where scripts can be loaded from.
CSRF (Cross-Site Request Forgery)
Section titled โCSRF (Cross-Site Request Forgery)โForces an authenticated user to execute unwanted actions on a web application.
- Programmer Mitigation: Use
SameSite=LockerorSameSite=Strictcookies and anti-CSRF tokens for state-changing requests (POST, PUT, DELETE).
๐ API Hardening Patterns
Section titled โ๐ API Hardening PatternsโRate Limiting & Throttling
Section titled โRate Limiting & ThrottlingโProtects against Brute Force and DoS (Denial of Service) attacks.
- Implementation: Use a sliding window algorithm (often via Redis) to limit requests per IP or per API Key.
Input Sanitization vs. Validation
Section titled โInput Sanitization vs. Validationโ- Validation: Ensuring the data follows the correct format (e.g., โIs this a valid email?โ).
- Sanitization: Cleaning the data to remove dangerous characters (e.g., removing
<script>tags). - Programmer Rule: Validate at the entry point, sanitize before use.
โ๏ธ The โSecurity Cultureโ
Section titled โโ๏ธ The โSecurity CultureโโThe Principle of Least Privilege
Section titled โThe Principle of Least PrivilegeโAn application component (e.g., a microservice) should only have the access it needs to perform its job. If the service only reads data, its DB user should not have DROP TABLE permissions.
Secrets Management
Section titled โSecrets Managementโ- Never commit secrets to Git. Use Secret Scanning in your CI/CD.
- Dynamic Secrets: Use tools like HashiCorp Vault to generate short-lived credentials that expire automatically.
๐ก Note: Security is a trade-off with Usability. A system that requires a 20-character password changed every week will lead to users writing passwords on sticky notes. Your goal is to make the secure path the easiest path for both developers and users.