ITZone

Common vulnerabilities and practices for safe programming in web application development (P1)

1. Control database queries to avoid SQL Injection vulnerabilities

– Risk: When querying the database, programmers often use the input string from users, these queries may be affected by SQL Injection or HQL Injection (if using Hibernate). By taking advantage of these errors, an attacker can view, edit, delete data in the database, thereby gaining admin accounts, stealing user information, etc.

– Prevention:

Example 2: Some cases cannot prevent SQL Injection errors through the “order by” command. Because the setParam function cannot be used, the following method can be used:

Maybe you are interested

67 useful tools, libraries and resources to save time for web developers

From MVC to the Modern Web Framework

2. Processing input data to avoid XSS vulnerability

– Risk: The server results returned to users mainly in HTML. The returned content usually includes values ​​that users enter into the system that may suffer XSS errors if they do not control the input data. XSS (Cross-Site Scripting) is a technique of attack by inserting into dynamic websites (JSP, ASP, PHP …) HTML tags or dangerous scripts that can be harmful to other users. In particular, the dangerous code inserted is mostly written in Cross-Site Scrip such as JavaScript, JScript, DHTML and also HTML tags.

– Prevention:

Example 1: The JSP page below shows the greeting with the username taken from the client

I would like to pause the article here! In the following article, I will continue with “Using tokens to avoid CSRF vulnerabilities” and “Controlling file uploads to the system.”

Viblo

Share the news now