Comment On Disconnection String

"In ASP.NET programming," writes Chad Braun-Duin, "database connection strings are stored in configuration files, and the standard way of getting your connection string from these files looks like this:" [expand full text]
« PrevPage 1 | Page 2Next »

Re: Disconnection String

2012-06-14 14:15 • by DB (unregistered)
Frist frist.

Re: Disconnection String

2012-06-14 14:16 • by bewbs (unregistered)
second!

.
.
.
.not spam

Re: Disconnection String

2012-06-14 14:17 • by Chronomium (unregistered)
The worst part is probably all the variables defined at the start of the code, especially those commented out. Only two of them are actually used, while the rest imply that some sort of heavy-duty database punching was attempted at some point.

Re: Disconnection String

2012-06-14 14:18 • by DB (unregistered)
Anyway, I'm not a seasoned .NET programmer, but it's possible they were trying to avoid any potential issues with an empty or null return value.

Re: Disconnection String

2012-06-14 14:27 • by M (unregistered)
383153 in reply to 383151
Chronomium:
The worst part is probably all the variables defined at the start of the code, especially those commented out. Only two of them are actually used, while the rest imply that some sort of heavy-duty database punching was attempted at some point.


Maybe they tried putting all the connection strings in a database table?

Not removing the obviously useless code is definitely a WTF. Also, who the heck is still using hungarian notation? sHere, sThere, sEverywhere.

Re: Disconnection String

2012-06-14 14:32 • by KattMan
Another WTF is how ASP.Net defaults breaks PCI compliance.

Connection strings have usernames and passwords in them in plain text when usign them this way. Either encrypt them or do not use the config file to store them, have the config file point to something else that has them and that is encrypted.

Another possible way of getting them is through some service call, or maybe not getting them at all, let the service call access the data instead of the Asp.net application. Of course then you have the config file for the service that needs to be cleaned, but that is easier to point to a resource that has encrypted data instead of that resource being accessable from your web server.

Re: Disconnection String

2012-06-14 14:35 • by honnza (unregistered)
383156 in reply to 383153
M:
Chronomium:
The worst part is probably all the variables defined at the start of the code, especially those commented out. Only two of them are actually used, while the rest imply that some sort of heavy-duty database punching was attempted at some point.


Maybe they tried putting all the connection strings in a database table?

Not removing the obviously useless code is definitely a WTF. Also, who the heck is still using hungarian notation? sHere, sThere, sEverywhere.


$var for jQuery objects? Kinda useful in weakly typed languages with similar types.

Re: Disconnection String

2012-06-14 14:42 • by Scrummy
383157 in reply to 383155
KattMan:
Another WTF is how ASP.Net defaults breaks PCI compliance.

Connection strings have usernames and passwords in them in plain text when usign them this way. Either encrypt them or do not use the config file to store them, have the config file point to something else that has them and that is encrypted.

Another possible way of getting them is through some service call, or maybe not getting them at all, let the service call access the data instead of the Asp.net application. Of course then you have the config file for the service that needs to be cleaned, but that is easier to point to a resource that has encrypted data instead of that resource being accessable from your web server.


Read the chapter on "Integrated Security."

Re: Disconnection String

2012-06-14 14:56 • by emurphy
383159 in reply to 383155
KattMan:
Connection strings have usernames and passwords in them in plain text when usign them this way. Either encrypt them or do not use the config file to store them, have the config file point to something else that has them and that is encrypted.


Well, you can encrypt them in the config file, so I assume "this way" refers to this (unused) part:

sColumns = "DataLink, Platform, Login, Password, Server, Database"


Encryption is less of a big deal if you're dealing with an intranet app, or if the login only has read access to data that you want to share with the general public anyway.

Re: Disconnection String

2012-06-14 15:10 • by Zylon
383160 in reply to 383150
bewbs:
not spam

Let's agree to disagree on that.

Re: Disconnection String

2012-06-14 15:14 • by HungarianProf (unregistered)
The Real WTF is that they do not have a string variable called HitCount (or anything that begins with Hit ...)

Re: Disconnection String

2012-06-14 15:16 • by anony-mouse (unregistered)
383162 in reply to 383155
KattMan:
Another WTF is how ASP.Net defaults breaks PCI compliance.

Connection strings have usernames and passwords in them in plain text when usign them this way. Either encrypt them or do not use the config file to store them, have the config file point to something else that has them and that is encrypted.

