A few months ago, I created a bot to scan GitHub for publicly exposed Azure Storage connection strings. The bot then notifies the repository owners (to its best effort). What gave me the idea? Well, I accidentally pushed a connection string to GitHub. Even though it was a personal demo project and there's no sensitive data, I thought that it was still a poor practice on my part
Upon launch, the scanner quickly found a multitude of exposed connection strings. Since then, it has been detecting about 100 some valid unique connection strings per month:
The numbers aren't really too surprising. It's so easy to just hard code the connection string somewhere and tell yourself "I'll remove it later. Just let me quickly get the prototype out." Guess what, if you're using GIT and making commits along the way, it's in your commit history.
Environment variables to the rescue!
Since then, I forced myself to put all the connection strings, application IDs, and application secrets in environment variables -- even for personal or demo projects. Why environment variables? Because most popular hosting platforms support them. Here are a few reference links to managing app configurations: Azure Web Apps, Azure Cloud Service, Heroku, App Harbor, etc.
I recognize that even environment variables aren't 100% safe. It's probably okay for mid size applications that can afford to have "secrets" in memory for a short period of time. If your application is handling million dollar transactions, I'd recommend looking into Azure Key Vault.