Skip to content
Snippets Groups Projects

Add DPoP checks in GraphQL and API requests

Merged Ameya Darshan requested to merge ameya-dpop-2 into master
Compare and
4 files
+ 99
1
Compare changes
  • Side-by-side
  • Inline
Files
4
# frozen_string_literal: true
class GraphqlController < ApplicationController
include Gitlab::Auth::AuthFinders
extend ::Gitlab::Utils::Override
# Unauthenticated users have access to the API for public data
@@ -85,6 +86,8 @@ class GraphqlController < ApplicationController
urgency :low, [:execute]
def execute
check_dpop!
result = if multiplex?
execute_multiplex
else
@@ -106,6 +109,12 @@ def execute
end
end
rescue_from Gitlab::Auth::DpopValidationError do |exception|
log_exception(exception)
render_error(exception.message, status: :unauthorized)
end
# ApplicationController has similar rescues but we declare these again here because the
# `rescue_from StandardError` above would prevent these from bubbling up to ApplicationController.
# These also return errors in a JSON format similar to GraphQL errors.
@@ -148,6 +157,16 @@ def feature_category
private
def check_dpop!
# For unauthenticated requests we don't need DPoP checks
return unless current_user&.dpop_enabled
# For authenticated requests we check if the user has DPoP enabled
::Auth::DpopAuthenticationService.new(current_user: current_user,
personal_access_token_plaintext: get_personal_access_token,
request: current_request).execute
end
def permitted_params
@permitted_params ||= multiplex? ? permitted_multiplex_params : permitted_standalone_query_params
end
Loading