diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 70a5f10..5926b40 100755 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,5 +1,6 @@ class AdminController < ApplicationController + # before_filter :administrative skip_before_filter :has_info def dashboard diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index eba7470..a0ef5cf 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -18,13 +18,13 @@ class ApplicationController < ActionController::Base end def is_admin? - admin = current_user.admin if current_user + current_user.admin if current_user end def administrative if not is_admin? reset_session - redirect_to login_path + redirect_to root_url end end diff --git a/app/views/layouts/tutorial/url_access/_url_access_first.html.erb b/app/views/layouts/tutorial/url_access/_url_access_first.html.erb index 692f6a7..62cdc0c 100755 --- a/app/views/layouts/tutorial/url_access/_url_access_first.html.erb +++ b/app/views/layouts/tutorial/url_access/_url_access_first.html.erb @@ -16,7 +16,7 @@
- Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor + Many web applications check URL access rights before rendering protected links and buttons. However, applications need to perform similar access control checks each time these pages are accessed, or attackers will be able to forge URLs to access these hidden pages anyway.
@@ -30,7 +30,17 @@
- Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor +

+ Rails provides the ability to apply before_filter(s) which run prior to rendering content to the user. This is helpful when restricting access to content based on the user's role. Currently, the methods to apply a before_filter already exist in the application controller but were forgotten when creating the administrative functionality. Notice an asbsence of the before_filter within app/controllers/admin_controller.rb +

+
+				<%= %q{
+				class AdminController < ApplicationController
+				
+				  skip_before_filter :has_info
+				} %>
+			  
+
@@ -44,7 +54,37 @@
- Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor +

Failure to Restrict URL Access - ATTACK

+

+ Request the following URL /admin/1/dashboard and have fun :-) +

+

Failure to Restrict URL Access - SOLUTION

+

+ The code is already available to restrict access to the admin controller by role within app/controllers/application_controller.rb: +

+
+				helper_method :current_user, :is_admin?
+				
+				def is_admin?
+			    	current_user.admin if current_user 
+			  	end
+			
+			  	def administrative
+			  	  if not is_admin?
+			  	   reset_session
+			  	   redirect_to root_url
+			  	 end
+			  	end
+			  
+

+ Then add the following line within app/controllers/admin_controller.rb +

+
+				class AdminController < ApplicationController
+
+				  before_filter :administrative
+				  skip_before_filter :has_info
+			  
@@ -58,7 +98,7 @@
- Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor + I bet there is some admin functionality in here :-)