CodeAstro Online Railway Reservation System 1.0 - Cross Site Scripting (XSS)
# Exploit Title: CodeAstro Online Railway Reservation System 1.0 - Cross Site Scripting (XSS)
# Date: 2024-08-15
# Exploit Author: Raj Nandi
# Vendor Homepage: https://codeastro.com/
# Software Link:
https://codeastro.com/online-railway-reservation-system-in-php-with-source-code/
# Version: 1.0
# Tested on: Any OS
# CVE: CVE-2024-7815
## Description:
A Cross-Site Scripting (XSS) vulnerability exists in [Application
Name/Version]. This vulnerability allows an attacker to inject and execute
arbitrary JavaScript code within the context of the user's browser session.
## Proof of Concept (PoC):
1. Navigate to [vulnerable page or input field].
2. Input the following payload: `<script>alert(document.cookie)</script>`
3. Upon execution, the script will trigger and display the user's cookies
in an alert box.
## Mitigation:
To prevent this vulnerability, ensure that all user inputs are properly
sanitized and validated before being reflected back on the webpage. CodeAstro Online Railway Reservation System 1.0 — Cross Site Scripting (XSS) (CVE-2024-7815)
This article explains the Cross-Site Scripting (XSS) vulnerability discovered in CodeAstro's Online Railway Reservation System 1.0 (CVE-2024-7815). It covers the impact, a safe proof of concept for testing in authorized environments, root cause analysis, secure coding fixes, mitigation strategies, and testing guidance for developers and defenders.
Vulnerability summary
| Item | Details |
|---|---|
| Product | CodeAstro Online Railway Reservation System |
| Version | 1.0 |
| Vulnerability | Stored / Reflected Cross-Site Scripting (XSS) |
| CVE | CVE-2024-7815 |
| Severity | High (depends on context — user privileges, persistence) |
| CWE | CWE-79: Improper Neutralization of Input During Web Page Generation |
What is XSS and why it matters
Cross-Site Scripting (XSS) allows an attacker to inject malicious JavaScript into pages viewed by other users. Successful XSS can enable session theft, account takeover, phishing, cryptomining, and client-side request forgery. For web apps handling reservations and PII (Personally Identifiable Information), such an exploit can be used to hijack sessions or perform unauthorized actions as logged-in users.
Where this vulnerability typically appears in the application
- Search or booking forms that echo user-supplied strings back to the page without encoding.
- Reservation confirmation pages that display user inputs (names, notes, special requests) directly.
- Admin pages that render stored comments or inputs from other users without sanitization.
Proof of Concept (PoC) — for authorized testing only
Only perform the following PoC on systems you own or where you have explicit permission to test. Unauthorized testing or exploitation is illegal and unethical.
Typical PoC steps:
- Navigate to an input field that is reflected back (e.g., search box, booking form comment field).
- Submit a payload that includes a script element.
- If the application reflects input without proper output encoding, the script will run in the victim's browser context.
<script>alert(document.cookie)</script>
Explanation: This payload, when reflected and executed in a victim's browser, displays cookies (including session tokens if they are accessible to JavaScript). It demonstrates that arbitrary script can run in the user context. In real testing, avoid stealing or disclosing sensitive data—use safe benign indicators (e.g., a console.log) or test-only alerts.
Root cause analysis
- The application outputs user-controlled data directly into HTML without context-aware encoding.
- Input validation may be absent or only applied incorrectly (e.g., blacklisting certain characters).
- Security headers like Content-Security-Policy (CSP) and HTTPOnly are missing or misconfigured.
Example: vulnerable PHP snippet (common pattern)
<?php
// Vulnerable: user input is echoed without encoding
$name = $_GET['name'] ?? '';
echo "Welcome, $name";
?>
Explanation: This code takes a query parameter named "name" and injects it into the HTML response directly. If a user supplies <script>...</script>, it will be rendered and executed by the browser.
Secure fix — contextual output encoding in PHP
<?php
// Safer: encode output for HTML context and enforce UTF-8
$name_raw = filter_input(INPUT_GET, 'name', FILTER_UNSAFE_RAW);
$name = htmlspecialchars($name_raw ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
echo 'Welcome, ' . $name;
?>
Explanation: htmlspecialchars() converts characters such as <, >, ", and ' to their HTML entity equivalents, preventing them from being interpreted as markup. ENT_QUOTES also encodes single quotes which is important if values are placed in HTML attributes. Using a consistent UTF-8 encoding avoids potential encoding-related bypasses. Use filter_input to centralize input handling.
When inputs are intended to contain limited HTML (e.g., formatting)
If the application must allow some HTML (rich text), use a robust whitelist-based sanitizer such as HTMLPurifier or an equivalent library rather than simple stripping. Always sanitize on output and store the canonical, sanitized form.
// Example using HTMLPurifier (pseudo-PHP)
// $config = HTMLPurifier_Config::createDefault();
// $purifier = new HTMLPurifier($config);
// $safe_html = $purifier->purify($user_submitted_html);
// echo $safe_html;
Explanation: HTMLPurifier enforces a strict allowed-set of tags and attributes and removes dangerous constructs like inline event handlers and javascript: URIs. Use libraries vetted by the community rather than home-grown regex-based sanitizers.
Additional mitigations (defense-in-depth)
- Output encoding: Always encode based on context (HTML body, attribute, JavaScript, URL, CSS). OWASP provides context-specific encoding guidance.
- Content Security Policy (CSP): Enforce a strict CSP to reduce the impact of XSS. Example header: Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-...';
- HTTPOnly and Secure cookies: Mark session cookies as HttpOnly and Secure so JavaScript cannot read them and they're sent only over HTTPS.
- SameSite cookie attribute: Use SameSite=Lax or Strict to mitigate CSRF combined attacks.
- Use templating engines/framework escaping: Modern templating engines automatically escape by default (e.g., Twig, Blade).
- Input validation: Validate inputs for expected formats and lengths. Do not rely on blacklists; prefer positive whitelists.
- Sanitize stored content: Sanitize and/or canonicalize inputs before storing if they might be rendered later.
Example: setting a CSP header in PHP
<?php
// Basic CSP example — adjust per application needs.
// Avoid 'unsafe-inline' for script-src. Prefer nonces or hashes.
header("Content-Security-Policy: default-src 'self'; script-src 'self'; object-src 'none';");
?>
Explanation: This header restricts resource loading to the same origin and disallows plugin objects. A stricter, nonce-based CSP is recommended for apps that need inline scripts.
Testing and detection
- Automated scanners: OWASP ZAP, Burp Suite, and commercial scanners can detect common reflected and stored XSS.
- Manual testing: Try context-specific payloads (HTML body, attributes, JavaScript contexts) and verify that output is encoded.
- Unit and integration tests: Add tests that assert encoding behavior for user-facing outputs.
- Code review: Look for direct echoes of user input, templating without escaping, or unsafe database storage of raw HTML.
Severity considerations and impact
Severity depends on where the XSS occurs and whether it is stored (persisting for many users) or reflected (one-time). Stored XSS against admin pages or user inboxes is particularly severe. Consider the value of affected accounts and any sensitive actions that can be performed via CSRF or session hijacking.
Responsible disclosure and remediation timeline
- Notify vendor with reproducible steps and suggested fixes.
- Coordinate disclosure to allow the vendor to patch before public disclosure.
- Apply patches and deploy security headers quickly. Communicate fixes to users.
Quick checklist for developers (practical)
- Replace raw echoing of user input with context-aware encoding.
- Use framework/template escaping by default.
- Enable CSP; avoid inline scripts where possible.
- Mark cookies as HttpOnly, Secure, and SameSite.
- Use vetted HTML sanitizers if HTML is needed.
- Add tests for encoding and XSS scenarios.
References and further reading
- OWASP XSS Prevention Cheat Sheet — practical encoding rules and examples.
- OWASP Testing Guide — how to test for injection issues.
- HTMLPurifier project — library for safe HTML sanitization.