I need to prevent cross-site scripting (XSS). How can I validate that it isn't cross-site script? The issue is with my "url" BBCode.
function bbcode($input) {
$search = array('/\[a url="(.+?)"\](.*?)\[\/a\]/is');
$replace = array('<a href="$1" style="color: #337ab7;
text-decoration: none" target="_blank">$2
</a>');
return preg_replace($search, $replace, $input);
}
bbcode([a url="javascript://hello.com/%0Aalert(%27s%27)"]XSS[/url]);
The code above is an example of what happens. When you click the link, a JavaScript popup comes up. Also, there are more BBCode in that array, but I removed them when posting this to make it easier.