Thanks, misson. I've carefully read your entire post (worth its weight in gold) and the links you put, except the 'Programmatic Mutualism' one
It's in a .co.cc domain and my antivirus block it. Maybe later I'll give it a try, temporarily disabling the AV.
So, I'm forgetting about SQL injection in order to concentrate on possible cross-site scripting attacks.
If I understood it well, the main problem when someone try any kind of injection is not storing the injected input, but reading that injected info and outputting it in the browser, isn't it?
Right now, my website doesn't pass parameters between PHP pages. So I think we can also forget those
'Reflected XSS Attacks', according to what I could read in the owasp.org link.
In my particular case, the problem appears (if I don't filter at all the input data) when I open the 'infected' mail sent by the user in my mail client. That is,
'Stored XSS Attacks', right?
Now that (I think) we're delimiting the problem, this portion of your post got my attention:
Cross-site scripting is a form of HTML injection, which (as you've at least partially realized) is a concern. As stated in the docs,
strip_tags doesn't alter any attributes, so the contact form could still be vulnerable to XSS. This vulnerability should be mitigated by the protection against XSS
provided by most webmail readers; however, that security isn't guaranteed.
The contact form that we are talking about send emails to a GMail account in HTML format. Then I supposed GMail has its own filters (it's Google, for Kobol's sake! XD) and wanted to try some kind of XSS attack without sanitizing anything. So in the 'message' field I put this, reading various XSS guides including the one you put:
HTML:
<div style="background-image: url(javascript:alert('XSS_1'))">
Testing, <strong>testing</strong>
</div>
<script>alert('XSS_2');</script>
<span onLoad=alert('XSS_3')>Span testing</span>
Then I opened the sent email and the output was simply:
Testing, testing
alert('XSS_2');
Span testing
Not even a single JS pop-up
alert window. Can I be sure that we are safe from most common direct XSS attacks? Or did I make it the wrong way and the experiment is not valid?
There are a few things when looking at websecurity especially when your using MySQL and Cookies for Login. Not only do you need to look out for SQL Injection but XSS (Cross Site Scripting), so sanitizing any data you OUTPUT on a page that might not necessarily be user inputted. ANY $_GET data should be sanitized and ALL $_POST data from forms should be sanitized, not just custom data from users, because using tools such as Tamper Data (firefox addon) you are able to change any value (select boxes, check boxes etc.) or even creating false POST data to send to your server is relatively easy if you know what your doing.
Thank you too for your comment.
Fortunately, I don't echo neither $_POST nor $_GET info in the website. The only part where that type of parameters are even used is the contact form and it's used through jFormer (jQuery form plugin) via ajax I think. Direct from user input (or "other" ways) to my e-mail. That info is not printed anywhere.
I think (and hope) that this kind of reflected attack will not affect my website, as I stated before.
1 If you are going to use any user input in any part of the headers, be careful. ie, don't do it. Don't use the input for "To", "From" or "Subject".
2. Just the body of the message? You want them to send you HTML? Why? If not, strip out all HTML markup and then remove any occurrences of '&#' in what remains.
1. :S Right now, "From" and "Subject" are user input. Anyway, "From" is supposedly validated client-side and server-side, and has to be a string in a "user@domain.com" style. "Subject" is right now 'sanitized' via strip_tags, so I'm still vulnerable to attacks via tag's attributes as misson mentioned. I'm planning to make it only alpha-numerical + spaces. No punctuation, no symbols. Or directly getting rid of it, it's not neccessary at all, now that you mention it.
2. The body is in HTML right now just because I'm planning to use a WYSIWYG editor that automatically converts input to HTML. What I don't know right now is if it sanitizes input data in any way. If it doesn't I would plan to use HTML Sanitizer.
Unless, of course, you tell me that the small experiment I did before (see above, in response to misson) means we are safe.
Thanks for all your informations and comments. I'm learning a lot.