sql-injection

How do I build a parameterized PDO statement in PHP for a dynamic query?

帅比萌擦擦* 提交于 2019-12-06 13:01:10
问题 Apologies if this has been asked already. I've seen answers regarding static SQLs, but in this case I'd like to use PDO->prepare() for a query string that is built dynamically at runtime. Breaking down into a simple example: $TempSQL = "SELECT field1, field2, field3 FROM table WHERE "; if ($numberParams == 1) { $TempSQL = $TempSQL . " field1 = '$val1' "; } else { $TempSQL = $TempSQL . " field2 = '$val2' "; $TempSQL = $TempSQL . " AND field3 = '$val3' "; } db->query($TempSQL); How do I rewrite

how to avoid SQL Injection with Linq with EF in codefirst technique in c#

☆樱花仙子☆ 提交于 2019-12-06 12:29:13
I am using asp.net mvc 3 with WCF with EF 4.1 With Sql Azure. I am building the search engine for my application. and using the dynamic Linq to build queries. I want to avoid the sql injetion in this scenario. what is the best practice for the same ? what are the precaoution i should take in this scenario ? As long as your are building your queries through LINQ, then you are not vulnerable to SQL injection. While this doesn't mean that your code is invulnerable to ALL sorts of attacks (brute forcing passwords, etc.), you won't be vulnerable to SQL injection. Dynamic LINQ automatically protects

mysql(i)_real_escape_string, safe to rely on?

狂风中的少年 提交于 2019-12-06 10:25:13
function Query() { $args = func_get_args (); if (sizeof ($args) > 0) { $query = $args[0]; for ($i = 1; $i < sizeof ($args); $i++) $query = preg_replace ("/\?/", "'" . mysql_real_escape_string ($args[$i]) . "'", $query, 1); } else { return FALSE; } I have a function like this. Basically, I make a query like this: $this->Query('SELECT * FROM USERS WHERE Username = ? AND Points < ?', $username, $points); It currently supports deprecated mysql functions, but adapting to mysqli will be as easy as replacing mysql with mysqli in my class. Is this a safe approach to rely on against SQL Injection

Parameterized query with several optional search terms

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 10:19:00
I have a web application with lots of data, and a search/filter function with several fields, such as name, status, date, and so on. I have been using parameterized queries like this for the regular (non-search) queries: $id = $_POST['itemID']; $db = mysqli_connect($host, $username, $password, $database); $sql_query = "SELECT * FROM tbl_data WHERE ID = ?"; $stmt_query = mysqli_prepare($db, $sql_query); mysqli_stmt_bind_params($stmt_query, "i", $id); mysqli_stmt_execute($stmt_query); //and so on.. How would I protect agains SQL-injection with multiple, optional parameters? There can be up to 10

mysqli_real_escape_string - example for 100% safety

孤人 提交于 2019-12-06 08:36:17
I know there have been a lot of questions asked already about this topic. And I also know that the way to go are prepared statements. However I have still not completely understood if or how the following could become a security problem: $mysqli = new mysqli("localhost", "root", "", "myDatabase"); $mysqli->set_charset("utf8"); $pw = mysqli_real_escape_string($mysqli,$_POST['pw']); $username = mysqli_real_escape_string($mysqli,$_POST['username']); $str = "SELECT * FROM users WHERE id='".$id."' AND username='".$username."'"; $result = $this -> mysqli -> query($qstr); if($result->num_rows > 0){ /

How do you protect your website from Local File Inclusion & SQL Injection in PHP?

五迷三道 提交于 2019-12-06 07:49:47
问题 How do you protect your website from Local File Inclusion & SQL Injection (PHP)? 回答1: There are numerous measures to be taken. Be sure to sanitize all input before storing in the database. I suggest using mysql_real_escape_string() on all data that will be stored. Limit character-input to reasonable lengths, and be sure you're getting the TYPE of data you are expecting for that field. Lock multiple attempts to submitting specific areas of data. Crawl the contents of uploaded files looking for

Erlang Mysql: How to prevent SQL Injections

喜欢而已 提交于 2019-12-06 05:54:17
I'm very new to erlang and I need to code something which inserts rows in a MySQL Database. How can I prevent SQL Injections with Erlang? Is there also something like prepared statements in other Languages or how should I do it? Thanks for your replies. This answer depends on the driver you are using. Erlang ODBC has a function param_query that binds a set of parameters to the query and it might also escape all the SQL special characters. erlang-mysql-driver has prepared statements: %% Register a prepared statement mysql:prepare(update_developer_country, <<"UPDATE developer SET country=? where

What are the dangers of dynamic SQL, and can they be avoided?

回眸只為那壹抹淺笑 提交于 2019-12-06 04:54:26
问题 We've just been given the following code as a solution for a complicated search query in a new application provided by offshore developers. I'm skeptical of the use of dynamic SQL because I could close the SQL statement using '; and then excute a nasty that will be performed on the database! Any ideas on how to fix the injection attack? ALTER procedure [dbo].[SearchVenues] --'','',10,1,1,'' @selectedFeature as varchar(MAX), @searchStr as varchar(100), @pageCount as int, @startIndex as int,

Is hexing input sufficient to sanitize SQL Queries?

会有一股神秘感。 提交于 2019-12-06 03:55:43
问题 I was reading last night on preventing SQL injections, and I ran across this answer: How can I prevent SQL injection in PHP? The comments from 'Your Common Sense' made it sound like that was dysfunctional/unsafe. However, in my (albeit limited) testing, I found that php's "bin2hex($var)" worked with anything I threw at it - literal number, number string, string of text - even when matching a numerical (tinyint) column. My question is this: Is there a way to inject SQL when every user input is

Can this simple String escaping prevent any SQL Injections?

心已入冬 提交于 2019-12-06 03:02:02
I'm working at a company where the person responsible for the database module is strictly against using prepared statements. I'm worrying that his implementation is not secure. Here is the code we are currently using to make a SQL query (Java 8 Application with JDBC/MySQL 5.5): String value = "Raw user input over HTTP-Form"; String sql = "SELECT * FROM db1.articles WHERE title like '" + replaceSingleQuotes(value) + "'"; executeSQL(sql); public static String replaceSingleQuotes(String value) { value = value.replaceAll("\\\\", "\\\\\\\\"); return value.replaceAll("'", "\\\\'"); } I was not able