2019-08-14 08:05:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module InvisibleCaptcha
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
invisible_captcha only: :create, on_spam: :on_honeypot_spam_callback, on_timestamp_spam: :on_timestamp_spam_callback
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_honeypot_spam_callback
|
2020-02-03 16:09:00 -05:00
|
|
|
return unless Feature.enabled?(:invisible_captcha)
|
2019-08-14 08:05:24 -04:00
|
|
|
|
|
|
|
invisible_captcha_honeypot_counter.increment
|
|
|
|
log_request('Invisible_Captcha_Honeypot_Request')
|
|
|
|
|
|
|
|
head(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_timestamp_spam_callback
|
2020-02-03 16:09:00 -05:00
|
|
|
return unless Feature.enabled?(:invisible_captcha)
|
2019-08-14 08:05:24 -04:00
|
|
|
|
|
|
|
invisible_captcha_timestamp_counter.increment
|
|
|
|
log_request('Invisible_Captcha_Timestamp_Request')
|
|
|
|
|
|
|
|
redirect_to new_user_session_path, alert: InvisibleCaptcha.timestamp_error_message
|
|
|
|
end
|
|
|
|
|
|
|
|
def invisible_captcha_honeypot_counter
|
|
|
|
@invisible_captcha_honeypot_counter ||=
|
|
|
|
Gitlab::Metrics.counter(:bot_blocked_by_invisible_captcha_honeypot,
|
|
|
|
'Counter of blocked sign up attempts with filled honeypot')
|
|
|
|
end
|
|
|
|
|
|
|
|
def invisible_captcha_timestamp_counter
|
|
|
|
@invisible_captcha_timestamp_counter ||=
|
|
|
|
Gitlab::Metrics.counter(:bot_blocked_by_invisible_captcha_timestamp,
|
|
|
|
'Counter of blocked sign up attempts with invalid timestamp')
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_request(message)
|
|
|
|
request_information = {
|
|
|
|
message: message,
|
|
|
|
env: :invisible_captcha_signup_bot_detected,
|
2019-08-20 14:12:28 -04:00
|
|
|
remote_ip: request.ip,
|
2019-08-14 08:05:24 -04:00
|
|
|
request_method: request.request_method,
|
2019-08-20 14:12:28 -04:00
|
|
|
path: request.fullpath
|
2019-08-14 08:05:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Gitlab::AuthLogger.error(request_information)
|
|
|
|
end
|
|
|
|
end
|