Another possible way of getting them is through some service call, or maybe not getting them at all, let the service call access the data instead of the Asp.net application. Of course then you have the config file for the service that needs to be cleaned, but that is easier to point to a resource that has encrypted data instead of that resource being accessable from your web server.

Haven't heard of Windows Authentication, eh?
If you're using ASP.NET you're probably using MS SQL Server, in which the proper security model is to use Windows auth instead of a hard coded login/password.

Re: Disconnection String

2012-06-14 15:31 • by Nagesh (unregistered)
The major atrocity here is that instead of simply getting the connection string by key ('ConnectionString' in this case), they first look it up by position. This makes no sense. Later, if the lookup-by-position works, then they get it by key.

Um, I'm not fluent in VB.NET, but I can't see any "look it up by position" in the code snippet here. What they are doing seems to be to ask if the key at position 0 is 'ConnectionString', and then look it up by key. In all other cases -- including when 'ConnectionString' is the key in some non-zero position -- then they pretend that whatever the key at position 0 is, is the right connection string to use!

That's much more of a WTF than doing something that works but in a unnecessarily roundabout way.

Re: Disconnection String

2012-06-14 15:41 • by PedanticCurmudgeon
383165 in reply to 383163
Nagesh:
The major atrocity here is that instead of simply getting the connection string by key ('ConnectionString' in this case), they first look it up by position. This makes no sense. Later, if the lookup-by-position works, then they get it by key.

Um, I'm not fluent in VB.NET, but I can't see any "look it up by position" in the code snippet here. What they are doing seems to be to ask if the key at position 0 is 'ConnectionString', and then look it up by key. In all other cases -- including when 'ConnectionString' is the key in some non-zero position -- then they pretend that whatever the key at position 0 is, is the right connection string to use!

That's much more of a WTF than doing something that works but in a unnecessarily roundabout way.
Did someone forget to switch sock-puppet names again?

Re: Disconnection String

2012-06-14 15:47 • by Marc (unregistered)
383167 in reply to 383163
I'm glad you said this, cause that's how I am reading it too.

Re: Disconnection String

2012-06-14 15:52 • by Puzzles (unregistered)
383168 in reply to 383153
M:
Also, who the heck is still using hungarian notation? sHere, sThere, sEverywhere.

Not only that, but only one of those three was actually declared as a string.

"Dim x, y, z As String" creates z as a string but x and y as variants.

Re: Disconnection String

2012-06-14 15:53 • by KattMan
383169 in reply to 383162
anony-mouse:
Haven't heard of Windows Authentication, eh?
If you're using ASP.NET you're probably using MS SQL Server, in which the proper security model is to use Windows auth instead of a hard coded login/password.


Not always, I've had Informix databases sitting behind and ASP.Net app.

I agree, the inetuser should be the one with access and use authentication, but not always easy with certian databases.

Some Manager

2012-06-14 16:10 • by lurch
Some Manager probably said

"The Key is the Connection"

And it was.

Re: Disconnection String

2012-06-14 16:22 • by cdosrun
383171 in reply to 383155
KattMan:
Another WTF is how ASP.Net defaults breaks PCI compliance.

Connection strings have usernames and passwords in them in plain text when usign them this way. Either encrypt them or do not use the config file to store them, have the config file point to something else that has them and that is encrypted.

Another possible way of getting them is through some service call, or maybe not getting them at all, let the service call access the data instead of the Asp.net application. Of course then you have the config file for the service that needs to be cleaned, but that is easier to point to a resource that has encrypted data instead of that resource being accessable from your web server.


Or you can encrypt the data in your web.config file.

Re: Disconnection String

2012-06-14 16:27 • by KattMan
383172 in reply to 383171
cdosrun:
KattMan:
Another WTF is how ASP.Net defaults breaks PCI compliance.

Connection strings have usernames and passwords in them in plain text when usign them this way. Either encrypt them or do not use the config file to store them, have the config file point to something else that has them and that is encrypted.

Another possible way of getting them is through some service call, or maybe not getting them at all, let the service call access the data instead of the Asp.net application. Of course then you have the config file for the service that needs to be cleaned, but that is easier to point to a resource that has encrypted data instead of that resource being accessable from your web server.


Or you can encrypt the data in your web.config file.

