Securing the Application Against Attacks
Introduction
In our previous courses, we took a deep dive into client-side validation when working on the user registration feature. However, it’s crucial to note that client-side validation can be bypassed with tools like cURL. cURL (short for “Client URL”) is a command-line utility used to transfer data to and from servers. It offers a straightforward way to send customized HTTP requests without relying on browser-based checks. Attackers can leverage cURL to deliberately circumvent client-side restrictions, emphasizing the importance of robust server-side validation. Let’s now shift our focus to the snippets part of our application and demonstrate secure server-side validation using TypeScript.
Understanding Server-Side Validation
Server-side validation is your final gatekeeper to ensure that data is clean and meets the expected requirements. Even if malicious users bypass client-side checks, robust server-side validation will stop unsafe or malformed data from compromising your application. TypeScript’s strict typing, combined with libraries like Zod, offers a structured way to define and enforce these rules.
Vulnerable Code Example
Below is a snippet of our “save snippet” endpoint. Currently, there is no server-side validation in place to verify the data contained in the request body:
Since the snippet is directly created from user input, attackers could insert malicious data (e.g., harmful scripts) into these fields.
Gaining the Token
