-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3841 from jlledom/THREESCALE-765-brute-force-admi…
…n-login THREESCALE-765: Brute force protection for the admin login screen
- Loading branch information
Showing
37 changed files
with
392 additions
and
97 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
app/controllers/provider/admin/bot_protections_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class Provider::Admin::BotProtectionsController < Provider::Admin::BaseController | ||
|
||
activate_menu! :account, :integrate, :bot_protection | ||
|
||
before_action :find_settings | ||
|
||
def edit; end | ||
|
||
def update | ||
if @settings.update(params[:settings]) | ||
flash[:notice] = 'Bot protection settings updated.' | ||
redirect_to edit_provider_admin_bot_protection_url | ||
else | ||
flash[:error] = 'There were problems saving the settings.' | ||
render :action => 'edit' | ||
end | ||
end | ||
|
||
private | ||
|
||
def find_settings | ||
@settings = current_account.settings | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,9 @@ | |
.pf-c-alert.invisible { | ||
visibility: hidden; | ||
} | ||
|
||
.login-layout { | ||
.grecaptcha-badge { | ||
visibility: hidden; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
declare global { | ||
interface Window { | ||
grecaptcha: ReCaptchaInstance; | ||
} | ||
} | ||
|
||
export interface ReCaptchaInstance { | ||
ready: (cb: () => void) => void; | ||
execute: (sitekey: string, options: { action: string }) => Promise<string>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useState } from 'react' | ||
|
||
import { useScript } from 'utilities/useScript' | ||
|
||
import type { FunctionComponent } from 'react' | ||
|
||
interface Props { | ||
siteKey: string; | ||
action: string; | ||
} | ||
|
||
const ReCaptchaV3: FunctionComponent<Props> = ({ siteKey, action }) => { | ||
const inputId = `g-recaptcha-response-data-${action}`.replace(/\//g, '-') | ||
const inputName = `g-recaptcha-response-data[${action}]` | ||
const [token, setToken] = useState('') | ||
|
||
useScript(`https://www.google.com/recaptcha/api.js?render=${siteKey}`, () => { | ||
const { grecaptcha } = window | ||
grecaptcha.ready(() => { | ||
grecaptcha.execute(siteKey, { action: action }) | ||
.then((t: string) => { | ||
setToken(t) | ||
}) | ||
.catch((error: string) => { console.error(error) }) | ||
}) | ||
}) | ||
|
||
return ( | ||
<div> | ||
<small> | ||
This site is protected by reCAPTCHA and the Google <a href="https://policies.google.com/privacy">Privacy Policy</a> and <a href="https://policies.google.com/terms">Terms of Service</a> apply. | ||
</small> | ||
<input className="g-recaptcha g-recaptcha-response" data-sitekey={siteKey} id={inputId} name={inputName} type="hidden" value={token} /> | ||
</div> | ||
) | ||
} | ||
|
||
export type { Props } | ||
export { ReCaptchaV3 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useEffect } from 'react' | ||
|
||
const useScript = (url: string, cb: (ev: Event) => void): void => { | ||
useEffect(() => { | ||
const script = document.createElement('script') | ||
|
||
script.src = url | ||
script.async = true | ||
script.addEventListener('load', cb) | ||
|
||
document.body.appendChild(script) | ||
|
||
return () => { | ||
document.body.removeChild(script) | ||
} | ||
}, []) | ||
} | ||
|
||
export { useScript } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
= semantic_form_for settings, url: url, html: {:id => 'bot-protection-settings' } do |form| | ||
= form.inputs selector_label do | ||
= form.input field, | ||
label: false, | ||
hint: t("sites.spam_protections.edit.captcha_hint_#{Recaptcha.captcha_configured?.to_s}"), | ||
as: :radio, | ||
collection: ThreeScale::BotProtection::LEVELS, | ||
input_html: { disabled: !Recaptcha.captcha_configured? } | ||
|
||
= form.actions do | ||
= form.commit_button 'Update Settings' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- content_for :title, 'Bot Protection' | ||
- content_for :page_header_title, 'Bot Protection' | ||
- content_for :page_header_body, t('.description') | ||
|
||
= render partial: 'form', locals: { url: provider_admin_bot_protection_path, settings: @settings, field: :admin_bot_protection_level, selector_label: t('.selector_label') } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,5 @@ | ||
<% content_for(:title) do %> | ||
Bot Protection | ||
<% end %> | ||
|
||
<% content_for :title, 'Bot Protection' %> | ||
<% content_for :page_header_title, 'Bot Protection' %> | ||
<% content_for :page_header_body, t('.description') %> | ||
|
||
<%= semantic_form_for @settings, :url => admin_site_spam_protection_path, :html => {:id => 'spam-protection-settings' } do |form| %> | ||
<%= form.inputs 'Protection against bots' do %> | ||
<%= form.input :spam_protection_level, | ||
:label => false, | ||
hint: t(".captcha_hint_#{Recaptcha.captcha_configured?.to_s}"), | ||
:as => :radio, | ||
:collection => ThreeScale::BotProtection::LEVELS, | ||
input_html: { disabled: !Recaptcha.captcha_configured? } %> | ||
<% end %> | ||
|
||
<%= form.actions do %> | ||
<%= form.commit_button 'Update Settings' %> | ||
<% end %> | ||
<% end %> | ||
<%= render partial: 'provider/admin/bot_protections/form', locals: { url: admin_site_spam_protection_path, settings: @settings, field: :spam_protection_level, selector_label: t('.selector_label') } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
db/migrate/20240715075900_add_admin_bot_protection_to_settings.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class AddAdminBotProtectionToSettings < ActiveRecord::Migration[6.1] | ||
def up | ||
add_column :settings, :admin_bot_protection_level, :string | ||
change_column_default :settings, :admin_bot_protection_level, "none" | ||
end | ||
|
||
def down | ||
remove_column :settings, :admin_bot_protection_level | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.