Security
Security is not a feature; it's a mindset.
CIA Triad
- Confidentiality: Only authorized users can access data.
- Integrity: Data is accurate and trustworthy.
- Availability: Data is accessible when needed.
Authentication (AuthN) vs Authorization (AuthZ)
- AuthN: "Who are you?" (Passwords, MFA, OAuth).
- AuthZ: "What are you allowed to do?" (RBAC, ABAC, ACLs).
OWASP Top 10 (The Classics)
- Injection: SQL Injection, Command Injection. Fix: Prepared statements, input validation.
- Broken Authentication: Weak passwords, session hijacking. Fix: MFA, strong session management.
- Sensitive Data Exposure: Plaintext passwords, exposed keys. Fix: Encryption at rest/transit.
- XXE (XML External Entities): Malicious XML. Fix: Disable external entities.
- Broken Access Control: User A accessing User B's data. Fix: Server-side checks.
- Security Misconfiguration: Default passwords, verbose error messages.
- XSS (Cross-Site Scripting): Injecting scripts into client pages. Fix: CSP, output encoding.
- Insecure Deserialization: Executing code via serialized objects.
- Using Components with Known Vulnerabilities: Old libs. Fix:
npm audit, Dependabot. - Insufficient Logging: Not knowing you were hacked.
Cryptography Basics
Symmetric Encryption
- Same key for encryption and decryption.
- Fast.
- Algorithms: AES, ChaCha20.
- Problem: Key distribution.
Asymmetric Encryption (Public Key)
- Public key encrypts, Private key decrypts.
- Slow.
- Algorithms: RSA, ECC (Elliptic Curve).
- Use Case: TLS Handshake, SSH, Signing.
Hashing
- One-way function. Cannot be reversed.
- Use Case: Storing passwords (with salt), Integrity checks.
- Algorithms: SHA-256, Argon2 (for passwords).