0

I've learned how to parameterize my text boxes when we're talking about inserting data inside the database, now I'd like to implement the same technique while manually putting the Connection String for the SQL database. My code goes like this:

connectionString = "server=localhost;uid=" + usr.Text + ";pwd=" + pwd.Text;

And I think that it is quite vulnerable to SQL injections. Any suggestions?

3 Answers 3

3

It's not vulnerable to SQL injections since SQL isn't being used in this case. You can't access tables and records by specifying anything in the connection string, nor can you receive data just from specifying a connection string.

It is vulnerable to connection string property injection, as Nikola mentions in his answer. See also the question, " MS Access - prevent SQL injection in connection string ".

Sign up to request clarification or add additional context in comments.

1 Comment

But, something curious happens with my program. If I put some default SQL Injection code (' OR '1) in both textboxes, the application keeps running, when it should show an error message saying that the login failed. I'm using a try-catch clause controlling the SQLException n.1045, but no exception is thrown.
2

Depending on which provider you use, you can make use of one connection string builder classes provided in .NET framework.

http://msdn.microsoft.com/en-us/library/ms254947%28v=VS.100%29.aspx

There is no clear answer about any Connection String injection attacks. I can't see a way an attack can be performed by changing properties of a connection. However, Microsoft makes mention of such attack in link I posted above, but gives no detail in what such attack would do. At best (or worst) attacker would probably be able to change some properties of connection, maybe increase timeout and hope to DDoS your server that way.

Comments

0

As Mark said, no SQL injection vulnerability here. But just for readability, I'd go with:

connectionString = string.Format("server=localhost;uid={0};pwd={1}", usr.Text, pwd.Text);

But it's no safer and behaves the same.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.