Forum Moderators: coopster
Basically I want to be able to log failed/ suspicious queries which contain stuff like: x'; DROP TABLE tablename; -- etc etc into a table...however everywhere I see people use textfiles. I wonder why this is?
Id like to be able to access suspicious queries via a part of my admin control panel, view the details and ban the user's account, his Paypal adress and account associated email adres with a press of the button if it contains malicious entries.
It isnt very hard to do, I just wonder why people choose text files...which are easier to access if need be then a table (assuming all scripts are pretty secure ofcourse)
With the extra power of table storage comes extra complexity- you can't just make a simple file copy of your log for analysis offline, trimming and rotating it requires code instead of just a file delete, cron jobs may be involved, etc.
The problem with logging SQL injection attempts in a database is that one of them ever worked the intruder could potentially DELETE everything you'd logged. It's much more secure to use a text-file that lies outside the web directory.
I can understand that, but why then is there something like session_set_save_handler()?
Doesnt this impose the same problem?
I mean, if one is to assume the server will be hacked sometime, my would you wanne use this?
Ofcourse, you could argue to encrypt the session data first, but the same could be used for the database log :)
Its a different example, but I use it because it applies to what I wanne do. And I really dont think my site/ server is bulletproof :)
When your script gets bigger and more complicated, thinking in layers helps too. If you're 100% sure that all user input is being checked that it, for example, only contains alphanumeric characters, and it otherwise stops execution, you won't have to check it again or escape it when you make a query out of it. Or if you have only one search script, and this allows for non-alphanumeric data, and you are positive it can't be accessed by any other script, you know you only have to check this one script and add slashes for this script's queries. However, if you have a pretty complex script where data is being handed back and forth, you may just decide to add slashes to all info that gets used for making queries, even if it is "supposedly" from a source that has to be an integer, and you're fairly sure that this is so. Why? Just in case somewhere there's an eventuality you hadn't thought of, or something you failed to check. You're pretty confident that this isn't the case. But if it barely costs you anything, just go ahead and do it. Same for displaying data - if you have a fail-safe set of classes that rigorously cleans everything before output, you're pretty safe. But if this isn't the case, and you have data that you are very sure of, but the degree of complexity means you're less than 101%, go ahead and use htmlspecialchars on it just to be sure - it doesn't cost you so much in terms of script execution time.
This is sort of like having backups, and backups of your backups, and off-site backups. Nobody's assuming your house is going to burn down. But if it does, thank God for backups.