Medium 2 - Regex Single Replacement Bypass
Medium 2 - Regex Single Replacement Bypass
Platform: CUSTOM | Category: Web | Type: Challenge | Difficulty: Easy | OS: N/A | **Author: XESXOR Techniques: regex_single_replacement_bypass, sacrificial_pattern_injection
Summary
Walkthrough of the CUSTOM Web Medium 2 - Regex Single Replacement Bypass. XSS challenge from the sibearsxss series. The escape function uses regex to remove dangerous patterns, but the regex is applied only once (without the /g flag).
Description
XSS challenge from the sibearsxss series. The escape function uses regex to remove dangerous patterns, but the regex is applied only once (without the /g flag).
URL: http://109.233.56.90:11659/xss/medium/2
Analysis
Escape function:
js read-only • copy allowedfunction escape(s) { s = s.replace(/(?:<[a-z\s]+>|on[\s\S]+=)/i, ''); return s; }
Regex breakdown:
(?:...)— non-capturing group<[a-z\s]+>— HTML tag like<tag>or<tag >(letters and spaces)|— ORon[\s\S]+=— event handler likeonclick=,onerror=, etc./i— case-insensitive- NO
/gflag — only the FIRST match is replaced!
Vulnerability: The regex removes only the first match. If you send two XSS patterns, the first one will be removed, but the second one will remain.
Solution
Use a "sacrificial" pattern that will be removed by the regex, while the real XSS payload remains:
Payload:
html read-only • copy allowed<x >onerror=prompt("sibears")<img src=x onerror=prompt("sibears")>
How it works:
- Regex finds the first match:
<x >(matches<[a-z\s]+>) <x >is removed- Remaining:
onerror=prompt("sibears")<img src=x onerror=prompt("sibears")> - Regex is not applied again (no
/gflag) <img src=x onerror=prompt("sibears")>remains and executes
Alternative payload:
html read-only • copy allowed<a >x<img src=x onerror=prompt("sibears")>
<a >is removed as the first matchx<img src=x onerror=prompt("sibears")>remains
Key Takeaways / Lessons
- Mastering regex_single_replacement_bypass, sacrificial_pattern_injection was key to this challenge.
- Always check for common misconfigurations and verify assumptions.
Crafted by XESXOR Research • 2026-03-09 • CUSTOM • Medium 2 - Regex Single Replacement Bypass • Difficulty: Easy