Connection string security

Status
Not open for further replies.
I need to distribute a program that connects to a DB. I don't want it to be hacked, so I researched ways to secure the connection, but so far, everything I see amounts to locking the door and leaving the key in the lock, assuming that the program can be decompiled with utmost ease. However I decrypt the password, a hacker can follow the exact same steps.

I already limited the DB account so it can't do too much damage, but it still has to select, insert, update and delete on a fairly large number of fairly important tables.
 

technophile

Ars Legatus Legionis
23,768
Blacken00100":fc6mnfaz said:
wallinbl":fc6mnfaz said:
I would use a web service. I wouldn't make the database externally accessible at all.
This. Do it right.
"Right" is situational. If direct DB access is actually required, using sprocs is the correct approach.

If web service access will work, though, that's a good solution as well. It will also be a better approach if the app needs to work across arbitrary networks rather than all being on the same fast network.
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
technophile":1tozp1wh said:
Blacken00100":1tozp1wh said:
wallinbl":1tozp1wh said:
I would use a web service. I wouldn't make the database externally accessible at all.
This. Do it right.
"Right" is situational. If direct DB access is actually required, using sprocs is the correct approach.

If web service access will work, though, that's a good solution as well. It will also be a better approach if the app needs to work across arbitrary networks rather than all being on the same fast network.
I can't think of a time where giving end users database server access would be appropriate or required.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
If you wanted them to be able to use arbitrary sql specific tooling like a sql gui where replacing said tooling with something that could talk to a web service was a pain. Also if the interaction was extremely slow (massive amount of work done on the server) and going to the trouble of session state management in the web layer to allow them to cancel a query and the like was too much pain)

Giving someone read access on some tables/views or on a stored procedure that returns multiple rows is not the end of the world if it's internal.

In a SQL Server environment you then get things like SSPI all for free so there's no need to log in.

That said for something simple and well defined I'd favour the web service approach.
 

NickR

Ars Scholae Palatinae
708
Tiiba":ok12lgi8 said:
I need to distribute a program that connects to a DB. I don't want it to be hacked, so I researched ways to secure the connection, but so far, everything I see amounts to locking the door and leaving the key in the lock, assuming that the program can be decompiled with utmost ease. However I decrypt the password, a hacker can follow the exact same steps.

I already limited the DB account so it can't do too much damage, but it still has to select, insert, update and delete on a fairly large number of fairly important tables.

Do not distribute the username and password with the application.
Do not store the username and password with the application installation (prompt on each instance).
Create individual username/passwords for each user of the system. Take advantage of any network based credentials if possible.
If storing many usernames/passwords is not manageable then you need to look at building a server based frontend that can.
Use views and/or stored procs to limit potential table damage in the event username/password compromise to the current users data only.
Configure SSL for db connections if available.
 

HL7

Ars Praefectus
3,523
Subscriptor++
For those of you saying to use a web service, do you believe this is the best approach even for applications that are entirely on an internal corporate network? I maintain an application that I wrote for a client and I originally used the web service model. In updating it for the latest version of .NET, I planned to remove the web service and do data access from the front-end web application using sprocs. The users don't actually have a login for the SQL database -- they have an application-specific login, but only the domain 'aspnet' user has database access, and the program is a web application -- nothing runs local. This seemed to me to be the same level of security as using a web service -- right?
 

technophile

Ars Legatus Legionis
23,768
^^^^
That's essentially similar to the web services approach, yes.


Blacken00100":281yb3ai said:
I can't think of a time where giving end users database server access would be appropriate or required.
It's generally not, although there are reporting scenarios where it's common.

