Secure Coding is the art of writing codes with a security-first mindset.
SecDevOps is such a buzzword these days that I am sure you have encountered it a couple of times. While this article is not about SecDevOps, a three-way handshake between security, development, and operations, it narrows down to how to put on your security helmet while writing codes: secure coding.
As cyber threats and attacks continue to increase, it is extremely important to prioritize security when building applications. Secure coding helps prevent potential attacks and vulnerabilities.
This article comprises of two parts:
- Common Software Vulnerabilities and mitigations
- Secure Coding Best Practices
If you are familiar with software vulnerabilities, skip to the Secure Coding Best Practices part.
Common Software Vulnerabilities
Vulnerabilities are loopholes in software programs. The goal of a threat actor is to find and exploit these vulnerabilities, thereby launching successful attacks on software applications. Understanding these vulnerabilities is the first step to secure coding.
1. SQL Injection
Structured Query Language (SQL) is a standard programming language used to manage and manipulate data stored in relational databases. SQL queries can perform basic create, read, update, and delete (CRUD) functions. SQL Injection occurs when an attacker injects a malicious SQL query into an application through input data.
The developer has created an input field to receive data that is run backend to either carry out a post to or pull from the database. Instead of performing the intended operation, the input data adds, modifies, reads, or deletes data from the database or, worse still, shuts down the database itself.
Example of a vulnerable SQL code:
SELECT * FROM users WHERE email = 'input_value';
Below is an SQL Injection to exploit the above vulnerability
' OR '1'='1
With the above as an input, the query becomes
SELECT * FROM users WHERE email = '' OR '1'='1';
Now, because '1'='1'
will always be true, the attacker can read all the data in the users
table. This can result in data exfiltration.
SQL Injection Mitigations
- Proper input validations: This ensures the input conforms to the required format.
- Escaping special characters: The special characters useful in SQL Injections include but are not limited to,
'
,"
,--
,=
,;
,