sql-injection

Python best practice and securest to connect to MySQL and execute queries

老子叫甜甜 提交于 2019-11-26 15:08:20
What is the safest way to run queries on mysql, I am aware of the dangers involved with MySQL and SQL injection. However I do not know how I should run my queries to prevent injection on the variables to which other users (webclients) can manipulate. I used to write my own escape function, but apparently this is "not-done". What should I use and how should I use it to query and do inserts safely on a MySQL database through python without risking mysql injection? Bruno To avoid injections, use execute with %s in place of each variable, then pass the value via a list or tuple as the second

Shortcomings of mysql_real_escape_string?

♀尐吖头ヾ 提交于 2019-11-26 14:44:50
I have seen a few people on here state that concatenating queries using mysql_real_escape_string will not protect you (entirely) from SQL injection attacks. However, I am yet to see an example of input that illustrates an attack that mysql_real_escape_string would not protect you from. The majority of examples forget that mysql_query is limited to one query and use mysql_real_escape_string incorrectly. The only example I can think of is the following: mysql_query('DELETE FROM users WHERE user_id = '.mysql_real_escape_string($input)); This would not protect you from the following input: 5 OR 1

How to cleanse dynamic SQL in SQL Server — prevent SQL injection

只谈情不闲聊 提交于 2019-11-26 14:36:58
问题 We have a ton of SQL Server stored procedures which rely on dynamic SQL. The parameters to the stored procedure are used in a dynamic SQL statement. We need a standard validation function inside these stored procedures to validate these parameters and prevent SQL injection. Assume we have these constraints: We can't rewrite the procedures to not use Dynamic SQL We can't use sp_OACreate etc., to use regular expressions for validation. We can't modify the application which calls the stored

What does bind_param accomplish?

蹲街弑〆低调 提交于 2019-11-26 14:28:58
问题 I'm learning about avoiding SQL injections and I'm a bit confused. When using bind_param, I don't understand the purpose. On the manual page, I found this example: $stmt = mysqli_prepare($link, "INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)"); mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent); $code = 'DEU'; $language = 'Bavarian'; $official = "F"; $percent = 11.2; Now, assuming those 4 variables were user-inputted, I don't understand how this prevents SQL

Is preventing XSS and SQL Injection as easy as does this

只谈情不闲聊 提交于 2019-11-26 14:17:24
问题 Question : Is preventing XSS (cross-site scripting) as simple using strip_tags on any saved input fields and running htmlspecialchars on any displayed output ... and preventing SQL Injection by using PHP PDO prepared statements? Here's an example: // INPUT: Input a persons favorite color and save to database // this should prevent SQL injection ( by using prepared statement) // and help prevent XSS (by using strip_tags) $sql = 'INSERT INTO TABLE favorite (person_name, color) VALUES (?,?)';

Avoiding SQL injection without parameters

拜拜、爱过 提交于 2019-11-26 14:14:54
We are having another discussion here at work about using parametrized sql queries in our code. We have two sides in the discussion: Me and some others that say we should always use parameters to safeguard against sql injections and the other guys that don't think it is necessary. Instead they want to replace single apostrophes with two apostrophes in all strings to avoid sql injections. Our databases are all running Sql Server 2005 or 2008 and our code base is running on .NET framework 2.0. Let me give you a simple example in C#: I want us to use this: string sql = "SELECT * FROM Users WHERE

rails 3 activerecord order - what is the proper sql injection work around?

戏子无情 提交于 2019-11-26 14:08:11
问题 let us say I have a list page of users and you can sort by the different columns, when clicking 'email' it will pass sort_by=email sort_direction=asc or desc sort_by = "email" # really params[:sort_by] sort_direction = "asc" # really params[:sort_direction] User.order("#{sort_by} #{sort_direction}") # SELECT "users".* FROM "users" ORDER BY email asc so that works as expected, however if we change the sort_by sort_by = "email; DELETE from users; --" User.order("#{sort_by} #{sort_direction}") #

How to prevent SQL Injection with JPA and Hibernate?

北慕城南 提交于 2019-11-26 13:58:50
问题 I am developing an application using hibernate. When I try to create a Login page, The problem of Sql Injection arises. I have the following code: @Component @Transactional(propagation = Propagation.SUPPORTS) public class LoginInfoDAOImpl implements LoginInfoDAO{ @Autowired private SessionFactory sessionFactory; @Override public LoginInfo getLoginInfo(String userName,String password){ List<LoginInfo> loginList = sessionFactory.getCurrentSession().createQuery("from LoginInfo where userName='"

Does CodeIgniter automatically prevent SQL injection?

a 夏天 提交于 2019-11-26 12:11:16
I just inherited a project because the last developer left. The project is built off of Code Igniter. I've never worked with Code Igniter before. I took a quick look at the code and I see database calls in the controller like this: $dbResult = $this->db->query("SELECT * FROM users WHERE username = '".$_POST['user_name']."'"); or calls like this: $dbResult = $this->db->query("SELECT * FROM users WHERE username = '".$this->input->post('username')."'"); Does code igniter automatically sanitize these queries to prevent sql injection? MarioRicalde CodeIgniter DOES ESCAPE the variables you pass by

Why is using a mysql prepared statement more secure than using the common escape functions?

拥有回忆 提交于 2019-11-26 11:23:42
There's a comment in another question that says the following: "When it comes to database queries, always try and use prepared parameterised queries. The mysqli and PDO libraries support this. This is infinitely safer than using escaping functions such as mysql_real_escape_string." Source So, what i want to ask is: Why are prepared parameterized queries more secure? An important point that I think people here are missing is that with a database that supports parameterized queries, there is no 'escaping' to worry about. The database engine doesn't combine the bound variables into the SQL