The independent file on technology, travel & lifeFrom Pakistan, for everywhere
Huzi Blogs.
The ArchiveSectionsSearch

Planning a trip? HTG Travels — flights, visas, hotels & Umrah, handled properly.

WhatsApp +92 317 5054959
Huzi Blogs.

An independent file on technology, travel and life — long-form guides written plainly, from Pakistan, for everywhere.

ShopMeet the Creator

Sections

  • Travel
  • Technology
  • Lifestyle
  • Programming
  • Sports
  • Linux
  • All sections

The Desk

  • The Archive
  • Search the file
  • Disclaimer & Data Privacy Policy
  • A project of huzi.pk

© 2026 blogs.huzi.pk — All rights reserved.

Set in Playfair Display & Inter

    HomeCybersecurityStory
    Cybersecurity

    The Ghost in the Browser: A Guide to XSS Prevention in 2026

    H

    By Huzi

    File #107 · 4 min read

    Cross-site scripting is a stranger standing in your living room wearing your face, telling your family to hand over the keys. The browser cannot tell the difference, because the script runs on your own domain — so it gets the cookies, the session, the DOM. The browser gives it everything.

    The quick answer: XSS arrives in three working shapes — stored, reflected and DOM-based — plus mutation XSS, which breaks hand-rolled sanitizers. The defences that hold: context-aware escaping, DOMPurify for rich text, a strict CSP with Trusted Types, and hardened cookies.

    The three faces of XSS

    Stored XSS is the worst kind: the payload is saved — in a comment, a profile field — and every visitor runs it. Reflected XSS bounces off the server through a URL parameter, arriving as a crafted link.

    DOM-based XSS never touches the server at all; it is your own JavaScript mishandling data from location.hash or postMessage. A fourth variant, mutation XSS, is why hand-rolled sanitizers keep losing: browsers re-parse "clean" HTML and it mutates into something executable.

    The vector The fix that holds
    Stored payload in a comment or profile field encode on output, in the right context
    Reflected payload in a URL parameter escape the parameter, quote every attribute
    DOM-based sinks reading location.hash or postMessage Trusted Types, so dangerous sinks refuse raw strings
    Mutation XSS DOMPurify, kept updated
    Session theft via document.cookie HttpOnly, SameSite cookies

    What a successful XSS buys the attacker

    Session hijacking, first — reading document.cookie wherever it is not marked HttpOnly. Rewriting your page into a fake login form that posts credentials elsewhere.

    Chained with an adversary-in-the-middle proxy like Evilginx, a stolen cookie sidesteps MFA entirely. In rare cases, XSS plus a browser zero-day means code running on the victim's machine.

    The impersonation has a travel twin: a cloned booking page harvesting card details works exactly like the fake login form. It is why every booking, invoice and itinerary at HTG Travel goes out in writing, on numbers you can verify.

    Escape by context

    The rule is old and absolute: never trust input. But escaping is contextual, and the right encoding for HTML body will not save you inside a script tag:

    • HTML body: entity-encode the angle brackets, ampersands and quotes
    • Attributes: quote everything, and keep user data out of event handlers
    • JavaScript: serialize safely, then escape the characters that can break out of a block
    • URLs: encode the components, allow only known-safe schemes, block javascript: outright

    Modern frameworks — React, Vue, Svelte — escape HTML context by default, which is exactly why the explicit escape hatches stand out in review.

    Pro tip: React's dangerouslySetInnerHTML, Vue's v-html and Svelte's equivalent are the hatches to flag in code review — when you must render rich text, run it through DOMPurify and keep the library updated, because mXSS bypasses get patched there regularly.

    The header that saves you anyway

    A strict Content Security Policy is the defence that keeps working when code fails. Nonces over hashes, strict-dynamic so trusted scripts can load their own dependencies, and Trusted Types to make dangerous sinks refuse raw strings:

    Content-Security-Policy:
      default-src 'self';
      script-src 'self' 'nonce-abc123' 'strict-dynamic';
      object-src 'none';
      base-uri 'self';
      frame-ancestors 'none';
      require-trusted-types-for 'script';
      trusted-types dompurify default;
    

    Then harden the cookies — HttpOnly, SameSite, and an integrity attribute on external scripts so a compromised CDN cannot quietly swap in something else.

    Impersonation is the oldest theft there is, and no sanitizer fixes the version happening to Gaza's families, who keep watching their story told by everyone except themselves. Sudan's families verify news of each other across broken networks, hunting the fake from the true — may their hardest information problems become ordinary again.

    If you shipped a fix like this under deadline, take the proper week off. We plan honeymoons, including the phase where two sets of in-laws hold strong opinions about the destination — the everyday diplomacy of HTG Travel, and we are very good at it. The working line is +92 317 5054959 for the post-release detox up north.

    Presented by

    HTG Travels — Plan the Trip, Skip the Runaround

    Flights, visas, Umrah packages and Hunza–Skardu tours, handled end to end from our licensed Sialkot desk. Real fares, hotel names in writing, and a human who answers — before you pay a rupee.

    Flights & rebooking Visa files Umrah 2026–27 Northern tours
    Visit huzi.pkWhatsApp +92 317 5054959

    Sialkot, Pakistan · Licensed agency · Fast quotes on WhatsApp


    You Might Also Like

    Handwork Embroidered Organza Party Suit 2026 | Net Dupatta & Tassels

    Handwork Embroidered Organza Party Suit 2026 | Net Dupatta & Tassels

    PKR 5550

    6-Piece Kitchen Measuring Spoons Set for Cooking & Baking – Random Color

    6-Piece Kitchen Measuring Spoons Set for Cooking & Baking – Random Color

    PKR 750

    Portable Mesh Nebulizer JSL-W302 – USB/Battery, Kid & Adult Masks

    Portable Mesh Nebulizer JSL-W302 – USB/Battery, Kid & Adult Masks

    PKR 3300

    Glamorous Handwork Embroidered Masoori Gharara Suit 2026 | Organza Dupatta

    Glamorous Handwork Embroidered Masoori Gharara Suit 2026 | Organza Dupatta

    PKR 6760

    Black Digital Chunri Lawn Unstitched 3-Piece Suit – Embroidered Chiffon Dupatta

    Black Digital Chunri Lawn Unstitched 3-Piece Suit – Embroidered Chiffon Dupatta

    PKR 5000

    Keep reading

    Related files

    Cybersecurity
    English

    The Human Operating System: A Guide to Social Engineering in 2026

    How social engineering actually works on the mind — pretexting, vishing, deepfake calls and MFA fatigue — told through real attacks, with defences that go beyond 'just don't click'.

    By HuziFile #367

    Read
    Cybersecurity
    English

    Understanding OAuth 2.0 and OAuth 2.1: A Guide to Secure Authorization in 2026

    The OAuth 2.0 authorization code flow explained step by step, why PKCE became mandatory for every client, and the mistakes — token leakage, open redirects — that break real implementations.

    By HuziFile #448

    Read
    Cybersecurity
    English

    Cybersecurity 101: A Beginner's Guide for 2026

    How attackers actually make money — phishing, credential stuffing, infostealers, deepfake calls — and why being slightly harder than the next target is the whole game.

    By HuziFile #116

    Read
    Cybersecurity
    English

    Cryptography 101: A Beginner's Guide to Digital Security in 2026

    Encryption, hashing, key exchange and the post-quantum NIST standards explained without the maths degree — plus why passkeys change everything for normal users.

    By HuziFile #108

    Read
    Cybersecurity
    English

    Linux Security Hardening 2026: The Complete Problem-Solving Guide

    A copy-paste Linux server hardening checklist for 2026: sshd_config, key-based login, firewalld, fail2ban and auditd — in the order that avoids locking yourself out.

    By HuziFile #541

    Read
    Cybersecurity
    English

    The Ultimate WordPress Security Guide 2026: Fortify Your Site Like a Cybersecurity Expert

    A WordPress-specific hardening walkthrough for 2026: wp-config keys, locking down wp-admin, plugin hygiene, killing xmlrpc.php, and backups you have actually tested.

    By HuziFile #422

    Read
    Back to the archive