give me 5 question about security that elevatn to reveiw sorce code and coding
- User
give me 5 question about security that elevatn to reveiw sorce code and coding
- Assistant
Here are 5 crucial questions to ask when reviewing source code and coding practices for security:
1. Input Validation and Sanitization: "Are all user-inputs (e.g., params, queries, forms) thoroughly validated, sanitized, and encoded to prevent injection attacks (SQL, XSS, command injection), and do logs properly distinguish between user-supplied and trusted data?"
- Look for:
- Whitelisting approaches (e.g., precise regex patterns) instead of blacklisting.
- Consistent use of escaping/encoding mechanisms (e.g., HTML escaping, parameterized queries).
- Separation of concerns: validation, sanitization, and business logic.
2. Authentication, Authorization, and Session Management: "Are authentication mechanisms robust, and do access controls (authorization) properly enforce least privilege, with secure session handling and timely revocation of compromised or expired credentials?"
- Inspect:
- Password storage (e.g., bcrypt, Argon2, PBKDF2) and hashing practices.
- JWT/token generation, validation, and secure storage (e.g., HTTPS, secure cookies).
- Role-based access control (RBAC) implementation, with clear segregation of duties.
3. Sensitive Data Protection and Encryption: "Is sensitive data (e.g., PII, secrets, encryption keys) properly encrypted at rest and in transit, with secure key management, and are cryptographic primitives used correctly and up-to-date?"
- Verify:
- Data encryption schemes (e.g., AES, TLS 1.3) and key lengths (e.g., 256-bit).
- Secure key generation, rotation, and storage (e.g., KMS, HSM).
- Correct usage of cryptographic libraries and avoidance of deprecated algorithms (e.g., MD5, SHA-1).
4. Error Handling, Logging, and Incident Response: "Do error handling and logging mechanisms balance security (e.g., minimal info disclosure) with debuggability, and are incident response plans and procedures well-documented, regularly exercised, and aligned with compliance requirements?"
- Evaluate:
- Error messages: informative for devs, opaque for attackers (no sensitive data leaks).
- Log format, retention, and analysis (e.g., SIEM integration) for timely threat detection.
- Incident response playbooks, including containment, notification, and post-incident review.
5. :
- Look for: