Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing SQL injection in C++ OTL, DTL, or SOCI libraries

I've been looking at all three of these database libraries, and I'm wondering if they do anything to prevent SQL injection. I'm most likely going to be building a lib on top of one of them, and injection is a top concern I have in picking one. Anybody know?

like image 428
Brett Rossier Avatar asked Jun 25 '10 14:06

Brett Rossier


People also ask

Which will prevent SQL injection?

How to Prevent an SQL Injection. The only sure way to prevent SQL Injection attacks is input validation and parametrized queries including prepared statements. The application code should never use the input directly.

Does stored procedure prevent SQL injection?

All the input values should be validated before putting them under code to perform database transactions. Use of Stored Procedures (in right way) reduces risk of SQL Injection Attack.

What types of databases are more vulnerable to SQL injections?

If a web application or website uses SQL databases like Oracle, SQL Server, or MySQL, it is vulnerable to an SQL injection attack. Hackers use SQL injection attacks to access sensitive business or personally identifiable information (PII), which ultimately increases sensitive data exposure.


2 Answers

Got with the author of the OTL library. A parameterized query written in "OTL Dialect," as I'm calling it, will be passed to the underlying DB APIs as a parameterized query. So parameterized queries would be as injection safe as the underlying APIs make them.

Go to this other SO post for his full e-mail explanation: Is C++ OTL SQL database library using parameterized queries under the hood, or string concat?

Edit: SOCI uses the soci::use expression, which translates to the usual binding mechanism, but with more syntactic sugar. Example: db_session << "insert into table(column) values(:value_placeholder)", use(user_input,"value_placeholder");

As far as DTL is concerned, I'm not sure what it do with parameters in relation to the underlying APIs.

like image 123
Brett Rossier Avatar answered Oct 24 '22 09:10

Brett Rossier


Generally a library at this level should just do what you tell it to. You most prevent SQL injection by looking at strings you're provided by the user, and only passing things on to the library after you've sanitized them.

like image 44
Jerry Coffin Avatar answered Oct 24 '22 11:10

Jerry Coffin