At the moment, I apply a 'throw everything at the wall and see what sticks' method of stopping the aforementioned issues. Below is the function I have cobbled together:
function madSafety($string)
{
$string = mysql_real_escape_string($string);
$string = stripslashes($string);
$string = strip_tags($string);
return $string;
}
However, I am convinced that there is a better way to do this. I am using FILTER_ SANITIZE_STRING and this doesn't appear to to totally secure.
I guess I am asking, which methods do you guys employ and how successful are they? Thanks
Prevention techniques such as input validation, parametrized queries, stored procedures, and escaping work well with varying attack vectors. However, because of the large variation in the pattern of SQL injection attacks they are often unable to protect databases.
As we mentioned earlier, Cross-Site Scripting is more common in JavaScript and is used in this language, while SQL Injection includes Structured Query Language. In addition, through Cross-Site Scripting, malicious code is injected into the site. If users enter a site where malicious code has been placed there by the hackers, they will be hacked.
How to Prevent Cross-Site Scripting Attacks 1 Non-Persistent Cross-site scripting attack. Non-persistent XSS is also known as reflected cross-site vulnerability. ... 2 Persistent cross-site scripting attack. Persistent cross-site scripting is also known as stored cross-site scripting. ... 3 DOM-based cross-site scripting attack. ...
While SQL Injection can affect any data-driven application that uses a SQL database, it is most often used to attack web sites. SQL Injection is a code injection technique that hackers can use to insert malicious SQL statements into input fields for execution by the underlying SQL database.
Just doing a lot of stuff that you don't really understand, is not going to help you. You need to understand what injection attacks are and exactly how and where you should do what.
In bullet points:
mysql_real_escape_string
).stripslashes
) when you retrieve data from the database.echo
), you should default to escape the string (Using htmlentities
with ENT_QUOTES
).strip_tags
is in theory what you should use, but it's flawed; Use HtmlPurifier instead.See also: What's the best method for sanitizing user input with PHP?
The best way against SQL injection is to bind variables, rather then "injecting" them into string. http://www.php.net/manual/en/mysqli-stmt.bind-param.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With