Yes you could, but try managing that from an global perspective, any time a password changes (remember PCI requires this) you need to update all the web configs you have in your system.

Or you could have one file that has this that all the web.configs point to and simply change that one file.

Granted, if your company is small enough to only have one site or service then this isn't a problem.

Re: Disconnection String

2012-06-14 16:27 • by M (unregistered)
383173 in reply to 383169
KattMan:
anony-mouse:
Haven't heard of Windows Authentication, eh?
If you're using ASP.NET you're probably using MS SQL Server, in which the proper security model is to use Windows auth instead of a hard coded login/password.


Not always, I've had Informix databases sitting behind and ASP.Net app.

I agree, the inetuser should be the one with access and use authentication, but not always easy with certian databases.


Agreed. A place I know uses asp.net backed by oracle everywhere. In fact, many of the separate oracle database servers were recently 'upgraded' to a single exadata server. Now all the apps get to share in the fun on those occasions when oracle flakes out, i.e. often.

Re: Disconnection String

2012-06-14 17:25 • by Coyne
This is a total WTF. They should have looked up a key by position that would tell them the position of the database connection key. That way, they could move the database key by changing the first key.

As it is, the database key is stuck forever at position 0. Where's the configurability?

Re: Disconnection String

2012-06-14 17:27 • by hangy (unregistered)

sColumns = "DataLink, Platform, Login, Password, Server, Database"
sTableName = "tblzApp"

Aside from being out-of-context for this method - both variables are only being assigned to and are never read?!

Re: Disconnection String

2012-06-14 17:44 • by Jeff (unregistered)
383177 in reply to 383155
KattMan:
Another WTF is how ASP.Net defaults breaks PCI compliance.

Connection strings have usernames and passwords in them in plain text when usign them this way. Either encrypt them or do not use the config file to store them, have the config file point to something else that has them and that is encrypted.
But, to decrypt them, you need the key. Where do you get that? From another file? Shouldn't that be encrypted too?

Re: Disconnection String

2012-06-14 17:49 • by Bradley (unregistered)
383178 in reply to 383168
Puzzles:
M:
Also, who the heck is still using hungarian notation? sHere, sThere, sEverywhere.

Not only that, but only one of those three was actually declared as a string.

"Dim x, y, z As String" creates z as a string but x and y as variants.


Not since vb6.

Re: Disconnection String

2012-06-14 19:43 • by Wyrm (unregistered)
383180 in reply to 383163
It's even worse than I thought at first.
If the connection string is not the first configuration line, it doesn't even return the first configuration value but the first key.
Someone really has messed this up big time.

Re: Disconnection String

2012-06-14 21:45 • by Jaime
383182 in reply to 383177
Jeff:
KattMan:
Another WTF is how ASP.Net defaults breaks PCI compliance.

Connection strings have usernames and passwords in them in plain text when usign them this way. Either encrypt them or do not use the config file to store them, have the config file point to something else that has them and that is encrypted.
But, to decrypt them, you need the key. Where do you get that? From another file? Shouldn't that be encrypted too?
DPAPI. It's secure against everyone except administrators or those with physical access to the box. Almost nothing can help you in those two cases.

Re: Disconnection String

2012-06-14 21:52 • by Jaime
383183 in reply to 383172
KattMan:
cdosrun:
KattMan:
Another WTF is how ASP.Net defaults breaks PCI compliance.

Connection strings have usernames and passwords in them in plain text when usign them this way. Either encrypt them or do not use the config file to store them, have the config file point to something else that has them and that is encrypted.

Another possible way of getting them is through some service call, or maybe not getting them at all, let the service call access the data instead of the Asp.net application. Of course then you have the config file for the service that needs to be cleaned, but that is easier to point to a resource that has encrypted data instead of that resource being accessable from your web server.


Or you can encrypt the data in your web.config file.

Yes you could, but try managing that from an global perspective, any time a password changes (remember PCI requires this) you need to update all the web configs you have in your system.

Or you could have one file that has this that all the web.configs point to and simply change that one file.

Granted, if your company is small enough to only have one site or service then this isn't a problem.
Decrypting, changing, and re-encrypting is easy to script:

Aspnet_regiis -pdf "connectionStrings"
<<change password>>
Aspnet_regiis -pef "connectionStrings"

Also, creating a parent web.config that multiple applications inherit from is a built-in feature of ASP.Net, so you don't have to write customer code to create a pointer to a single configuration. The code is entirely unaware of the inheritance.

