diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:55:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:55:51 +0000 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /app/services/captcha | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) | |
download | gitlab-ce-e8d2c2579383897a1dd7f9debd359abe8ae8373d.tar.gz |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'app/services/captcha')
-rw-r--r-- | app/services/captcha/captcha_verification_service.rb | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/app/services/captcha/captcha_verification_service.rb b/app/services/captcha/captcha_verification_service.rb index 45a5a52367c..3ed8ea12f3a 100644 --- a/app/services/captcha/captcha_verification_service.rb +++ b/app/services/captcha/captcha_verification_service.rb @@ -7,20 +7,27 @@ module Captcha class CaptchaVerificationService include Recaptcha::Verify + # Currently the only value that is used out of the request by the reCAPTCHA library + # is 'remote_ip'. Therefore, we just create a struct to avoid passing the full request + # object through all the service layer objects, and instead just rely on passing only + # the required remote_ip value. This eliminates the need to couple the service layer + # to the HTTP request (for the purpose of this service, at least). + RequestStruct = Struct.new(:remote_ip) + + def initialize(spam_params:) + @spam_params = spam_params + end + ## # Performs verification of a captcha response. # - # 'captcha_response' parameter is the response from the user solving a client-side captcha. - # - # 'request' parameter is the request which submitted the captcha. - # # NOTE: Currently only supports reCAPTCHA, and is not yet used in all places of the app in which # captchas are verified, but these can be addressed in future MRs. See: # https://gitlab.com/gitlab-org/gitlab/-/issues/273480 - def execute(captcha_response: nil, request:) - return false unless captcha_response + def execute + return false unless spam_params.captcha_response - @request = request + @request = RequestStruct.new(spam_params.ip_address) Gitlab::Recaptcha.load_configurations! @@ -31,11 +38,13 @@ module Captcha # 2. We want control over the wording and i18n of the message # 3. We want a consistent interface and behavior when adding support for other captcha # libraries which may not support automatically adding errors to the model. - verify_recaptcha(response: captcha_response) + verify_recaptcha(response: spam_params.captcha_response) end private + attr_reader :spam_params + # The recaptcha library's Recaptcha::Verify#verify_recaptcha method requires that # 'request' be a readable attribute - it doesn't support passing it as an options argument. attr_reader :request |