Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any injection risk if no user input was sent to database?

I have a small MySQL database with a few hundred rows (all in text, no images). I am requesting all the rows using iQuery and do all filtering at client end. iQuery code is the following:

$(document).ready( function () {
     $.get("alldata.php", function(data){
         $('#result').text(data);
     });  
});

On the server side, the "alldata.php" has the following code and pass the data in JSON back to iQuery:

$sql = "SELECT title FROM mydatabase";
$result =  mysqli_query($conn, $sql);
$arr = array(); 

while($row = mysqli_fetch_assoc($result)){
    $row_array['Title'] =$row['title'];
    array_push($arr,$row_array);
}
mysqli_close($conn);

echo json_encode($arr);

It seems to me there will not be any risk of injection since there is NO user input submitted to the database. Am I right or wrong? Thanks a lot for your input!

like image 417
LearnAWK Avatar asked Aug 02 '15 18:08

LearnAWK


People also ask

What are the risks of SQL injection?

The impact SQL injection can have on a business is far-reaching. A successful attack may result in the unauthorized viewing of user lists, the deletion of entire tables and, in certain cases, the attacker gaining administrative rights to a database, all of which are highly detrimental to a business.

What causes an SQL injection?

To make an SQL Injection attack, an attacker must first find vulnerable user inputs within the web page or web application. A web page or web application that has an SQL Injection vulnerability uses such user input directly in an SQL query. The attacker can create input content.

Do we get any error while injecting blind SQL injection in an input field?

Blind SQL Injection. This type of injection attack does not show any error message, hence “blind” in its name. It is more difficult to exploit as it returns information when the application is given SQL payloads that return a true or false response from the server.


1 Answers

You are right. Your SQL statement includes no parameters outside of itself, so there is no vector for injection. While injection attacks ARE possible on SELECT statements, in your case the query is not created dynamically so cannot be tampered with.

like image 115
Peter Avatar answered Oct 02 '22 14:10

Peter