Files
Sachin SharmaandClaude Opus 4.7 e9daf3ccbb Phase 3.1: Playwright browser-execution harness — closes 2 gaps + corrects 1 Phase 2F overclaim
Real headless Chromium executes payloads against the lab; harness reads DOM
state and navigation chains to confirm what only-source-verification missed.

Verified live:

- TEST 28a — DOM XSS via alert dialog: payload <img src=x onerror=alert(...)>
  in location.hash → innerHTML sink. Chromium fired the alert with our
  message ("xss-via-playwright-2026"). DOM XSS confirmed at execution time,
  not just at sink shape.

- TEST 28b — DOM XSS via window variable: payload sets
  window.bughunter_xss_executed = true; harness reads it back via
  page.evaluate(). PASS. Robust pattern when CSP/popup-blocker would
  suppress dialogs.

Phase 2F correction (real verification finding):

- TEST 29 — OAuth @-userinfo bypass. Phase 2F Test 14 Attack B claimed
  redirect_uri=https://acme.example/@evil.com/ would land the auth code
  on evil.com against a server with prefix https://acme.example/ (trailing
  slash). Playwright shows this is WRONG against that specific lab:
  WHATWG URL parsing puts the @ in the PATH section once there's a `/`
  before it. Browser stays on acme.example.

- The vulnerability class is real — the @-userinfo bypass works when the
  prefix has NO trailing slash (verified by retest: browser navigated to
  evil.attacker.example with DNS failure as the only blocker). Updated
  Phase 2F doc with the correction + added a Browser-parse vs
  server-parse table to hunt-oauth covering the four redirect_uri attack
  shapes, when each works, and why headless-testing the final navigation
  is required before claiming an OAuth chain → ATO.

Closes the "source-verified only" gap from Phase 2 by providing a real
browser harness. Future stored-XSS / open-redirect / CSRF SameSite tests
can use the same pattern.

Lab + harness shipped at docs/verification/phase3-playwright/.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 14:45:38 +05:30

103 lines
3.1 KiB
Python

"""
Phase 3 target app — exhibits two browser-side vulnerabilities for Playwright verification:
1. /dom-xss — DOM XSS via location.hash → innerHTML sink
2. /oauth/authorize — OAuth prefix-match validation + @-userinfo bypass
3. /oauth/callback — attacker-controlled landing (logs the auth code)
"""
import time
import secrets
from flask import Flask, request, jsonify, redirect, make_response
app = Flask(__name__)
# ============================================================
# DOM XSS sink — classic location.hash → innerHTML pattern
# (mirrors Juice Shop / many SPA vulns where the URL fragment
# is read at page load and inserted into the DOM unsanitized)
# ============================================================
DOM_XSS_PAGE = """<!doctype html>
<html>
<head><title>Phase 3 DOM-XSS target</title></head>
<body>
<h1>Search results</h1>
<div id="result">No search yet.</div>
<script>
// Vulnerable sink: read location.hash, drop into innerHTML
// This is the canonical DOM XSS pattern from hunt-xss
const fragment = decodeURIComponent(window.location.hash.slice(1));
if (fragment) {
document.getElementById('result').innerHTML = 'You searched for: ' + fragment;
}
</script>
</body>
</html>
"""
@app.route("/dom-xss")
def dom_xss():
resp = make_response(DOM_XSS_PAGE)
resp.headers["Content-Type"] = "text/html"
return resp
# ============================================================
# OAuth provider — prefix-match redirect_uri (same flaw as Phase 2F)
# ============================================================
REGISTERED_CLIENTS = {
"acme-spa": {
"redirect_uri_prefix": "http://localhost:58020",
}
}
_codes = {}
@app.route("/oauth/authorize")
def oauth_authorize():
client_id = request.args.get("client_id")
redirect_uri = request.args.get("redirect_uri", "")
if client_id not in REGISTERED_CLIENTS:
return jsonify(error="unknown_client"), 400
# Vulnerable prefix-match
allowed_prefix = REGISTERED_CLIENTS[client_id]["redirect_uri_prefix"]
if not redirect_uri.startswith(allowed_prefix):
return jsonify(error="invalid_redirect_uri"), 400
code = secrets.token_urlsafe(16)
_codes[code] = time.time() + 60
sep = "&" if "?" in redirect_uri else "?"
return redirect(f"{redirect_uri}{sep}code={code}", code=302)
# ============================================================
# Attacker-controlled "callback" (the host evil.example.com
# in the real world; for the lab we use a different port so the
# browser ACTUALLY navigates cross-origin)
# ============================================================
_captured = []
@app.route("/attacker-callback")
def attacker_callback():
code = request.args.get("code", "")
_captured.append(code)
return jsonify(captured_code=code, total_captured=len(_captured))
@app.route("/attacker-log")
def attacker_log():
return jsonify(captured=_captured)
@app.route("/")
def index():
return jsonify(endpoints=["/dom-xss", "/oauth/authorize", "/attacker-callback", "/attacker-log"])
if __name__ == "__main__":
app.run(host="0.0.0.0", port=58020, debug=False)