Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8200

Show
Ignore:
Timestamp:
11/24/07 22:41:16 (11 months ago)
Author:
nzkoz
Message:

Improve error messages when providing a secret that is too short. Closes #10238 [Henrik N]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/session/cookie_store.rb

    r8184 r8200  
    2626#             secret is not vulnerable to a dictionary attack. Therefore, 
    2727#             you should choose a secret consisting of random numbers and 
    28 #             letters and preferably more than 30 characters. 
     28#             letters and more than 30 characters. 
    2929# 
    3030#             Example:  :secret => '449fe2e7daee471bffae2fd8dc02313d' 
     
    3939  # Cookies can typically store 4096 bytes. 
    4040  MAX = 4096 
     41  SECRET_MIN_LENGTH = 30 # characters 
    4142 
    4243  # Raised when storing more than 4K of session data. 
     
    8586 
    8687    if secret.blank? 
    87       raise ArgumentError, 'A secret is required to generate an integrity hash for cookie session data. Use config.action_controller.session = { :session_key => "_myapp_session", :secret => "some secret phrase" } in config/environment.rb' 
     88      raise ArgumentError, %Q{A secret is required to generate an integrity hash for cookie session data. Use config.action_controller.session = { :session_key => "_myapp_session", :secret => "some secret phrase of at least #{SECRET_MIN_LENGTH} characters" } in config/environment.rb} 
    8889    end 
    8990 
    90     if secret.length < 30 
    91       raise ArgumentError, "Secret should be something secure, like #{CGI::Session.generate_unique_id}.  The value you provided: [#{secret}]" 
     91    if secret.length < SECRET_MIN_LENGTH 
     92      raise ArgumentError, %Q{Secret should be something secure, like "#{CGI::Session.generate_unique_id}".  The value you provided, "#{secret}", is shorter than the minimum length of #{SECRET_MIN_LENGTH} characters} 
    9293    end 
    9394  end