Lab: Alert Function Filter Bypass
This lab demonstrates a reflected XSS vulnerability with an advanced filter that blocks multiple HTML tags AND the 'alert' function.
str_replace(array('script','Script',...,'alert'), '', $_GET['lname'])
Objective: Bypass the filter and execute a JavaScript alert, even though 'alert' is blocked.
Note: Only the Last Name field is filtered and displayed. The First Name field is unfiltered but not used in output.
if(isset($_GET["fname"]) && isset($_GET["lname"])){
$arr = array('script','Script','sCript','scRipt',
'scrIpt','scriPt','scripT','SCript',
'SCRipt','SCRIpt','SCRIPt','SCRIPT',
'img','alert','svg','audio','video','body');
$re = str_replace($arr, '', $_GET['lname']);
echo $re;
}
prompt(), confirm(), console.log() or create your own alert functionwindow.alert or accessing through different object pathsalert'al'+'ert'eval() or Function() constructors with encoded strings`al${''}ert`globalThis['al'+'ert'] or similar approachesString.fromCharCode() to build the function nameonerror with image loading, etc.Blocking specific JavaScript functions demonstrates:
For effective XSS prevention:
When 'alert' is blocked, consider these alternatives:
prompt(1) - Shows a prompt dialogconfirm(1) - Shows a confirmation dialogconsole.log(1) - Logs to browser consoleprint() - Opens print dialogtop['al'+'ert'](1) - String concatenationwindow['al'+'ert'](1) - Bracket notationeval('al'+'ert(1)') - Using evalFunction('al'+'ert(1)')() - Function constructor