Module 3 · Lesson 2 of 49/42 in the course~15 min
Module lessons (2/4)
Attribute, javascript: URI & Scheme Allowlists
Lesson preview6 hands-on exercises readyApplication & Web Security · Module 3 — XSS, CSP & Client-Side Security
Bypass HTML escaping through href injection, then lock down link targets with strict URL protocol allowlisting.
What you'll learn in this lesson
- Explain why naive
startsWith('javascript:')blocklists fail against whitespace, control bytes, and case variations in browsers. - Exploit naive URL scheme filters using leading whitespace or embedded control characters (
\t,\n). - Enforce a positive scheme allowlist (
https:/http:) vianew URL(...), reject protocol-relative//confusion, and harden `tags withrel="noopener noreferrer"`.
Overview
Even when you HTML-escape every character inside ``, a user-supplied URL can still execute arbitrary JavaScript when clicked! HTML escaping protects attribute boundaries, not URI scheme execution.
Look closely at how browsers normalize URLs differently from naive string filters:
Sections covered in this lesson
- 11. Why Scheme Blocklists Lose to Browser Parsers
- 22. Interactive Explorer:
hrefURI Context - 33. Progressive Labs: Warm-Up → Attack → Defend → Harden
- 44. Checkpoints & Code Review
Pro Lesson · Module 3 — XSS, CSP & Client-Side Security
Unlock "Attribute, javascript: URI & Scheme Allowlists" and the full Application & Web Security curriculum
Bypass HTML escaping through href injection, then lock down link targets with strict URL protocol allowlisting.
Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Application & Web Security plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.