TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Securing the Rails session secret

34 点作者 phsr超过 12 年前

6 条评论

thibaut_barrere超过 12 年前
Sharing a few thoughts:<p>- having a per-machine key auto-generated will not work properly with PaaS (such as Heroku, DotCloud etc), especially if you have N machines behind a load-balancer. In that case they need to share the key, so using a Heroku production variable or similar will have to be used instead.<p>- I believe we (Rails users) should at least move away from having a hard-coded key in the source by default, and instead generate and deploy it by other ways (such as symlinking like database.yml or PaaS variables), since having it in the source put an onus on people having access to the source code (such as freelancers/contractors, or other team members without deploy access etc). This should be treated sensitively!<p>- in today's practice of having the key in the source code, some staging environments would currently also have the same key by default, and sometimes these are less secure or up-to-date compared to production environment, providing another attack vector maybe.
评论 #5009236 未加载
LaGrange超过 12 年前
I like the solution I stole from rstat.us: you have an off-repository location for the token If there's none:<p>* on production you crash,<p>* on dev, you autogenerate one and save it to a config file that's possibly dev-only,<p>* during automated tests you just autogenerate something and live with it.<p>Here's the nice replacement for secret_token.rb: <a href="https://github.com/hotsh/rstat.us/blob/master/config/initializers/secret_token.rb" rel="nofollow">https://github.com/hotsh/rstat.us/blob/master/config/initial...</a>
MattRogish超过 12 年前
We use Heroku and PaaS environment variables, with a default value if you're running in development/test mode, e.g.<p>if Rails.env.production? &#38;&#38; ENV['SECRET_TOKEN'].blank? raise 'SECRET_TOKEN environment variable must be set!' end<p>secret_token = ENV['SECRET_TOKEN'] || 'safdasfjlkj...'
评论 #5008263 未加载
neilmiddleton超过 12 年前
"Users would still be logged out on every deploy, but I believe this is a minor problem for most people."<p>Would be an absolute pain for users of things such as Github who deploy several times a day.
X-Istence超过 12 年前
I store the secret inside of my paste config file ... which is picked up by uwsgi and passed to my Pyramid app.<p>You are required to configure my app anyway, and I can store it inside of a config file that doesn't need to be made public or stored in version control.
dllthomas超过 12 年前
"would be world-readable because it’s only used for deriving secret keys"<p>I don't like this.<p>Otherwise, not a bad exploration.
评论 #5007576 未加载