Re: Disconnection String

2012-06-14 23:34 • by I ar the frist! (unregistered)
PCI compliance? Who the hell care about that?!

Re: Disconnection String

2012-06-14 23:48 • by Dirk (unregistered)
Where's the WTF? They are simply making a mechanism to point at different dbs by config. The enterprise library does something similar by it's default connection string mechanism.
Sure, they should have had a named key for the default connection string key, however, not a huge issue.

Re: Disconnection String

2012-06-14 23:53 • by Dirk (unregistered)
383186 in reply to 383185
Dirk:
Where's the WTF? They are simply making a mechanism to point at different dbs by config. The enterprise library does something similar by it's default connection string mechanism.
Sure, they should have had a named key for the default connection string key, however, not a huge issue.

Ummm, ignore this comment. Not enough coffee yet or I'm still high.

Re: Disconnection String

2012-06-15 03:12 • by emurphy
383187 in reply to 383162
anony-mouse:
Haven't heard of Windows Authentication, eh?
If you're using ASP.NET you're probably using MS SQL Server, in which the proper security model is to use Windows auth instead of a hard coded login/password.


Unless the web site is meant to be accessed from outside your network.

Re: Disconnection String

2012-06-15 03:44 • by JimLahey
Too many people don't know that .net lets you encrypt connection strings, besides which, your IIS should be configured in such a way that httprequests to web.config are denied by default.

Does anyone else take issue with the way the data access layer is called "DAL"? shit like that makes my blood boil, like calling your business layer "BLL" - what does that class do again? oh yeah, it logics your business layer, how silly of me.

Re: Disconnection String

2012-06-15 04:37 • by Dave (unregistered)
383190 in reply to 383184
I ar the frist!:
PCI compliance? Who the hell care about that?!


Well, since PCI compliance unambiguously guarantees impenetrable security, you simply implement PCI, then you don't need to think about security and best practices any more. It's a huge saving, and a great deal of peace of mind, for any company.

The more you know.

Re: Disconnection String

2012-06-15 05:10 • by AB (unregistered)
383191 in reply to 383155
KattMan:
Another WTF is how ASP.Net defaults breaks PCI compliance.

Connection strings have usernames and passwords in them in plain text when usign them this way. Either encrypt them or do not use the config file to store them, have the config file point to something else that has them and that is encrypted.

Another possible way of getting them is through some service call, or maybe not getting them at all, let the service call access the data instead of the Asp.net application. Of course then you have the config file for the service that needs to be cleaned, but that is easier to point to a resource that has encrypted data instead of that resource being accessable from your web server.


TRWTF. Idiots like you are what lead to code like the OP.

Re: Disconnection String

2012-06-15 06:54 • by Hewes (unregistered)
383192 in reply to 383190
Dave:
I ar the frist!:
PCI compliance? Who the hell care about that?!


Well, since PCI compliance unambiguously guarantees impenetrable security, you simply implement PCI, then you don't need to think about security and best practices any more. It's a huge saving, and a great deal of peace of mind, for any company.

The more you know.


Wow...

Just wow, seriously, you said this?

PCI is more a minimum requirement for not being as holey as a leaky sieve.

Dothing nothing but meeing the minimum requirements of PCI DSS means you qualify to call yourself more secure than than a firevault made of chocolate, nothing more.

Re: Disconnection String

2012-06-15 06:57 • by Hmmmm (unregistered)
383193 in reply to 383186
Dirk:
Ummm, ignore this comment. Not enough coffee yet or I'm still high.

Probably both if I'm any judge...

Re: Disconnection String

2012-06-15 06:59 • by Hmmmm (unregistered)
383194 in reply to 383192
Hewes:
Wow...

Just wow, seriously, you said this?

You must be new here.

-100 internets for falling for obvious troll...

Re: Disconnection String

2012-06-15 07:39 • by Silfax
383195 in reply to 383161
HungarianProf:
The Real WTF is that they do not have a string variable called HitCount (or anything that begins with Hit ...)

in Hungarian notation would that be sHitCount?

Re: Disconnection String

2012-06-15 07:40 • by Jeff (unregistered)
383196 in reply to 383182
Jaime:
Jeff:
KattMan:
Another WTF is how ASP.Net defaults breaks PCI compliance.

