From the docs, a basic mongoose connection string is mongoose.connect('mongodb://username:password@host:port/database?options...');.
The problem is that the username:password are stored in plain text in the source code. The attack vector we are worried about is if someone was to get access to our source code they also have access to the database.
What are some strategies to avoid this vulnerability?
If someone was to gain root access to a server I believe we are up a creek no matter what, but is there a way to make it so that someone can't just get access to our source code and then compromise our DBs?
You are right in thinking that if someone gets access to the server itself it doesn't matter, so the data can be exposed in plain text on the server, but encrypting it wouldn't hurt (for example if you're looking at the file that has it).
There are two strategies for dealing with this:
For example if you were hosting on Heroku your config might look like:
{
"development": {
"db": "mongodb://localhost/app_devel"
},
"production": {
"db": process.env.MONGOLAB_URI
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With