Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

In my project, I have maintained all SQL query in resource (.resx) file.

my doubt is:
- Sql injection attacks possible using resource(.resx) file.
- If sql injection is possible then how and where to maintain all sql queries.

Please let me know best solution for the above mentioned problem.

Thanks,
Shanmuga Raja

What I have tried:

unable to find the right suggestion for my doubts
Posted
Updated 19-Mar-22 8:12am

It has nothing to do with where the queries are stored. It's how the queries are filled with data to modify the query. Say you have a query that accepts a value for a WHERE clause. If you're not preparing the query for execution properly, you're exposing code to exploitation.
 
Share this answer
 
Comments
[no name] 19-Oct-18 16:32pm    
I don't think it is possible to prevent from manipulating the resource data and then even the code is proper implemented using Parameters, you can always manipulate the ressource and add malicious SQL Statements. But that is really a very theoretical Scenario. Maybe I'm wrong, but I don't think so
Dave Kreskowiak 19-Oct-18 21:28pm    
It's possible to do, but difficult.
Quote:
Sql injection attacks possible using resource(.resx) file.
SQL Injection is made possible when your queries are exposed to the code injection. It doesn't matter how you store the queries, rather how they execute. It is of no benefit if you store and load the SQL queries from a file, or even from a network, or store them in resource files, or in-memory, if the query is exposed to injection, it will be injected with code.

Think of the code, if you are concatenating the strings, like,
SQL
var query = "SELECT * FROM table_name WHERE primary_column = '" + variable + "';
It will not matter whether this query comes from a resource, network, or is hardcoded inside the program. You need to change this query, to prevent the injection.

Quote:
If sql injection is possible then how and where to maintain all sql queries.
You need to write the queries in a secure manner, such as use of parameters is encouraged. You should also consider, whether the user is able to modify any of these queries or not. Your program should take care of the queries that it executes.

Although every engine has its own security loopholes, you can search for an instance based documentation and recommendation on Google quite easily, but I would recommend you start from here, SQL Injection | Microsoft Docs[^].
 
Share this answer
 
Comments
[no name] 19-Oct-18 16:32pm    
I don't think it is possible to prevent from manipulating the resource data and then even the code is proper implemented using Parameters, you can always manipulate the ressource and add malicious SQL Statements. But that is really a very theoretical Scenario. Maybe I'm wrong, but I don't think so
Afzaal Ahmad Zeeshan 19-Oct-18 16:44pm    
Exactly, that was the point. User can easily modify the correctly implemented and secure SQL queries if they are written in the resource files.

They can apply some tricks to counter that—remember these stupid hacks only are required if the SQL queries are stored in resource files, no sane mind would do that.

One way that I can think of on top of my head is, to check whether the query matches the hash value that was generated by the secure query. If tampering is done, they can abort. But of course, there would be a secure and better approach to this as well.

As for storage in the resource file, I was just following up with OP, otherwise, I do not find any reason to do so. :-)
[no name] 19-Oct-18 16:47pm    
Which is finally an Argument for signed applications, even I'm not that happy whith this at the Moment. Anyway a 5 now ;)
Afzaal Ahmad Zeeshan 19-Oct-18 16:51pm    
Thanks, well, OP is an OP after all. ;-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900