Security

Web & Application Attacks: SQL Injection, XSS, CSRF, SSRF, LFI & RFI Explained

By Razi Digi5 min read

The modern internet is powered by millions of websites, mobile applications, APIs, and cloud platforms. Whether you're shopping online, transferring money through internet banking, booking airline tickets, or accessing government portals, you're interacting with web applications. Unfortunately, web applications are among the most frequently targeted assets in cyber security because they often process sensitive information such as usernames, passwords, payment details, customer records, and business data. Unlike malware that infects individual computers, web attacks exploit weaknesses in application code, databases, APIs, and server configurations — and a single vulnerability can expose millions of users' personal information.

Why Are Web Applications Frequently Attacked?

Every web application processes user input — login forms, search boxes, contact forms, payment pages, registration forms, file upload portals, comment sections, and API requests. If developers fail to properly validate that input, attackers can manipulate the application to steal databases, hijack user accounts, execute malicious scripts, read confidential files, or control servers.

OWASP Top 10

The Open Worldwide Application Security Project (OWASP) publishes the industry's most recognized list of web application security risks, including broken access control, cryptographic failures, injection attacks, insecure design, security misconfiguration, vulnerable components, authentication failures, software integrity failures, logging failures, and server-side request forgery. Developers worldwide use it as a guide for building secure applications.

1. SQL Injection (SQLi)

SQL Injection is one of the oldest and most dangerous web application attacks. It occurs when attackers insert malicious SQL commands into user input fields that interact with a database. Instead of normal data, attackers send specially crafted commands that manipulate database queries. If user input isn't validated, an attacker may change the intended query, potentially bypassing authentication or exposing sensitive records.

Attackers can read confidential databases, delete records, modify customer information, create administrator accounts, bypass authentication, steal passwords, and execute administrative database commands. Types include classic SQL injection, blind SQL injection (inferring information from application behavior), time-based SQL injection (using response delays), and error-based SQL injection (using database error messages).

Prevention: use prepared statements (parameterized queries), validate all user input, escape special characters, apply least-privilege database permissions, use Web Application Firewalls (WAF), and regularly perform security testing.

2. Cross-Site Scripting (XSS)

XSS occurs when attackers inject malicious JavaScript into a trusted website. When another user visits the affected page, the malicious script executes within their browser. Unlike SQL injection, XSS primarily targets website visitors rather than the server. Attackers may steal session cookies, hijack accounts, redirect users to fake websites, display fake login forms, modify page content, and capture user input.

Stored XSS permanently stores malicious scripts on the server, such as in comments or forum posts, so every visitor executes the script. Reflected XSS immediately reflects the script in the application's response, usually via specially crafted links. DOM-based XSS exists entirely within client-side JavaScript, with no server-side modification required.

Prevention: sanitize user input, encode output properly, implement Content Security Policy (CSP), validate data before displaying it, and use secure JavaScript frameworks.

3. Cross-Site Request Forgery (CSRF)

CSRF tricks authenticated users into performing unwanted actions without their knowledge. The victim is already logged into a trusted website, then is convinced to visit a malicious webpage whose hidden code automatically sends unauthorized requests using the victim's active session. Example: a victim logged into online banking clicks an attractive link, and the page silently submits a money transfer request. Potential impact includes unauthorized payments, password changes, email changes, data deletion, and account modifications.

Prevention: implement CSRF tokens, SameSite cookies, re-authentication for sensitive actions, user confirmation dialogs, and session expiration.

4. Server-Side Request Forgery (SSRF)

SSRF occurs when attackers manipulate a server into making requests on their behalf. Instead of attacking users, SSRF targets backend servers, letting attackers access internal systems, retrieve cloud metadata, scan private networks, bypass firewalls, and reach services not accessible from the internet. Example: a website allows users to submit image URLs, and an attacker submits an internal network address instead, causing the server to retrieve confidential internal information.

Prevention: validate URLs, block internal IP addresses, restrict outbound server requests, use allowlists, and segment internal networks.

5. Local File Inclusion (LFI)

LFI allows attackers to force an application to load files from the local server, potentially reading password files, configuration files, application source code, and system logs. Example: a page loads content based on a user-supplied filename, and without input validation an attacker manipulates the path to access sensitive server files. Risks include information disclosure, configuration exposure, credential leakage, and in some scenarios remote code execution.

Prevention: validate filenames, restrict directory access, disable unnecessary file inclusion functions, and apply least privilege.

6. Remote File Inclusion (RFI)

RFI allows attackers to instruct the application to load malicious files hosted on external servers, which then execute on the vulnerable server — potentially leading to complete server compromise, malware installation, website defacement, remote command execution, and data theft. Prevention: disable remote file inclusion where unnecessary, validate all file paths, restrict URL-based includes, and keep applications updated.

Comparing Web Application Attacks

SQL Injection targets the database to steal or manipulate data. XSS targets website visitors to execute malicious scripts. CSRF targets authenticated users to force unauthorized actions. SSRF targets the backend server to access internal resources. LFI targets local server files to read confidential files. RFI targets the web server to execute remote malicious code.

Best Practices for Secure Web Applications

Validate and sanitize all user input. Use parameterized database queries. Encode output to prevent XSS. Implement CSRF protection tokens. Apply least-privilege access controls. Keep frameworks and libraries up to date. Conduct regular penetration testing. Use secure coding standards. Deploy a Web Application Firewall. Continuously monitor logs and suspicious activity.

Key Takeaways

Web applications are among the most common targets for cyber attacks. SQL Injection targets databases and can expose or alter sensitive data. XSS injects malicious scripts affecting visitors. CSRF abuses authenticated sessions. SSRF manipulates servers into accessing internal resources. Local and Remote File Inclusion can expose sensitive files or lead to server compromise. Secure coding practices, regular testing, and layered defenses are essential.

← Back to all articles