Ever Wonder What Happened to Your Azure Website Connection String?
Join the DZone community and get the full member experience.Join For Free
the curious case of the missing azure connection string
you’re new to azure and you’re working on deploying your shiny new web application to azure’s website service. but you’re storing your web application in a public repository like github , bitbucket or codeplex . currently, through any number of possible techniques you have managed to keep your connection strings out of public view by not checking it in. now you’re trying to figure out how to continue committing to your repository and deploy to azure without having to commit your connection string just so azure websites can know about. sound familiar?
well, kudos to you. at least you recognize an easily missed security hole of accidentally exposing sensitive application data through whats referred to as security misconfiguration. azure website connection strings makes this potential security rule, easier to follow. but first, why is it sensitive data?
security misconfiguration is a serious security flaw so much so that owasp has moved it up from #6 to #5 of its 2013 top 10 web application security flaws . aptly named, connection strings within our web application is one of the gateways to a prized position, our application data. i have talked about leaky application data before, but this is a vulnerability that really makes attackers life a lot easier.
when self-hosting a web application, not only do we have to secure information such as connection strings, but at a deeper level we have to ensure that access to such files is not available as well. but this isn’t a article on an securing an application file resources, so let’s bring it back to what azure website’s can do to make our life easier when it comes to securing our application’s connection strings.
azure website connection strings
assuming your web application is running with a similar connection string as below:
<add name=”shpt” connectionstring=”…..”/>
azure websites service makes it extremely easy to keep information such as our web.config connection strings out of our repository of choice. within azure’s management portal under the website service, you can select the “ configure” tab.
from here we can scroll down to the connection strings area to find where you can specify an azure website connection strings. here you can add a new connection string who’s name matches the name=”” field you specified in your web.config.
now, when your application is committed to your repository and building and deployment processes occur, azure will swap out and replace the connection string you have listed where the names match with the one that azure possesses.
note: when working with visual studio, it is possible for some of the described azure connection string setup to be taken care of for you depending on whether you configured azure originally at the onset of your web application.
this article is about bringing to light what azure will do for you when it comes to making connections string available to your web application. but, a problem that might have jumped out to you is “ how do you make a connection string available to you for local development as well ?”
having your cake and eating it too
when it comes to connecting to a local database, ensuring that local database connection information is not publicly available, all the while ensuring azure has the proper connection strings available can be tricky. there are a number of different scenarios that you might find yourself in. therefore, i will throw out a few approaches people might take to juggle that typical scenario. this is by no means an exhaustive list.
use a web.config transform as outlined in this msdn article . this allows you to have a separate file that contains the specific database connection information for your connection string. then the placeholder for the connection string in your web.config is replaced appropriately with the correct database connection string that is retained in the separate file.
another approach is using the “ configsource” attribute of the “ connectionstrings” element in your web.config to specify a separate file similar to the one in option #1 but a little less verbose. there is a bit more to this option but you can read a detailed overview and approach to this here as well as the benefits it offers.
in either case, the security benefit is gained when we apply a separation of concerns to our web.config and ensure that this separation is safeguarded. any security benefit will be diminished if we don’t ensure that this additional file is not leaked through a public repository or other means.
this was a short one, but the purpose of this article was just to point out what the azure website service is capable of doing via convention to help safeguard important web application information without having to break a cardinal security rule. in addition, it brings to light the importance of ensuring that we keep important application information secured and don’t commit what is deemed security misconfiguration. information such as your database connection strings can expose incredible security holes in our application and it is up to you to ensure you have implemented the proper security hardening steps and azure website connection strings make this easier. in the very near future, i will be putting up the article that details how you can ensure your web application doesn’t fall prey to security misconfiguration. so stay tuned.
Opinions expressed by DZone contributors are their own.