|
1 | 1 | # rubocop:disable Layout/LineLength |
2 | | -Rails.application.config.to_prepare do |
| 2 | +BotChallengePage.configure do |config| |
3 | 3 | # If disabled, no challenges will be issued |
4 | | - BotChallengePage::BotChallengePageController.bot_challenge_config.enabled = Settings.turnstile.enabled |
| 4 | + config.enabled = Settings.turnstile.enabled |
5 | 5 |
|
6 | 6 | # Get from CloudFlare Turnstile: https://www.cloudflare.com/application-services/products/turnstile/ |
7 | 7 | # Some testing keys are also available: https://developers.cloudflare.com/turnstile/troubleshooting/testing/ |
8 | 8 | # |
9 | 9 | # This set of keys will always pass the challenge; the link above includes |
10 | 10 | # sets that will always challenge or always fail, which is useful for local testing |
11 | | - BotChallengePage::BotChallengePageController.bot_challenge_config.cf_turnstile_sitekey = Settings.turnstile.site_key |
12 | | - BotChallengePage::BotChallengePageController.bot_challenge_config.cf_turnstile_secret_key = Settings.turnstile.secret_key |
| 11 | + config.cf_turnstile_sitekey = Settings.turnstile.site_key |
| 12 | + config.cf_turnstile_secret_key = Settings.turnstile.secret_key |
13 | 13 |
|
14 | 14 | # Do the challenge "in place" on the page the user was on |
15 | | - BotChallengePage::BotChallengePageController.bot_challenge_config.redirect_for_challenge = false |
| 15 | + config.redirect_for_challenge = false |
16 | 16 |
|
17 | 17 | # How long will a challenge success exempt a session from further challenges? |
18 | | - # BotChallengePage::BotChallengePageController.bot_challenge_config.session_passed_good_for = 36.hours |
| 18 | + # config.session_passed_good_for = 36.hours |
19 | 19 |
|
20 | 20 | # Exempt async JS facet requests from the challenge. Someone really determined could fake |
21 | 21 | # this header, but until we see that behavior, we'll allow it so the facet UI works. |
22 | 22 | # We also have an exception for index json so that the mini-bento frontend fetch in Searchworks doesn't get blocked. |
23 | 23 | # Also exempt any IPs contained in the CIDR blocks in Settings.turnstile.safelist. |
24 | | - BotChallengePage::BotChallengePageController.bot_challenge_config.allow_exempt = lambda do |controller, _config| |
25 | | - (controller.is_a?(CatalogController) && controller.params[:action].in?(%w[facet index]) && controller.request.format.json? && controller.request.headers['sec-fetch-dest'] == 'empty') || |
26 | | - Settings.turnstile.safelist.map { |cidr| IPAddr.new(cidr) }.any? { |range| controller.request.remote_ip.in?(range) } |
| 24 | + config.skip_when = lambda do |_config| |
| 25 | + (is_a?(CatalogController) && params[:action].in?(%w[facet index]) && request.format.json? && request.headers['sec-fetch-dest'] == 'empty') || |
| 26 | + Settings.turnstile.safelist.map { |cidr| IPAddr.new(cidr) }.any? { |range| request.remote_ip.in?(range) } |
27 | 27 | end |
28 | 28 |
|
29 | 29 | # More configuration is available; see: |
|
0 commit comments