Rails mailer / smtp - 潜在的安全问题?

时间:2011-08-03 14:49:52

标签: ruby-on-rails-3 smtp

在Rails中使用SMTP设置发送电子邮件时,您需要提供用户名和密码才能从您的帐户发送电子邮件。但是,在您的代码中以纯文本形式将密码放入网站的电子邮件帐户是不是有点危险?有更安全的方法吗?

config.action_mailer.smtp_settings = {
        :address => "address_here",
        :port => 'port_#_here',
        :domain => "example.com",
        :authentication => :plain,
        :user_name => "user@example.com",
        :password => "foobar",
        :enable_starttls_auto => true
  }

1 个答案:

答案 0 :(得分:1)

这可能不是开发环境的问题,因为您可能正在使用不需要身份验证的服务器或某种虚拟帐户。

对于生产环境,我经常看到/使用的模式是在环境中保留用户名,密码等信息,例如:

config.action_mailer.smtp_settings = {
        :address => "address_here",
        :port => 'port_#_here',
        :domain => "example.com",
        :authentication => :plain,
        :user_name => ENV['EMAIL_USERNAME'],
        :password => ENV['EMAIL_PASSWORD'],
        :enable_starttls_auto => true
  }

这样攻击者就必须获得对生产箱本身的访问才能获取此信息。如果您将应用程序部署到Heroku,例如使用Sendgrid插件为您发送电子邮件 - 该插件将使您遵循该模式。