E-INSUARANCE v1.0 - Stored Cross Site Scripting (XSS)
# Exploit Title: E-INSUARANCE v1.0 - Stored Cross Site Scripting (XSS)
# Google Dork: NA
# Date: 28-03-2024
# Exploit Author: Sandeep Vishwakarma
# Vendor Homepage: https://www.sourcecodester.com
# Software Link:https://www.sourcecodester.com/php/16995/insurance-management-system-php-mysql.html
# Version: v1.0
# Tested on: Windows 10
# Description: Stored Cross Site Scripting vulnerability in E-INSUARANCE -
v1.0 allows an attacker to execute arbitrary code via a crafted payload to
the Firstname and lastname parameter in the profile component.
# POC:
1. After login goto http://127.0.0.1/E-Insurance/Script/admin/?page=profile
2. In fname & lname parameter add payolad
"><script>alert("Hacked_by_Sandy")</script>
3. click on submit.
# Reference:
https://github.com/hackersroot/CVE-PoC/blob/main/CVE-2024-29411.md E-INSUARANCE v1.0 — Stored Cross‑Site Scripting (XSS) Analysis and Remediation
This article explains a stored Cross‑Site Scripting (XSS) issue reported in E‑INSUARANCE v1.0, describes the technical cause and impact, and provides practical, developer‑level mitigations and testing guidance. The intent is defensive: to help developers, administrators, and security teams remediate the vulnerability and harden applications against similar issues.
Vulnerability overview
Stored (persistent) XSS occurs when an application accepts input from a user, stores it on the server (typically in a database), and later renders that content into a web page without proper context‑aware encoding. In E‑INSUARANCE v1.0 the profile component (Firstname / Lastname fields) was observed to accept and persist HTML/JavaScript, which is then rendered back to other users or to the same user in a way that the browser executes the script.
Why this is high risk
- An attacker can inject script into stored fields that will execute in the security context of any user who views the affected page — including administrators.
- Impact ranges from session theft and account takeover to CSRF, persistent defacement, data exfiltration, and pivoting to other parts of the application.
- Stored XSS is often more severe than reflected XSS because the malicious content persists and can reach many users over time.
Technical root causes
- Lack of proper output encoding when rendering user‑supplied data into HTML.
- Insufficient server‑side validation and/or normalization of profile fields (trusting client side checks alone).
- Using direct string concatenation to build SQL queries and HTML output without using safer APIs and encoding helpers.
Example of vulnerable patterns (illustrative)
<?php
// Vulnerable: accepting POST input and storing directly
$fname = $_POST['fname'];
$lname = $_POST['lname'];
mysqli_query($conn, "UPDATE users SET fname='$fname', lname='$lname' WHERE id=" . $_SESSION['user_id']);
?>
<?php
// Vulnerable: echoing database values directly into HTML
$row = mysqli_fetch_assoc(mysqli_query($conn, "SELECT fname,lname FROM users WHERE id=" . $_SESSION['user_id']));
echo $row['fname'] . ' ' . $row['lname'];
?>
Explanation: The first block stores raw POST values into the database without validation/sanitization. The second block outputs database values directly into the HTML page without context‑appropriate encoding. If an attacker stores markup or JavaScript in those fields, it will be interpreted by the browser when the profile page is rendered.
Secure fixes and best practices
Fixes should be applied in multiple layers: input validation, safe storage practices, and context‑aware output encoding. Never rely only on client‑side filtering.
1) Use prepared statements for database updates
<?php
// Prepared statement (safe against SQL injection)
$fname = $_POST['fname'] ?? '';
$lname = $_POST['lname'] ?? '';
$stmt = $conn->prepare("UPDATE users SET fname = ?, lname = ? WHERE id = ?");
$stmt->bind_param("ssi", $fname, $lname, $_SESSION['user_id']);
$stmt->execute();
?>
Explanation: Using parameterized queries prevents SQL injection and removes the need to manually escape strings before writing to the database. It does not, by itself, prevent XSS — you still must encode/validate output.
2) Context‑aware output encoding when rendering
<?php
// When rendering into HTML body/content
echo htmlspecialchars($row['fname'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . ' ' .
htmlspecialchars($row['lname'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
// When rendering into an HTML attribute (e.g., <input value="...">)
echo '<input value="' . htmlspecialchars($row['fname'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '">';
?>
Explanation: htmlspecialchars (or equivalent framework helpers) performs HTML encoding so that characters like <, >, &, and quotes are rendered as text instead of being interpreted as markup or script. Always choose the right encoding for the context (HTML body, attribute, JavaScript string, CSS, URL).
3) Server‑side validation and normalization
- Apply whitelisting: limit allowed characters (e.g., letters, spaces, hyphens) for names where appropriate.
- Enforce sensible length limits.
- Normalize Unicode and strip control characters.
Example (simple):
<?php
// Basic whitelist validation for a "name" field
function sanitize_name($value) {
$value = trim($value);
// Allow letters, spaces, hyphens, and apostrophes only
if (preg_match("/^[\p{L}\s'-]{1,60}$/u", $value)) {
return $value;
}
return ''; // or handle as validation error
}
$fname = sanitize_name($_POST['fname'] ?? '');
$lname = sanitize_name($_POST['lname'] ?? '');
?>
Explanation: Whitelisting reduces the risk surface by rejecting unexpected characters. The above regex uses Unicode letter class (\p{L}) and enforces a maximum length.
4) Deploy defensive HTTP headers
<?php
// Example Content Security Policy (CSP) — tune to site needs
header(\"Content-Security-Policy: default-src 'self'; script-src 'self'; object-src 'none';\");
// Make cookies safer
// session_set_cookie_params(['httponly' => true, 'secure' => true, 'samesite' => 'Lax']);
?>
Explanation: CSP can limit the ability of injected scripts to execute or to load external resources, and cookie flags protect session cookies from access by JavaScript. CSP should be tested carefully to avoid breaking legitimate functionality.
Additional mitigations
- Use framework templating engines that auto‑escape output (and understand how to disable it safely when necessary).
- Store and display user content as data rather than HTML; if rich text is required, use a secure HTML sanitizer (e.g., OWASP Java HTML Sanitizer, HTMLPurifier for PHP) with a strict allowlist.
- Log and monitor profile changes and unusual payloads; add alerts for suspicious input patterns.
- Perform periodic automated scanning (SAST/DAST) and manual code review focusing on output encoding.
Detection and safe testing guidance
Testing for XSS should be performed only in authorized environments (development, staging, or an explicitly permitted testing instance). Automated tools such as OWASP ZAP and Burp Suite can help identify stored XSS, and manual review should focus on places that persist user input and later render it.
When validating fixes, use benign, non‑malicious test payloads and ensure you have permission. Use escaped representations when documenting tests (e.g., <script>alert('x')</script> shown as text) rather than distributing active exploit strings in public systems.
Impact assessment and risk management
| Item | Details |
|---|---|
| Product | E‑INSUARANCE v1.0 |
| Vulnerability | Stored Cross‑Site Scripting (XSS) |
| CVE / Reference | CVE‑2024‑29411 (reference repository and PoC publicly recorded) |
| Severity | High — persistent XSS can lead to account takeover, data exfiltration, and admin compromise |
Recommended remediation timeline
- Immediate: Apply output encoding to all places that render user‑supplied profile values.
- Short term (days): Add server‑side validation, prepared statements, and CSP headers.
- Medium term (weeks): Conduct an application‑wide audit for other stored XSS sinks and deploy automated scanning in CI/CD.
Developer checklist
- Use parameterized queries for all database operations.
- Encode output according to rendering context (HTML, attribute, JS, CSS, URL).
- Whitelist input where practical; enforce reasonable length limits.
- Use a secure sanitizer for any allowed rich HTML input.
- Deploy CSP and secure cookie attributes.
- Test fixes in an isolated environment before deploying to production.
References and further reading
- OWASP XSS Cheat Sheet — practical encoding and sanitization guidance.
- OWASP Top Ten — XSS is covered under injection/insufficient output encoding topics.
- Project documentation and commit history for the application (vendor files / SourceCodester link).
Applying defense‑in‑depth — strict input validation, prepared statements, context‑aware output encoding, and runtime protections like CSP — will mitigate stored XSS and significantly reduce the risk of exploitation across the application.