Lab: Character Replacement Filter Bypass
This lab demonstrates a reflected XSS vulnerability with a character replacement filter that replaces all '<' characters with ';' in the First Name parameter.
str_replace('<', ';', $_GET['fname'])
Objective: Bypass the character replacement filter and execute a JavaScript alert.
Note: Only the First Name field is filtered and displayed. The Last Name field is unfiltered but not used in output.
if(isset($_GET["fname"]) && isset($_GET["lname"])){
$re = str_replace('<', ';', $_GET['fname']);
echo $re;
}
javascript:alert(1) in href or other attributes if you can create linksThis character replacement filter demonstrates:
For effective XSS prevention:
Character replacement filters are one of the weakest forms of XSS protection because:
This lab shows why character-level filtering should never be the primary defense against XSS attacks.