For Python website projects, I enforce the creation of a _secrets.py file in the config folder that is ignored by git and contains all sensitive constants like database information and tokens. Then, in the _base.py settings file (what all other settings files inherit from), I make sure to `from _secrets import *`. I'm not a fan of setting tokens by environment because it gets a little too unwieldy to make sure bash/z…
A Better Way to Manage the Rails Secret Token
21–30 of 60 posts
Re: A Better Way to Manage the Rails Secret Token
#22> Knowing the secret token allows an attacker to trivially impersonate any user in the application. Worse. Knowing the secret token allows an attacker to trivially execute code in your application. Don't ever let your secret token become public knowledge, and if it does, you need to change it straight away.
Doesn't Rails use randomly generated session IDs? Also, how does it allow an attacker to trivially execute code?
http://daniel.fone.net.nz/blog/2013/05/20/a-better-way-to-ma...
Re: A Better Way to Manage the Rails Secret Token
#23For Python website projects, I enforce the creation of a _secrets.py file in the config folder that is ignored by git and contains all sensitive constants like database information and tokens. Then, in the _base.py settings file (what all other settings files inherit from), I make sure to `from _secrets import *`. I'm not a fan of setting tokens by environment because it gets a little too unwieldy to make sure bash/z…
When using Heroku and similar hosts, the only way to upload files is via git push, so you won't be able to get your _secrets.py file into the server.
Re: A Better Way to Manage the Rails Secret Token
#24Earlier quoted context omitted.
Doesn't Rails use randomly generated session IDs? Also, how does it allow an attacker to trivially execute code?
> Session data is marshal-ed Ruby data, deserializing it has the same risks as YAML.load. http://daniel.fone.net.nz/blog/2013/05/20/a-better-way-to-ma...
Re: A Better Way to Manage the Rails Secret Token
#25Earlier quoted context omitted.
When using Heroku and similar hosts, the only way to upload files is via git push, so you won't be able to get your _secrets.py file into the server.
Oh, that's a very good point. I assume Heroku allows you to set environment variables? I've never really used it before, so I didn't even think of that possibility.
Re: A Better Way to Manage the Rails Secret Token
#26Earlier quoted context omitted.
If it doesn't show up in a repo file then it is a bit better.
Yes, but only marginally; You can get the environment of another process with the "ps" command trivially. If you're in a shared environment you just made it that much easier for other people to monkey with your stuff. Here's a great example of the repo file checkin fail though: http://bit.ly/10dLiDz
The common wisdom seems to be that you can forget about security in a shared environment regardless. The "secret key in environment variable" technique is mostly useful at protecting against malicious employees since it's easy to limit access to the production server but not so easy to limit access to configuration files which are in a Git repository.
Re: A Better Way to Manage the Rails Secret Token
#27We've had discussions about this several times, and haven't come up with something that's satisfactory as a generic replacement, other than "configuration could probably be improved." For one example, see this from a year ago: https://github.com/rails/rails/pull/3777#issuecomment-289375... > If we ignore them, this means a recently created, pushed and then cloned project is not going to work at all. Some people repla…
Re: A Better Way to Manage the Rails Secret Token
#28Earlier quoted context omitted.
Yes, but only marginally; You can get the environment of another process with the "ps" command trivially. If you're in a shared environment you just made it that much easier for other people to monkey with your stuff. Here's a great example of the repo file checkin fail though: http://bit.ly/10dLiDz
> If you're in a shared environment The common wisdom seems to be that you can forget about security in a shared environment regardless. The "secret key in environment variable" technique is mostly useful at protecting against malicious employees since it's easy to limit access to the production server but not so easy to limit access to configuration files which are in a Git repository.
Re: A Better Way to Manage the Rails Secret Token
#29Earlier quoted context omitted.
> Session data is marshal-ed Ruby data, deserializing it has the same risks as YAML.load. http://daniel.fone.net.nz/blog/2013/05/20/a-better-way-to-ma...
That's a bit surprising. I'd be interested to read the reasoning behind this design decision as most frameworks I have used store session data in a database rather than directly in the cookie. Well I guess there is a pretty damn good reason given Rails' reputation.
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
# ShopMobile::Application.config.session_store :active_record_storeRe: A Better Way to Manage the Rails Secret Token
#30Eh... Keeping that in the system environment isn't really any better than hardcoded in a file. There's a long history of "do not trust the system environment" when it comes to security so I can't say I'd recommend this. Last I checked it was also fairly trivial to dump this data out of a running program... Unless you're grabbing that key out of "secure memory", a HSM or a TPM then its not really particularly secure.
If it doesn't show up in a repo file then it is a bit better.