Lab: Multi-Filter Bypass Challenge
This lab demonstrates a reflected XSS vulnerability with multiple filters that attempt to block both 'script' and 'img' tags in the First Name parameter.
'script''img'str_replace(array('script','img'), '', $_GET['fname'])
Objective: Bypass both filters and execute a JavaScript alert.
Note: Only the First Name field is filtered. The Last Name field is unfiltered but not displayed.
if(isset($_GET["fname"]) && isset($_GET["lname"])){
$arr = array('script','img');
$re = str_replace($arr, '', $_GET['fname']);
echo $re;
}
svg, body, iframe, etc.onmouseover, onload, etc.This lab demonstrates why blacklist-based filtering is insufficient for XSS prevention. Attackers can easily bypass filters by using alternative tags, case variations, or encoding techniques.
Real-world recommendation: Use whitelist-based validation and context-aware output encoding instead of blacklists. Libraries like DOMPurify properly handle these edge cases.