Connection strings have usernames and passwords in them in plain text when usign them this way. Either encrypt them or do not use the config file to store them, have the config file point to something else that has them and that is encrypted.
But, to decrypt them, you need the key. Where do you get that? From another file? Shouldn't that be encrypted too?
DPAPI. It's secure against everyone except administrators or those with physical access to the box. Almost nothing can help you in those two cases.
Hey Jamie, are you a salesman? (Saleswoman?) Your answer surely makes me think so.

1. Answer a technical question with a buzzword.

2. Assurance that it "is secure" -- an unachievable state, but a nice marketing term.

3. No discussion of how this magic might achieve its lofty promise.

Re: Disconnection String

2012-06-15 08:07 • by Bridget (unregistered)
383197 in reply to 383190
Dave:
I ar the frist!:
PCI compliance? Who the hell care about that?!


Well, since PCI compliance unambiguously guarantees impenetrable security, you simply implement PCI, then you don't need to think about security and best practices any more. It's a huge saving, and a great deal of peace of mind, for any company.

The more you know.


We must work at the same place, because I swear I've heard that before in the past few months.

Re: Disconnection String

2012-06-15 08:17 • by Todd Lewis (unregistered)
TRWTF is not doing this in Perl. Then nobody would expect it to be right anyway, so no disappointment.

[I actually like Perl. It's like python for people who aren't afraid of punctuation.]

Re: Disconnection String

2012-06-15 08:23 • by Nagesh (unregistered)
383199 in reply to 383165
PedanticCurmudgeon:
Nagesh:
Um, I'm not fluent in VB.NET, but I can't see any "look it up by position" in the code snippet here. What they are doing seems to be to ask if the key at position 0 is 'ConnectionString', and then look it up by key. In all other cases -- including when 'ConnectionString' is the key in some non-zero position -- then they pretend that whatever the key at position 0 is, is the right connection string to use!

That's much more of a WTF than doing something that works but in a unnecessarily roundabout way.
Did someone forget to switch sock-puppet names again?

"Sock puppet"? It's only a sock puppet if a reasonable person could think the names denotes an actual person. Effectively, "Nagesh" is just the accepted spelling variant for "Anonymous" here.

Re: Disconnection String

2012-06-15 08:35 • by radarbob (unregistered)
383200 in reply to 383195
Silfax:
HungarianProf:
The Real WTF is that they do not have a string variable called HitCount (or anything that begins with Hit ...)

in Hungarian notation would that be sHitCount?

+10 internets, Silfax.

Re: Disconnection String

2012-06-15 08:42 • by Pedant (unregistered)
Willing to hazard good money that all the commented out crap was an initial effort to store all their configuration in a database, including the connection strings.

All was going well until, hang on, seem to be getting some deep recursion here...

Re: Disconnection String

2012-06-15 08:48 • by PedanticCurmudgeon
383202 in reply to 383195
Silfax:
HungarianProf:
The Real WTF is that they do not have a string variable called HitCount (or anything that begins with Hit ...)

in Hungarian notation would that be sHitCount?
Does anyone have a "That's the joke!" image I can borrow?

Re: Disconnection String

2012-06-15 08:53 • by QJo
383204 in reply to 383161
HungarianProf:
The Real WTF is that they do not have a string variable called HitCount (or anything that begins with Hit ...)


Oh come on! Get the joke right. "HitList".

Re: Disconnection String

2012-06-15 08:57 • by veggen
383205 in reply to 383150
bewbs:
second!

.
.
.
.not spam

What do you mean by "not spam"? It so very much *is* spam.

Re: Disconnection String

2012-06-15 09:23 • by ¯\(°_o)/¯ I DUNNO LOL (unregistered)
383206 in reply to 383192
Hewes:
PCI is more a minimum requirement for not being as holey as a leaky sieve.

Dothing nothing but meeing the minimum requirements of PCI DSS means you qualify to call yourself more secure than than a firevault made of chocolate, nothing more.
I'll have you know that my computer has FOUR of them PCI slots!

Re: Disconnection String

2012-06-15 10:13 • by MikeD (unregistered)
383207 in reply to 383155
You don't have to have the user name and password in the connection string. Most places I worked that required PCI compliance used a trusted connection and has the app/service run with the active directory identity of a user that was setup with access to the database.
« PrevPage 1 | Page 2Next »

Add Comment