The browser cannot tell which bytes you meant as data and which bytes the server assembled into code. Ask where the value crosses into HTML, an attribute, a URL or a JavaScript context.
XSS is a context failure. The server or client inserts untrusted data into a document without encoding for the exact sink, so the browser parses it as markup or script. The payload does not need to be clever; it only needs to land in the wrong grammar.
- Find the controlled injection point
- Build a payload that runs in the bot's browser
- Read /admin from the same origin and send it to /collect
- Capture the flag
Server data to HTML body
Where to look before you type a payload
The attacker controls a query parameter, stored field, fragment, postMessage or third-party response.
The application concatenates, escapes for the wrong context, sanitizes with a regex or writes to a DOM property.
The browser parses the result as HTML, an attribute, a URL or JavaScript and creates an execution context.
Script runs with the origin of the vulnerable page, not the attacker's origin.
Open one hint at a time. The first two build the model; the last two point at the boundary.
Hint 1
Find the exact sink where the value appears.
Hint 2
Identify whether the sink is HTML body, an attribute, a URL or a DOM property.
Hint 3
The preview writes location.hash with innerHTML. Use an image onerror payload.
Hint 4 · near the answer
A same-origin fetch can read /admin; exfiltrate its text with encodeURIComponent to /collect.
Observe → Hypothesize → Test → Prove → Explain
This is the same loop a reviewer expects in a report. Your draft stays in this browser; nothing is submitted until you choose to export it.
Evidence log
Write for a reviewer who was not in the room. Every claim needs a request, response or state change behind it.
Preview the evidence report
# Lab evidence report — Theme Hash Sink
- Family: Cross-Site Scripting
- Lab ID: web-xss-theme-preview
- Date: 2026-12-05
## Workflow
### Observe
- [ ] Open "Theme Hash Sink" and record /theme, the HTTP method and the role you are given.
- [ ] List every parameter, header, cookie and object identifier the normal flow exposes.
- [ ] Save a baseline response: status, body shape, timing and the fields that change by user.
### Hypothesize
- [ ] Name the server decision that protects /theme, and the evidence it should use.
- [ ] Use the clue as a constraint, not an answer: The bot has an HttpOnly admin session. A same-origin fetch('/admin') can read the secret, then fetch('/collect?d='+encodeURIComponent(secret)).
- [ ] Predict the exact status, body or state change that would prove the decision is missing.
### Test
- [ ] Start from the baseline and change one value: the theme sink.
- [ ] Keep the request replayable; vary encoding, method or identifier location only after the first result.
- [ ] Capture the full request and response for the winning attempt, including the flag.
### Prove
- [ ] Capture the flag and name the exact foreign object, role or state change it proves.
- [ ] Repeat from a clean session and confirm the result is not cached or stale.
- [ ] State impact precisely: what data or action did you actually obtain?
### Explain
- [ ] State the root cause without naming the payload: which decision failed?
- [ ] Name the control that prevents recurrence and the layer where it belongs.
- [ ] Write one regression test that fails before the fix and passes after it.
## Evidence
### Target and baseline
_Not recorded._
### Hypothesis
_Not recorded._
### Winning request
_Not recorded._
### Proof
_Not recorded._
### Root cause
_Not recorded._
### Control and regression test
_Not recorded._
## Analyst conclusion
The proof demonstrates the missing control above. The regression test should fail against the vulnerable behavior and pass after remediation.
The full request, the reasoning and the debrief unlock after a successful capture. That is deliberate: struggle first, then consolidate.
False positives to rule out
- The payload appears in the response but is HTML-encoded: reflection is not execution; verify in a browser.
- An alert is blocked by CSP: try a different sink or check whether the policy can be bypassed; a blocked alert alone does not prove safety.
- The server strips script tags but leaves event handlers: test attributes, URLs and DOM sinks separately.
Regression tests to name
- Reflected body: The response shows literal text and the browser executes no script
- Attribute context: The attribute stays intact and no handler executes
- Stored content: The sanitizer removes the handler or the browser refuses execution
- Encode for the exact output context, preferably with a context-aware templating engine.
- Use a strict Content Security Policy and Trusted Types where the application supports them.
- Sanitize rich HTML with a maintained allowlist library, never with a regex.
- Keep session cookies HttpOnly and test the actual browser execution path.
XSS ليست مشكلة اقتباسات، بل مشكلة سياق: المتصفح يقرأ ما كتبه الخادم كـHTML أو JavaScript. الترميز يجب أن يناسب مكان الظهور، والاختبار يجب أن يجري في متصفح حقيقي.