SECURE CODE REVIEW
- This is the first line of security on defense, for developers.
It is not only the duty of a bug researcher or a bug hunter to find out the vulns or threats that a code could produce, But it is most important for a developer to review the code for vulnerability production.
This is a specialized task to review an application's source code.
- First level of defense
- Identify security issues and vulns
- Almost 75% remediations happen at code reviews level
- Manula review along with automation
- It familiriases the developers with the code.
- Helps developers in saving time in the future.
- Identifying the entry and exit points in the code.
- Automated Scan (using SAST - Static Application Security Testing)
- Conduct a manual review on the reported issues by the SAST tools, and additional manual information.
- Apply the fixes, and perform a revalidation.
- Using parameterized queries
- Data whitelisting
- Encode xml specific control characters (&, ', ", <, >, )
- Disable DTD or Doctype entities to prevent XXE.
- Avoid inserting user inputs to commands executed by the OS
- Perform strict input validation and sanitization
- Different frameworks allows different set of inputs and commands to execute.
- Regex validation of values obtained from requests / APIs / Databases
- Escaping malicious characters from user inputs
- Output encoding before webpage display.
- HTTP headers added for addn. security
- X-XSS-Protection
- Content Security Policy
- Session identifiers re-generated and re-issued after every login
- Uniqueness of Session ID and validating Session ID for every incoming request
- INvalidate session after user logout both on client and the server side
- User http security header attributes for cookies and random generators for 128/256 bit long session IDs.
- Validating file name and upload
- Magic byte of the file must be validated
- Enforcing an upper limit of the file size
- Frequency of file uploads must be validated
- Upload of files must be scanned for malwares, or viruses before stored in the Database.