When receiving user input on forms I want to detect whether fields like \"username\" or \"address\" does not contain markup that has a special meaning in XML (RSS feeds) or
I suggest you to take a look at the xss_clean
function from CodeIgniter. I know you don't want to clean, sanitize, or filter anything. You just want to "detect bad behaviour" and reject it. That's exactly why I recommend you to look at this function code.
IMO, we can find a deep and strong XSS vulnerability knowledge there, including all the knowledge you want and need with your question.
Then, my short / direct answer to you would be:
if (xss_clean($data) === $data)
Now, you don't need to use the whole CodeIgniter framework just because you need this single function, of course. But I believe you may want to grab the whole CI_Security
class (at /system/core/Security.php
) and do a few modifications to eliminate other dependencies.
As you will see, xss_clean
code is quite complex, as XSS vulnerabilities really are, and I would just trust it and do not try to "reinvent this wheel"... IMHO, you can't get rid of XSS vulnerabilities by merely detecting a dozen of characters.