Commit f7fa7c1f authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'arkose-labs-captcha-header-guard' into 'master'

Guard ArkoseLabs challenge behind a header check

See merge request gitlab-org/gitlab!83903
parents d0510240 ccd1bb75
...@@ -39,7 +39,7 @@ class SessionsController < Devise::SessionsController ...@@ -39,7 +39,7 @@ class SessionsController < Devise::SessionsController
after_action :log_failed_login, if: :action_new_and_failed_login? after_action :log_failed_login, if: :action_new_and_failed_login?
after_action :verify_known_sign_in, only: [:create] after_action :verify_known_sign_in, only: [:create]
helper_method :captcha_enabled?, :captcha_on_login_required? helper_method :captcha_enabled?, :captcha_on_login_required?, :arkose_labs_enabled?
# protect_from_forgery is already prepended in ApplicationController but # protect_from_forgery is already prepended in ApplicationController but
# authenticate_with_two_factor which signs in the user is prepended before # authenticate_with_two_factor which signs in the user is prepended before
...@@ -111,6 +111,10 @@ class SessionsController < Devise::SessionsController ...@@ -111,6 +111,10 @@ class SessionsController < Devise::SessionsController
Gitlab::Recaptcha.enabled_on_login? && unverified_anonymous_user? Gitlab::Recaptcha.enabled_on_login? && unverified_anonymous_user?
end end
def arkose_labs_enabled?
false
end
# From https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise#devisepasswordscontroller # From https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise#devisepasswordscontroller
def check_captcha def check_captcha
return unless user_params[:password].present? return unless user_params[:password].present?
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
- else - else
= link_to _('Forgot your password?'), new_password_path(:user) = link_to _('Forgot your password?'), new_password_path(:user)
%div %div
- if Feature.enabled?(:arkose_labs_login_challenge) - if arkose_labs_enabled?
= render_if_exists 'devise/sessions/arkose_labs' = render_if_exists 'devise/sessions/arkose_labs'
- elsif captcha_enabled? || captcha_on_login_required? - elsif captcha_enabled? || captcha_on_login_required?
= recaptcha_tags nonce: content_security_policy_nonce = recaptcha_tags nonce: content_security_policy_nonce
......
...@@ -24,7 +24,7 @@ module EE ...@@ -24,7 +24,7 @@ module EE
redirect_to oauth_geo_auth_url(host: current_node_uri.host, port: current_node_uri.port, state: state) redirect_to oauth_geo_auth_url(host: current_node_uri.host, port: current_node_uri.port, state: state)
else else
if ::Feature.enabled?(:arkose_labs_login_challenge) if ::Feature.enabled?(:arkose_labs_login_challenge)
@arkose_labs_public_key ||= ENV['ARKOSE_LABS_PUBLIC_KEY'] # rubocop:disable Gitlab/ModuleWithInstanceVariables @arkose_labs_public_key ||= Settings.arkose['public_key'] # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
super super
...@@ -79,6 +79,11 @@ module EE ...@@ -79,6 +79,11 @@ module EE
super super
end end
override :arkose_labs_enabled?
def arkose_labs_enabled?
::Feature.enabled?(:arkose_labs_login_challenge, default_enabled: :yaml) && request.headers[::SessionsController::CAPTCHA_HEADER]
end
override :check_captcha override :check_captcha
def check_captcha def check_captcha
if ::Feature.enabled?(:arkose_labs_login_challenge, default_enabled: :yaml) if ::Feature.enabled?(:arkose_labs_login_challenge, default_enabled: :yaml)
......
...@@ -16,9 +16,9 @@ RSpec.describe 'devise/sessions/new' do ...@@ -16,9 +16,9 @@ RSpec.describe 'devise/sessions/new' do
allow(Gitlab).to receive(:com?).and_return(true) allow(Gitlab).to receive(:com?).and_return(true)
end end
context 'when the :arkose_labs_login_challenge feature flag is enabled' do context 'when arkose_labs_enabled? is enabled' do
before do before do
stub_feature_flags(arkose_labs_login_challenge: true) stub_arkose_labs(enabled: true)
subject subject
end end
...@@ -32,9 +32,9 @@ RSpec.describe 'devise/sessions/new' do ...@@ -32,9 +32,9 @@ RSpec.describe 'devise/sessions/new' do
end end
end end
context 'when the :arkose_labs_login_challenge feature flag is disabled' do context 'when arkose_labs_enabled? is disabled' do
before do before do
stub_feature_flags(arkose_labs_login_challenge: false) stub_arkose_labs(enabled: false)
subject subject
end end
...@@ -55,4 +55,8 @@ RSpec.describe 'devise/sessions/new' do ...@@ -55,4 +55,8 @@ RSpec.describe 'devise/sessions/new' do
allow(view).to receive(:captcha_enabled?).and_return(false) allow(view).to receive(:captcha_enabled?).and_return(false)
allow(view).to receive(:captcha_on_login_required?).and_return(false) allow(view).to receive(:captcha_on_login_required?).and_return(false)
end end
def stub_arkose_labs(enabled:)
allow(view).to receive(:arkose_labs_enabled?).and_return(enabled)
end
end end
...@@ -12,6 +12,7 @@ RSpec.describe 'Sessions (JavaScript fixtures)' do ...@@ -12,6 +12,7 @@ RSpec.describe 'Sessions (JavaScript fixtures)' do
before do before do
set_devise_mapping(context: @request) set_devise_mapping(context: @request)
allow(controller).to receive(:arkose_labs_enabled?).and_return(true)
end end
it 'sessions/new.html' do it 'sessions/new.html' do
......
...@@ -9,6 +9,7 @@ RSpec.describe 'devise/sessions/new' do ...@@ -9,6 +9,7 @@ RSpec.describe 'devise/sessions/new' do
before do before do
stub_devise stub_devise
disable_captcha disable_captcha
allow(view).to receive(:arkose_labs_enabled?).and_return(false)
allow(Gitlab).to receive(:com?).and_return(true) allow(Gitlab).to receive(:com?).and_return(true)
end end
......
...@@ -11,6 +11,7 @@ RSpec.describe 'devise/shared/_signin_box' do ...@@ -11,6 +11,7 @@ RSpec.describe 'devise/shared/_signin_box' do
allow(view).to receive(:captcha_enabled?).and_return(false) allow(view).to receive(:captcha_enabled?).and_return(false)
allow(view).to receive(:captcha_on_login_required?).and_return(false) allow(view).to receive(:captcha_on_login_required?).and_return(false)
allow(view).to receive(:experiment_enabled?).and_return(false) allow(view).to receive(:experiment_enabled?).and_return(false)
allow(view).to receive(:arkose_labs_enabled?).and_return(false)
end end
it 'is shown when Crowd is enabled' do it 'is shown when Crowd is enabled' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment