Diagnostic playbook
Stored XSS via guestbook name field
Web / Cross-Site Scripting
Knowledge identity
Definition and taxonomy
Summary
Persistent (stored) cross-site scripting where a comment/name submitted once is stored in the database and re-rendered without encoding for every future page view.
Severity rationale
Demonstrated persistent injection: attacker-supplied HTML/script stored in the guestbook table and reflected unencoded to every subsequent viewer of the page. Persistent cross-user impact in a real app (session theft, defacement). Confirmed in authorized local lab only.
Aliases
Persistent XSS, Second-order XSS
Standards
CWE-79 CAPEC-592 A03:2021-Injection
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
1. First Signal
What should make an agent suspicious
Symptoms
A payload submitted once reappears raw in the page on a subsequent GET; a unique marker is visible to other sessions/viewers; name field reflects <IMG onerror=...> verbatim at medium/high while message field sanitizes it.
Prerequisites
Authorized lab session. A field is stored in the DB and re-rendered without context-aware encoding.
2. Recognition Logic
How to recognize this next time
If a value persists across page loads and appears unencoded in HTML, it is stored XSS. If message is sanitized but name is not, each field needs its own output-encoding check.
3. Diagnostic Procedure
Safe checks, in order
- Confirm authorized scope. 2. Submit a unique marker into each field. 3. Reload the page and check for raw reflection. 4. Confirm persistence across a fresh session. 5. Use inert payloads. 6. Record which fields are sanitized vs not.
4. Proof
Evidence
DVWA xss_s: low message <script>alert(1)</script> stored and re-rendered raw; medium and high name field stored <IMG SRC=x onerror=alert(1)> raw while message was strip_tags+htmlspecialchars sanitized.
5. Controls
Negative checks
message field at medium/high had tags stripped and encoded (sanitized control); a benign text entry never produced HTML.
6. Avoid Bad Memory
False positives and traps
Reflection of plain text is not XSS. Encoding in some fields but not others means only the unencoded field is vulnerable.
7. Why It Matters
Impact
Any user who views the guestbook executes the stored payload. Persistent impact across all visitors of the page.
8. Why It Happened
Root cause
Input stored in DB without output encoding on display; sanitization applied inconsistently across fields (message sanitized, name not).
9. Fix
Remediation and prevention
Apply context-aware output encoding on every stored value at render time. Use consistent encoding for all fields. Consider CSP as defense-in-depth.
10. Re-test
Verification steps
- After fix, submit markers to both fields and confirm page source shows encoded entities. 2. Reload and confirm encoding persists. 3. Add regression test asserting no raw HTML in guestbook output.
Reference
Tools and sources
Tools used
curl for submit+verify, docker exec for read-only source review
References
OWASP XSS Prevention Cheat Sheet; CWE-79; PortSwigger Stored XSS
Intelligence
Products and history
Technologies
PHP, MariaDB, HTML, browser
Affected products / versions
DVWA (Damn Vulnerable Web Application) current master
History
First documented in DVWA xss_s module low/medium/high in the 2026-08 benchmark run.
Exploit knowledge
Variants and references
Attack surface
Guestbook comment/message and name inputs stored in DB and echoed into the guestbook page HTML
Exploit maturity
proof-of-concept
Known variants
Stored script tag (low), stored event-handler in name field with message htmlspecialchars-encoded (medium/high), second-order XSS where data is stored then reflected later
Defensive signatures
Comments/guestbook entries whose values appear unencoded in subsequent page loads, event-handler attributes in stored fields, marker payload persisting across sessions
Reproduction commands
Low (message stored unencoded): curl -s -b $JAR -d 'txtName=probe&mtxMessage=<script>alert(1)</script>&btnSign=Sign+Guestbook' http://127.0.0.1:4280/vulnerabilities/xss_s/ curl -s -b $JAR http://127.0.0.1:4280/vulnerabilities/xss_s/ # entry re-rendered with <script> Medium (name vulnerable, message sanitized): curl -s -b $JAR -d 'txtName=<IMG SRC=x onerror=alert(1)>&mtxMessage=safe&btnSign=Sign+Guestbook' http://127.0.0.1:4280/vulnerabilities/xss_s/ High (name regex strips script only): curl -s -b $JAR -d 'txtName=<IMG SRC=y onerror=alert(2)>&mtxMessage=safe&btnSign=Sign+Guestbook' http://127.0.0.1:4280/vulnerabilities/xss_s/
Exploit references
No external references stored; all evidence from the authorized local lab.
Case provenance