diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 91de7ea..0f734b7 100755 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -6,6 +6,7 @@ class SessionsController < ApplicationController redirect_to home_dashboard_index_path if current_user end + def create begin @@ -17,6 +18,8 @@ class SessionsController < ApplicationController session[:id] = user.id if User.where(:id => user.id).exists? redirect_to home_dashboard_index_path else + # Removed this code, just doesn't seem specific enough! + # flash[:error] = "Either your username and password is incorrect" flash[:error] = e.message render "new" end diff --git a/app/models/user.rb b/app/models/user.rb index 43c9a75..a813974 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,6 +9,7 @@ class User < ActiveRecord::Base validates_uniqueness_of :email validates_format_of :email, :with => /.+@.+\..+/i + def self.authenticate(email, password) auth = nil user = find_by_email(email) @@ -23,6 +24,6 @@ class User < ActiveRecord::Base raise "#{email} doesn't exist!" end return auth - end - + end + end diff --git a/app/views/layouts/tutorial/broken_auth_sess/_user_pass_enum.html.erb b/app/views/layouts/tutorial/broken_auth_sess/_user_pass_enum.html.erb index 6637631..35a8015 100644 --- a/app/views/layouts/tutorial/broken_auth_sess/_user_pass_enum.html.erb +++ b/app/views/layouts/tutorial/broken_auth_sess/_user_pass_enum.html.erb @@ -90,7 +90,31 @@
+ Username and Password Enumeration - SOLUTION +
+Within /app/controllers/sessions_controller.rb
++ def create + + begin + user = User.authenticate(params[:email], params[:password]) + rescue Exception => e + end + + if user + session[:id] = user.id if User.where(:id => user.id).exists? + redirect_to home_dashboard_index_path + else + flash[:error] = "Either your username and password is incorrect" #e.message + render "new" + end + + end ++
+ Although this fix is neither systemic nor does it address the problematic code at its core (within the user model), it does provide a quick solution. On line 12, we comment out the "e.message code" and instead provide a very generic error message that lacks specificity on what credential was incorrectly entered. +
+ Enter an email address that wouldn't likely exist into the login form. Analyze the result.
+ Can you leverage this to gain unauthorized access?
+
Cross-Site Request Forgery (CSRF) - The following code was taken from: /app/controllers/application_controller.rb and /app/views/layouts/application.html.erb
-application_controller.rb<
+
application_controller.rb
# Our security guy keep talking about sea-surfing, cool story bro.