Skip to content

Commit 12c9540

Browse files
committed
Always require a fully authenticated user for controllers
There are only a few exceptions when no authenticated user is needed. The app's behavior shouldn't be touched by this commit, it is rather a refactoring and safeguard.
1 parent 866fd27 commit 12c9540

14 files changed

+19
-20
lines changed

app/controllers/application_controller.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ class ApplicationController < ActionController::Base
1313
LEGAL_SETTINGS = CodeOcean::Config.new(:code_ocean).read[:legal] || {}
1414
MONITORING_USER_AGENT = /updown\.io/
1515

16-
before_action :deny_access_from_render_host
16+
before_action :require_fully_authenticated_user!
17+
before_action :deny_access_from_render_host, prepend: true
1718
after_action :verify_authorized, except: %i[welcome]
18-
around_action :mnemosyne_trace
19-
around_action :switch_locale
19+
around_action :mnemosyne_trace, prepend: true
20+
around_action :switch_locale, prepend: true
2021
before_action :set_sentry_context, :load_embed_options, :set_document_policy
22+
skip_before_action :require_fully_authenticated_user!, only: %i[welcome]
2123
protect_from_forgery(with: :exception, prepend: true)
2224
rescue_from Pundit::NotAuthorizedError, with: :render_not_authorized
2325
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
@@ -48,7 +50,7 @@ def welcome
4850

4951
private
5052

51-
def require_user!
53+
def require_fully_authenticated_user!
5254
raise Pundit::NotAuthorizedError unless current_user
5355
end
5456

app/controllers/code_ocean/files_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FilesController < ApplicationController
1111
skip_before_action :deny_access_from_render_host, only: :render_protected_upload
1212
skip_before_action :verify_authenticity_token, only: :render_protected_upload
1313
skip_before_action :set_sentry_context, only: :render_protected_upload
14-
before_action :require_user!, except: :render_protected_upload
14+
skip_before_action :require_fully_authenticated_user!, only: :render_protected_upload
1515

1616
# In case the .realpath cannot resolve a file (for example because it is no longer available)
1717
rescue_from Errno::ENOENT, with: :render_not_found

app/controllers/community_solutions_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class CommunitySolutionsController < ApplicationController
55
include RedirectBehavior
66
include SubmissionParameters
77

8-
before_action :require_user!
98
before_action :set_community_solution, only: %i[edit update]
109
before_action :set_community_solution_lock, only: %i[edit]
1110
before_action :set_exercise_and_submission, only: %i[edit update]

app/controllers/events_controller.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22

33
class EventsController < ApplicationController
4-
before_action :require_user!
5-
64
def create
75
@event = Event.new(event_params)
86
authorize!

app/controllers/exercises_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ExercisesController < ApplicationController
1919
before_action :set_available_tips, only: %i[implement show new edit]
2020

2121
skip_before_action :verify_authenticity_token, only: %i[import_task import_uuid_check]
22+
skip_before_action :require_fully_authenticated_user!, only: %i[import_task import_uuid_check]
2223
skip_after_action :verify_authorized, only: %i[import_task import_uuid_check]
2324
skip_after_action :verify_policy_scoped, only: %i[import_task import_uuid_check], raise: false
2425

app/controllers/external_users_controller.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
class ExternalUsersController < ApplicationController
44
include TimeHelper
55

6-
before_action :require_user!
7-
86
def authorize!
97
authorize(@user || @users)
108
end

app/controllers/flowr_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
class FlowrController < ApplicationController
44
def insights
5-
require_user!
65
# get the latest submission for this user that also has a test run (i.e. structured_errors if applicable)
76
submission = Submission.joins(:testruns)
87
.where(submissions: {contributor: current_contributor})

app/controllers/internal_users_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
class InternalUsersController < ApplicationController
44
include CommonBehavior
55

6-
before_action :require_user!, except: %i[activate forgot_password reset_password]
76
before_action :require_activation_token, only: :activate
87
before_action :require_reset_password_token, only: :reset_password
98
before_action :set_user, only: MEMBER_ACTIONS + %i[change_password]
109
before_action :collect_set_and_unset_study_group_memberships, only: MEMBER_ACTIONS + %i[create]
11-
after_action :verify_authorized, except: %i[activate forgot_password reset_password]
10+
skip_before_action :require_fully_authenticated_user!, only: %i[activate forgot_password reset_password]
11+
skip_after_action :verify_authorized, only: %i[activate forgot_password reset_password]
1212

1313
def activate
1414
set_up_password if request.patch? || request.put?

app/controllers/live_streams_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class LiveStreamsController < ApplicationController
99
skip_before_action :deny_access_from_render_host, only: :download_submission_file
1010
skip_before_action :verify_authenticity_token, only: :download_submission_file
1111
skip_before_action :set_sentry_context, only: :download_submission_file
12-
before_action :require_user!, except: :download_submission_file
12+
skip_before_action :require_fully_authenticated_user!, only: :download_submission_file
1313

1414
def download_submission_file
1515
@submission = AuthenticatedUrlHelper.retrieve!(Submission, request)

app/controllers/ping_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
class PingController < ApplicationController
44
before_action :postgres_connected!, :runner_manager_healthy!
5-
after_action :verify_authorized, except: %i[index]
5+
skip_before_action :require_fully_authenticated_user!, only: %i[index]
6+
skip_after_action :verify_authorized, only: %i[index]
67

78
def index
89
render json: {

0 commit comments

Comments
 (0)