Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

allow actions to be called on those not using default authorization before_actions

ulfertsed5a16223002
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 700a0c132ed..ebb0b295951 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -36,6 +36,7 @@ class AccountController < ApplicationController
# prevents login action to be filtered by check_if_login_required application scope filter
skip_before_action :check_if_login_required
+ no_authorization_required!
before_action :apply_csp_appends, only: %i[login]
before_action :disable_api
diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb
index fee13edbd99..8093becbaf1 100644
--- a/app/controllers/activities_controller.rb
+++ b/app/controllers/activities_controller.rb
@@ -30,7 +30,7 @@ class ActivitiesController < ApplicationController
include Layout
menu_item :activity
- before_action :find_optional_project,
+ before_action :authorize_in_optional_project,
:verify_activities_module_activated,
:determine_subprojects,
:determine_author,
diff --git a/app/controllers/angular_controller.rb b/app/controllers/angular_controller.rb
index d44fd99127a..8697a2fb39a 100644
--- a/app/controllers/angular_controller.rb
+++ b/app/controllers/angular_controller.rb
@@ -29,6 +29,8 @@
class AngularController < ApplicationController
before_action :require_login
+ no_authorization_required!
+
def empty_layout
# Frontend will handle rendering
# but we will need to render with layout
diff --git a/app/controllers/api_docs_controller.rb b/app/controllers/api_docs_controller.rb
index 50ac41572ef..5a1bec3d2ed 100644
--- a/app/controllers/api_docs_controller.rb
+++ b/app/controllers/api_docs_controller.rb
@@ -28,6 +28,7 @@
class APIDocsController < ApplicationController
before_action :require_login
+ no_authorization_required! only: :index
helper API::APIDocsHelper
diff --git a/app/controllers/colors_controller.rb b/app/controllers/colors_controller.rb
index 018c6cbfaac..569dacf9540 100644
--- a/app/controllers/colors_controller.rb
+++ b/app/controllers/colors_controller.rb
@@ -28,6 +28,7 @@
class ColorsController < ApplicationController
before_action :require_admin_unless_readonly_api_request
+ authorization_checked! only: %i[index show new edit create update confirm_destroy destroy]
layout "admin"
diff --git a/app/controllers/concerns/accounts/omniauth_login.rb b/app/controllers/concerns/accounts/omniauth_login.rb
index efb866c8966..96a7a447531 100644
--- a/app/controllers/concerns/accounts/omniauth_login.rb
+++ b/app/controllers/concerns/accounts/omniauth_login.rb
@@ -38,10 +38,13 @@ module Accounts::OmniauthLogin
# the other filters are not applicable either since OmniAuth is doing authentication
# itself
%i[
- verify_authenticity_token user_setup
- check_if_login_required check_session_lifetime
+ verify_authenticity_token
+ user_setup
+ check_if_login_required
+ check_session_lifetime
]
.each { |key| skip_before_action key, only: [:omniauth_login] }
+ no_authorization_required! only: %i[omniauth_login omniauth_failure]
helper :omniauth
end
diff --git a/app/controllers/custom_styles_controller.rb b/app/controllers/custom_styles_controller.rb
index 692a06ec23f..228c47c8343 100644
--- a/app/controllers/custom_styles_controller.rb
+++ b/app/controllers/custom_styles_controller.rb
@@ -30,12 +30,19 @@ class CustomStylesController < ApplicationController
layout "admin"
menu_item :custom_style
+ UNGUARDED_ACTIONS = %i[logo_download
+ export_logo_download
+ export_cover_download
+ favicon_download
+ touch_icon_download].freeze
+
before_action :require_admin,
- except: %i[logo_download export_logo_download export_cover_download favicon_download touch_icon_download]
+ except: UNGUARDED_ACTIONS
before_action :require_ee_token,
- except: %i[upsale logo_download export_logo_download export_cover_download favicon_download touch_icon_download]
+ except: UNGUARDED_ACTIONS + %i[upsale]
skip_before_action :check_if_login_required,
- only: %i[logo_download export_logo_download export_cover_download favicon_download touch_icon_download]
+ only: UNGUARDED_ACTIONS
+ no_authorization_required! only: UNGUARDED_ACTIONS
def show
@custom_style = CustomStyle.current || CustomStyle.new
diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb
index 6f4cc9c089e..3dc66c8bdea 100644
--- a/app/controllers/favorites_controller.rb
+++ b/app/controllers/favorites_controller.rb
@@ -29,6 +29,7 @@
class FavoritesController < ApplicationController
before_action :find_favored_by_object
before_action :require_login
+ no_authorization_required! only: %i[favorite unfavorite]
def favorite
if @favored.visible?(User.current)
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index c305bb1c7f7..ba45fc56000 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -31,6 +31,8 @@ class GroupsController < ApplicationController
layout "admin"
before_action :require_admin, except: %i[show]
+ no_authorization_required! only: %i[show]
+
before_action :find_group, only: %i[destroy update show create_memberships destroy_membership
edit_membership add_users]
diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb
index 2af67cb280a..ffcc23bfe19 100644
--- a/app/controllers/help_controller.rb
+++ b/app/controllers/help_controller.rb
@@ -27,6 +27,8 @@
#++
class HelpController < ApplicationController
+ no_authorization_required! only: %i[keyboard_shortcuts text_formatting]
+
def keyboard_shortcuts
redirect_to OpenProject::Static::Links[:shortcuts][:href]
end
diff --git a/app/controllers/highlighting_controller.rb b/app/controllers/highlighting_controller.rb
index 6cd953a7f8f..b67442cd91f 100644
--- a/app/controllers/highlighting_controller.rb
+++ b/app/controllers/highlighting_controller.rb
@@ -29,6 +29,7 @@
class HighlightingController < ApplicationController
before_action :determine_freshness
skip_before_action :check_if_login_required, only: [:styles]
+ no_authorization_required! only: [:styles]
def styles
response.content_type = Mime[:css]
diff --git a/app/controllers/homescreen_controller.rb b/app/controllers/homescreen_controller.rb
index c84ed013104..a989230b62a 100644
--- a/app/controllers/homescreen_controller.rb
+++ b/app/controllers/homescreen_controller.rb
@@ -28,6 +28,7 @@
class HomescreenController < ApplicationController
skip_before_action :check_if_login_required, only: [:robots]
+ no_authorization_required! only: %i[index robots]
layout "global"
diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb
index cd408645845..31e664f0e60 100644
--- a/app/controllers/journals_controller.rb
+++ b/app/controllers/journals_controller.rb
@@ -29,9 +29,12 @@
#++
class JournalsController < ApplicationController
- before_action :find_optional_project, only: [:index]
- before_action :find_journal, only: [:diff]
- before_action :ensure_permitted, only: [:diff]
+ before_action :authorize_in_optional_project, only: [:index]
+ before_action :find_journal,
+ :ensure_permitted,
+ only: [:diff]
+ authorization_checked! only: %i[diff]
+
accept_key_auth :index
menu_item :issues
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index efe9fcb66f3..397afab2373 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -32,6 +32,8 @@ class MessagesController < ApplicationController
model_object Message, scope: Forum
before_action :find_object_and_scope
before_action :authorize, except: %i[edit update destroy]
+ # Checked inside the method.
+ no_authorization_required! only: %i[edit update destroy]
include AttachmentsHelper
include PaginationHelper
diff --git a/app/controllers/my/auto_login_tokens_controller.rb b/app/controllers/my/auto_login_tokens_controller.rb
index 21de9f6f221..f0222b9f856 100644
--- a/app/controllers/my/auto_login_tokens_controller.rb
+++ b/app/controllers/my/auto_login_tokens_controller.rb
@@ -1,5 +1,8 @@
module My
class AutoLoginTokensController < ::ApplicationController
+ before_action :require_login
+ no_authorization_required! only: %i(destroy)
+
before_action :find_token, only: %i(destroy)
layout "my"
diff --git a/app/controllers/my/sessions_controller.rb b/app/controllers/my/sessions_controller.rb
index b243be219a6..2c6094505d6 100644
--- a/app/controllers/my/sessions_controller.rb
+++ b/app/controllers/my/sessions_controller.rb
@@ -1,6 +1,8 @@
module My
class SessionsController < ::ApplicationController
before_action :require_login
+ no_authorization_required! only: %i(index show destroy)
+
self._model_object = ::Sessions::UserSession
before_action :find_model_object, only: %i(show destroy)
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb
index 52937b948e4..95bd8021132 100644
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@ -39,6 +39,22 @@ class MyController < ApplicationController
before_action :set_grouped_ical_tokens, only: %i[access_token]
before_action :set_ical_token, only: %i[revoke_ical_token]
+ no_authorization_required! only: %i[account
+ update_account
+ settings
+ update_settings
+ password
+ change_password
+ access_token
+ delete_storage_token
+ notifications
+ reminders
+ generate_rss_key
+ revoke_rss_key
+ generate_api_key
+ revoke_api_key
+ revoke_ical_token]
+
menu_item :account, only: [:account]
menu_item :settings, only: [:settings]
menu_item :password, only: [:password]
@@ -177,6 +193,8 @@ class MyController < ApplicationController
redirect_to action: 'access_token'
end
+ private
+
def default_breadcrumb
I18n.t(:label_my_account)
end
@@ -185,8 +203,6 @@ class MyController < ApplicationController
false
end
- private
-
def redirect_if_password_change_not_allowed_for(user)
unless user.change_password_allowed?
flash[:error] = I18n.t(:notice_can_t_change_password)
diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb
index 92d31cf6c08..3455f2d1324 100644
--- a/app/controllers/news_controller.rb
+++ b/app/controllers/news_controller.rb
@@ -36,7 +36,7 @@ class NewsController < ApplicationController
before_action :find_project_from_association, except: %i[new create index]
before_action :find_project, only: %i[new create]
before_action :authorize, except: [:index]
- before_action :find_optional_project, only: [:index]
+ before_action :authorize_in_optional_project, only: [:index]
accept_key_auth :index
def index
diff --git a/app/controllers/oauth/auth_base_controller.rb b/app/controllers/oauth/auth_base_controller.rb
index 1428e523019..89a6b5f88fe 100644
--- a/app/controllers/oauth/auth_base_controller.rb
+++ b/app/controllers/oauth/auth_base_controller.rb
@@ -37,6 +37,8 @@ module OAuth
prepend_before_action :extend_content_security_policy
skip_before_action :check_if_login_required
+ no_authorization_required!
+
layout "only_logo"
def extend_content_security_policy
diff --git a/app/controllers/oauth/grants_controller.rb b/app/controllers/oauth/grants_controller.rb
index e38afe156b1..c4587b5e5e8 100644
--- a/app/controllers/oauth/grants_controller.rb
+++ b/app/controllers/oauth/grants_controller.rb
@@ -29,6 +29,7 @@
module OAuth
class GrantsController < ::ApplicationController
before_action :require_login
+ authorization_checked! only: %i[index revoke_application]
layout "my"
menu_item :access_token
@@ -57,6 +58,7 @@ module OAuth
def find_application
::Doorkeeper::Application
+ .authorized_for(current_user)
.where(id: params[:application_id])
.select(:name, :id)
.take
diff --git a/app/controllers/oauth_clients_controller.rb b/app/controllers/oauth_clients_controller.rb
index 4a9823bc427..afe14e36985 100644
--- a/app/controllers/oauth_clients_controller.rb
+++ b/app/controllers/oauth_clients_controller.rb
@@ -38,6 +38,8 @@ class OAuthClientsController < ApplicationController
before_action :set_code, only: [:callback]
before_action :set_connection_manager, only: [:callback]
+ no_authorization_required! only: %i[callback ensure_connection]
+
after_action :clear_oauth_state_cookie, only: [:callback]
# Provide the OAuth2 "callback" endpoint.
diff --git a/app/controllers/onboarding_controller.rb b/app/controllers/onboarding_controller.rb
index b63925e1b9b..95bc94725a4 100644
--- a/app/controllers/onboarding_controller.rb
+++ b/app/controllers/onboarding_controller.rb
@@ -27,6 +27,8 @@
#++
class OnboardingController < ApplicationController
+ no_authorization_required! only: %i[user_settings]
+
def user_settings
@user = User.current
diff --git a/app/controllers/placeholder_users_controller.rb b/app/controllers/placeholder_users_controller.rb
index 8ec919515c3..daaf585fce5 100644
--- a/app/controllers/placeholder_users_controller.rb
+++ b/app/controllers/placeholder_users_controller.rb
@@ -30,6 +30,7 @@ class PlaceholderUsersController < ApplicationController
include EnterpriseTrialHelper
layout "admin"
before_action :authorize_global, except: %i[show]
+ no_authorization_required! only: %i[show]
before_action :find_placeholder_user, only: %i[show
edit
diff --git a/app/controllers/projects/menus_controller.rb b/app/controllers/projects/menus_controller.rb
index 57edb6124e8..08c92d81fc3 100644
--- a/app/controllers/projects/menus_controller.rb
+++ b/app/controllers/projects/menus_controller.rb
@@ -29,6 +29,7 @@ module Projects
class MenusController < ApplicationController
# No authorize as every user (or logged in user)
# is allowed to see the menu.
+ no_authorization_required! only: :show
def show
projects_menu = Menus::Projects.new(controller_path: params[:controller_path], params:, current_user:)
diff --git a/app/controllers/projects/queries_controller.rb b/app/controllers/projects/queries_controller.rb
index bf9bbc36fd1..27b7018364e 100644
--- a/app/controllers/projects/queries_controller.rb
+++ b/app/controllers/projects/queries_controller.rb
@@ -30,6 +30,7 @@ class Projects::QueriesController < ApplicationController
include Projects::QueryLoading
# No need for a more specific authorization check. That is carried out in the contracts.
+ no_authorization_required! only: %i[show new create rename update publish unpublish destroy]
before_action :require_login
before_action :find_query, only: %i[show rename update destroy publish unpublish]
before_action :build_query_or_deny_access, only: %i[new create]
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index a23acff93c7..3d09898e072 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -36,6 +36,8 @@ class ProjectsController < ApplicationController
before_action :authorize_global, only: %i[new]
before_action :require_admin, only: %i[destroy destroy_info]
+ no_authorization_required! only: %i[index]
+
include SortHelper
include PaginationHelper
include QueriesHelper
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index dbdf68110eb..2b526534d47 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -29,7 +29,7 @@
class SearchController < ApplicationController
include Layout
- before_action :find_optional_project,
+ before_action :authorize_in_optional_project,
:prepare_tokens
LIMIT = 10
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 1a599d96d23..9f7ea9ea6ef 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -44,6 +44,9 @@ class UsersController < ApplicationController
before_action :authorize_for_user, only: [:destroy]
before_action :check_if_deletion_allowed, only: %i[deletion_info
destroy]
+ no_authorization_required! only: %i[show]
+ authorization_checked! only: %i[destroy deletion_info]
+
before_action :set_current_activity_page, only: [:show]
# Password confirmation helpers and actions
diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb
index af71ecb1556..9d367af4b51 100644
--- a/app/controllers/watchers_controller.rb
+++ b/app/controllers/watchers_controller.rb
@@ -27,16 +27,15 @@
#++
class WatchersController < ApplicationController
- before_action :find_watched_by_object
- before_action :find_project
- before_action :require_login, :check_project_privacy, only: %i[watch unwatch]
+ before_action :find_watched_by_object,
+ :find_project,
+ :require_login,
+ :deny_access_unless_visible
+
+ authorization_checked! only: %i[watch unwatch]
def watch
- if @watched.respond_to?(:visible?) && [email protected]?(User.current)
- render_403
- else
- set_watcher(User.current, true)
- end
+ set_watcher(User.current, true)
end
def unwatch
@@ -60,4 +59,8 @@ class WatchersController < ApplicationController
@watched.set_watcher(user, watching)
redirect_back(fallback_location: home_url)
end
+
+ def deny_access_unless_visible
+ deny_access unless @watched.visible?(User.current)
+ end
end
diff --git a/app/controllers/work_packages/auto_completes_controller.rb b/app/controllers/work_packages/auto_completes_controller.rb
index 58152a1e5ff..f5533e281c7 100644
--- a/app/controllers/work_packages/auto_completes_controller.rb
+++ b/app/controllers/work_packages/auto_completes_controller.rb
@@ -29,6 +29,9 @@
require "rack/utils"
class WorkPackages::AutoCompletesController < ApplicationController
+ # Authorization is checked by the query.
+ no_authorization_required! only: :index
+
def index
@work_packages = work_packages_matching_query_prop
diff --git a/app/controllers/work_packages/progress_controller.rb b/app/controllers/work_packages/progress_controller.rb
index d9e5cfa196a..f10dc61cf1e 100644
--- a/app/controllers/work_packages/progress_controller.rb
+++ b/app/controllers/work_packages/progress_controller.rb
@@ -37,6 +37,7 @@ class WorkPackages::ProgressController < ApplicationController
layout false
before_action :set_work_package
before_action :extract_persisted_progress_attributes, only: %i[edit create update]
+ authorization_checked! only: %i[new edit create update]
helper_method :modal_class
diff --git a/app/controllers/work_packages_controller.rb b/app/controllers/work_packages_controller.rb
index ab209aadfa2..f66dcea7711 100644
--- a/app/controllers/work_packages_controller.rb
+++ b/app/controllers/work_packages_controller.rb
@@ -36,9 +36,10 @@ class WorkPackagesController < ApplicationController
before_action :authorize_on_work_package,
:project, only: :show
- before_action :find_optional_project,
+ before_action :authorize_in_optional_project,
:check_allowed_export,
:protect_from_unauthorized_export, only: :index
+ authorization_checked! only: %i[index show]
before_action :load_and_validate_query, only: :index, unless: -> { request.format.html? }
before_action :load_work_packages, only: :index, if: -> { request.format.atom? }
diff --git a/modules/avatars/app/controllers/avatars/avatar_controller.rb b/modules/avatars/app/controllers/avatars/avatar_controller.rb
index 39dc2c32acf..a5a68b0f74e 100644
--- a/modules/avatars/app/controllers/avatars/avatar_controller.rb
+++ b/modules/avatars/app/controllers/avatars/avatar_controller.rb
@@ -3,6 +3,8 @@ module ::Avatars
before_action :ensure_enabled
before_action :find_avatar
+ no_authorization_required!
+
def show
send_file @avatar.diskfile,
filename: filename_for_content_disposition(@avatar.filename),
diff --git a/modules/avatars/app/controllers/avatars/my_avatar_controller.rb b/modules/avatars/app/controllers/avatars/my_avatar_controller.rb
index 5acbbdeb17a..9054b3c03a7 100644
--- a/modules/avatars/app/controllers/avatars/my_avatar_controller.rb
+++ b/modules/avatars/app/controllers/avatars/my_avatar_controller.rb
@@ -3,6 +3,8 @@ module ::Avatars
before_action :require_login
before_action :set_user
+ no_authorization_required! only: %i[show update destroy]
+
layout "my"
menu_item :avatar
diff --git a/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb b/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb
index 00c6bdcca40..0e3ac8abe60 100644
--- a/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb
+++ b/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb
@@ -39,6 +39,7 @@ module Bim
before_action :authorize, except: %i[direct_upload_finished set_direct_upload_file_name]
before_action :require_login, only: [:set_direct_upload_file_name]
skip_before_action :verify_authenticity_token, only: [:set_direct_upload_file_name] # AJAX request in page, so skip authenticity token
+ no_authorization_required! only: %i[set_direct_upload_file_name direct_upload_finished]
menu_item :ifc_models
diff --git a/modules/boards/app/controllers/boards/boards_controller.rb b/modules/boards/app/controllers/boards/boards_controller.rb
index 4d60fabb108..07e9f85d6b8 100644
--- a/modules/boards/app/controllers/boards/boards_controller.rb
+++ b/modules/boards/app/controllers/boards/boards_controller.rb
@@ -2,10 +2,7 @@ module ::Boards
class BoardsController < BaseController
include Layout
- before_action :find_optional_project
-
- before_action :authorize_global, if: -> { @project.nil? }
- before_action :authorize, if: -> { @project.present? }
+ before_action :authorize_in_optional_project
# The boards permission alone does not suffice
# to view work packages
diff --git a/modules/budgets/app/controllers/budgets_controller.rb b/modules/budgets/app/controllers/budgets_controller.rb
index 852a1d5758a..a6edf12954f 100644
--- a/modules/budgets/app/controllers/budgets_controller.rb
+++ b/modules/budgets/app/controllers/budgets_controller.rb
@@ -32,16 +32,17 @@ class BudgetsController < ApplicationController
before_action :find_budget, only: %i[show edit update copy destroy_info]
before_action :find_budgets, only: :destroy
before_action :check_and_update_belonging_work_packages, only: :destroy
- before_action :find_project, only: %i[new create update_material_budget_item update_labor_budget_item]
+ before_action :find_project_by_project_id, only: %i[new create update_material_budget_item update_labor_budget_item]
before_action :find_optional_project, only: :index
before_action :authorize_global, only: :index
before_action :authorize, except: [
- # unrestricted actions
:index,
+ # unrestricted actions
:update_material_budget_item,
:update_labor_budget_item
]
+ no_authorization_required! only: %i[update_material_budget_item update_labor_budget_item]
helper :sort
include SortHelper
diff --git a/modules/calendar/app/controllers/calendar/calendars_controller.rb b/modules/calendar/app/controllers/calendar/calendars_controller.rb
index c85bd8311c6..2145a5b76e8 100644
--- a/modules/calendar/app/controllers/calendar/calendars_controller.rb
+++ b/modules/calendar/app/controllers/calendar/calendars_controller.rb
@@ -28,7 +28,7 @@
module ::Calendar
class CalendarsController < ApplicationController
- before_action :find_optional_project
+ before_action :authorize_in_optional_project
before_action :build_calendar_view, only: %i[new]
before_action :authorize, except: %i[index new create]
before_action :authorize_global, only: %i[index new create]
diff --git a/modules/calendar/app/controllers/calendar/ical_controller.rb b/modules/calendar/app/controllers/calendar/ical_controller.rb
index f3284d7c4f5..ad2deaffad1 100644
--- a/modules/calendar/app/controllers/calendar/ical_controller.rb
+++ b/modules/calendar/app/controllers/calendar/ical_controller.rb
@@ -30,6 +30,7 @@ module ::Calendar
class ICalController < ApplicationController
# Authentication and authorization is handled within the service.
skip_before_action :check_if_login_required
+ no_authorization_required! only: :show
def show
begin
diff --git a/modules/costs/app/controllers/hourly_rates_controller.rb b/modules/costs/app/controllers/hourly_rates_controller.rb
index f97c18a8f02..b47f0cf22e6 100644
--- a/modules/costs/app/controllers/hourly_rates_controller.rb
+++ b/modules/costs/app/controllers/hourly_rates_controller.rb
@@ -38,8 +38,9 @@ class HourlyRatesController < ApplicationController
before_action :find_optional_project, only: %i[show edit update]
before_action :find_project, only: [:set_rate]
- # #show, #edit have their own authorization
+ # #show, #edit and #update have their own authorization
before_action :authorize, except: %i[show edit update]
+ no_authorization_required! only: %i[show edit update]
# TODO: this should be an index
def show
diff --git a/modules/gantt/app/controllers/gantt/gantt_controller.rb b/modules/gantt/app/controllers/gantt/gantt_controller.rb
index 62424595cb7..69289d26747 100644
--- a/modules/gantt/app/controllers/gantt/gantt_controller.rb
+++ b/modules/gantt/app/controllers/gantt/gantt_controller.rb
@@ -6,7 +6,7 @@ module ::Gantt
accept_key_auth :index
- before_action :find_optional_project, :protect_from_unauthorized_export, only: :index
+ before_action :authorize_in_optional_project, :protect_from_unauthorized_export, only: :index
before_action :load_and_validate_query, only: :index, unless: -> { request.format.html? }
diff --git a/modules/gantt/app/controllers/gantt/menus_controller.rb b/modules/gantt/app/controllers/gantt/menus_controller.rb
index 094e0148151..3e6cae9bdd8 100644
--- a/modules/gantt/app/controllers/gantt/menus_controller.rb
+++ b/modules/gantt/app/controllers/gantt/menus_controller.rb
@@ -27,7 +27,7 @@
# ++
module Gantt
class MenusController < ApplicationController
- before_action :find_optional_project
+ before_action :authorize_in_optional_project
def show
@sidebar_menu_items = menu_items
diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rb
index 41588cf11dd..07b9a2dbc7a 100644
--- a/modules/meeting/app/controllers/meetings_controller.rb
+++ b/modules/meeting/app/controllers/meetings_controller.rb
@@ -28,7 +28,7 @@
class MeetingsController < ApplicationController
around_action :set_time_zone
- before_action :find_optional_project, only: %i[index new show create history]
+ before_action :authorize_in_optional_project, only: %i[index new show create history]
before_action :verify_activities_module_activated, only: %i[history]
before_action :determine_date_range, only: %i[history]
before_action :determine_author, only: %i[history]
diff --git a/modules/recaptcha/app/controllers/recaptcha/request_controller.rb b/modules/recaptcha/app/controllers/recaptcha/request_controller.rb
index 2d48aa38032..63f81b212f1 100644
--- a/modules/recaptcha/app/controllers/recaptcha/request_controller.rb
+++ b/modules/recaptcha/app/controllers/recaptcha/request_controller.rb
@@ -7,6 +7,7 @@ module ::Recaptcha
# User is not yet logged in, so skip login required check
skip_before_action :check_if_login_required
+ no_authorization_required! only: %i[perform verify]
# Skip if recaptcha was disabled
before_action :skip_if_disabled
diff --git a/modules/reporting/app/controllers/cost_reports_controller.rb b/modules/reporting/app/controllers/cost_reports_controller.rb
index 8014ac1b6e5..d333cf6430f 100644
--- a/modules/reporting/app/controllers/cost_reports_controller.rb
+++ b/modules/reporting/app/controllers/cost_reports_controller.rb
@@ -40,7 +40,7 @@ class CostReportsController < ApplicationController
before_action :check_cache
before_action :load_all
- before_action :find_optional_project
+ before_action :authorize_in_optional_project
before_action :find_optional_user
include Layout
diff --git a/modules/storages/app/controllers/storages/project_storages_controller.rb b/modules/storages/app/controllers/storages/project_storages_controller.rb
index 8a63558450d..530e79b8f18 100644
--- a/modules/storages/app/controllers/storages/project_storages_controller.rb
+++ b/modules/storages/app/controllers/storages/project_storages_controller.rb
@@ -36,6 +36,7 @@ class Storages::ProjectStoragesController < ApplicationController
before_action :find_model_object
before_action :find_project_by_project_id
before_action :render_403, unless: -> { User.current.allowed_in_project?(:view_file_links, @project) }
+ no_authorization_required! only: %i[open]
# rubocop:disable Metrics/AbcSize
def open
diff --git a/modules/team_planner/app/controllers/team_planner/team_planner_controller.rb b/modules/team_planner/app/controllers/team_planner/team_planner_controller.rb
index aecacbec217..c720fd2ba2a 100644
--- a/modules/team_planner/app/controllers/team_planner/team_planner_controller.rb
+++ b/modules/team_planner/app/controllers/team_planner/team_planner_controller.rb
@@ -2,10 +2,8 @@ module ::TeamPlanner
class TeamPlannerController < BaseController
include EnterpriseTrialHelper
include Layout
- before_action :find_optional_project
+ before_action :authorize_in_optional_project
before_action :build_plan_view, only: %i[new]
- before_action :authorize, except: %i[overview new create upsale]
- before_action :authorize_global, only: %i[overview new create]
before_action :require_ee_token, except: %i[upsale]
before_action :find_plan_view, only: %i[destroy]
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb
index a16a2a07060..fdd4dc400c7 100644
--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb
+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb
@@ -11,6 +11,7 @@ module ::TwoFactorAuthentication
# User is not yet logged in, so skip login required check
skip_before_action :check_if_login_required
+ no_authorization_required!
# Avoid catch-all from core resulting in methods
before_action :only_post, only: :confirm_otp
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller.rb
index 384d95fec42..0a5f2363cae 100644
--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller.rb
+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller.rb
@@ -6,6 +6,12 @@ module ::TwoFactorAuthentication
# Skip default login
skip_before_action :check_if_login_required
+ no_authorization_required! only: %i[register
+ new
+ confirm
+ web_authn
+ make_default
+ destroy]
before_action :find_device, only: [:confirm]
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/backup_codes_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/backup_codes_controller.rb
index 9ed10ef1d1e..a6eb12a0f84 100644
--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/backup_codes_controller.rb
+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/backup_codes_controller.rb
@@ -3,6 +3,7 @@ module ::TwoFactorAuthentication
class BackupCodesController < ::ApplicationController
# Ensure user is logged in
before_action :require_login
+ no_authorization_required! only: %i[show create]
# Password confirmation helpers and actions
include PasswordConfirmation
@@ -23,6 +24,8 @@ module ::TwoFactorAuthentication
render
end
+ private
+
def check_regenerate_done
@backup_codes = flash[:_backup_codes]
flash.delete :_backup_codes
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/remember_cookie_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/remember_cookie_controller.rb
index 3f9d0d52055..5be5a66ee3a 100644
--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/remember_cookie_controller.rb
+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/remember_cookie_controller.rb
@@ -6,6 +6,7 @@ module ::TwoFactorAuthentication
# Ensure user is logged in
before_action :require_login
+ no_authorization_required!
layout "my"
menu_item :two_factor_authentication
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb
index d8d2844cbf0..59f69f24c15 100644
--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb
+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb
@@ -3,8 +3,10 @@ module ::TwoFactorAuthentication
class TwoFactorDevicesController < ::TwoFactorAuthentication::BaseController
# Ensure user is logged in
before_action :require_login
-
before_action :set_user_variables
+ # Authorization is not handled explictly but as the user on which changes can be done is only the current user
+ # (and that user needs to be logged in), no action harmful to other users can be done.
+ no_authorization_required!
before_action :find_device, except: %i[new index register webauthn_challenge]
diff --git a/modules/webhooks/app/controllers/webhooks/incoming/hooks_controller.rb b/modules/webhooks/app/controllers/webhooks/incoming/hooks_controller.rb
index 208399b7d3f..f1ef5786a89 100644
--- a/modules/webhooks/app/controllers/webhooks/incoming/hooks_controller.rb
+++ b/modules/webhooks/app/controllers/webhooks/incoming/hooks_controller.rb
@@ -35,6 +35,9 @@ module Webhooks
# Disable CSRF detection since we openly welcome POSTs here!
skip_before_action :verify_authenticity_token
+ # Authorization cannot be applied since authentication is skipped.
+ # It is then to be ensured when handling the hook.
+ no_authorization_required! only: [:handle_hook]
# Wrap the JSON body as 'payload' param
# making it available as params[:payload]
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index 1445e4aa56d..0d39fe54a3f 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -33,6 +33,8 @@ RSpec.describe ApplicationController do
# Fake controller to test calling an action
controller do
+ no_authorization_required!
+
def index
# just do anything that doesn't require an extra template
redirect_to root_path
@@ -152,6 +154,8 @@ RSpec.describe ApplicationController do
controller do
include OpenProjectErrorHelper
+ no_authorization_required!
+
def index
op_handle_error "fail"