But giving the application database server access is sometimes appropriate. And using sprocs to lock down what the application can and cannot do can be effective (especially if you combine it with, for example, Windows Authentication so that you don't have to worry about password changes etc). It helps defend against both unintended SQL errors as well as curious users.
 

Pont

Ars Legatus Legionis
26,160
Subscriptor
HL7":3kqapezi said:
For those of you saying to use a web service, do you believe this is the best approach even for applications that are entirely on an internal corporate network? I maintain an application that I wrote for a client and I originally used the web service model. In updating it for the latest version of .NET, I planned to remove the web service and do data access from the front-end web application using sprocs. The users don't actually have a login for the SQL database -- they have an application-specific login, but only the domain 'aspnet' user has database access, and the program is a web application -- nothing runs local. This seemed to me to be the same level of security as using a web service -- right?

A web service is still preferable, IMHO.

[*] WS apps are easier on the IT guys than allowing multiple clients to connect to the DB directly. If well-controlled internal servers and select developer workstations are the only clients that can reach the DB through the firewall, then IT can take a more... pragmatic approach to DB patches. On the other hand, if random employee laptops access the DB directly, IT is under much more pressure to apply security patches immediately. Also, if "something" is DOSing the database, there's fewer "something" for them to track down.

[*] Web services tend to work better over VPNs. This is not a hard and fast rule, obviously. However, the act of making your web service tends to make you think about the data-transfer chattiness. Going 100% SPROC (and no VIEWs) could get you the same thing, but you still can end up with situations where a client is holding onto a result cursor for too long.

[*] Keeping DB drivers up-to-date on client machines sucks.

[*] Flexibility. I've always found it easier to move machines around when clients are connecting to a genericly-named web front end. Easy to point the webserver at a different DB. Easy to point the DNS entry at a different web server.

[*] Connection limits. If for performance or licensing reasons your DB has a limited number of incoming connections, it's easier to control that with a WS architecture than with clients connecting directly.

[*] Aggregating disconnected data. Having client apps access multiple data sources simultaneously makes the data flow very complex. Imagine you have 10 data sources and 100 clients. Now mentally draw a network diagram for those clients to connect to each of those data sources. Much simpler to have your clients connect to your WS and your server connect to the other data sources.

Apps with a lot of ad-hoc queries are really the only ones I would consider giving direct DB access to these days.
 

HL7

Ars Praefectus
3,523
Subscriptor++
Thanks Pont -- I think you may have misunderstood, but still helped confirm that my plan is sound. My app is and always has been a web app connecting to the database through a web service. The plan was eventually that some other front-end (e.g. local Windows client) might have been needed, which is why I wrote the web service, but the web front-end proved sufficient and other plans were scrapped. Almost all of the advantages you listed (one connection to database, no drivers on client machines, etc) apply equally to a web app that connects to the database itself rather than through a web service. For the sake of simplification (they have no full-time developer and there's no telling who would maintain this if I'm gone) I plan to eliminate the web service if and when I upgrade it to the latest framework. Flexibility for other client types will be lost, but they don't need it -- less code to maintain is a bigger advantage for them.

I agree with you and others here that for client apps running on a local machine, connecting to a web service is preferable to connecting directly to the database.
 

technophile

Ars Legatus Legionis
23,768
I haven't met many users who could natively consume a web service. Usually they need some sort of client side app, which will have to be serviced in conjunction with at least some subset of web service updates.

Unless of course you mean a web app consuming web services, in which case the win for web services over database access is less clear. (It still exists in many cases, it's just not as clear cut for others.)
 

Megalodon

Ars Legatus Legionis
36,693
Subscriptor
technophile":1rxpsqbi said:
It can. But having a client app at all negates ronelson's point that "you only have to distribute a URL, not a piece of software, and everyone always runs the latest version".
That's true, but that doesn't mean there aren't advantages to going through HTTP instead of a direct database connection.

Assuming for the sake of argument that a client app is necessary, an HTTP API rather than a direct database connection would still be my preference.
 

ronelson

Ars Legatus Legionis
21,399
Subscriptor
It can. But having a client app at all negates ronelson's point that "you only have to distribute a URL, not a piece of software, and everyone always runs the latest version".
You can have java applets or flash apps or a million other things that actually run client side, but are accessed via your browser's Bookmarks. It is not difficult to detect when someone ran it locally as opposed through the browser at the appropriate URI, either.

However, I still think it is fair to say that you can have a client app that uses a web service that you point everyone to and obviate that need for distributing the latest and greatest version of your code. For instance, instant messaging. All the real connectors to the software stack are handled by the web service, your client just sends an XML packet for the service to figure out what needs done. If the back-end calls are changed, the client does not necessarily have to change, though obviously some changes will require that. In the case of a DB app, the request with some user auth information can be sent over HTTPS; the service can then engage the DB with the DB auth that is somehow known to the service itself and return the result. Your client app may eliminate the need for customer's to use URI's to get where they need to go, but other developers could also use the URI in their own apps, if that is permissible.
 
Status
Not open for further replies.