Bugzilla – Attachment 182474 Details for
Bug 39906
Add bot challenge (in Apache layer)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39906: Add a simple quick Apache-level bot challenge
Bug-39906-Add-a-simple-quick-Apache-level-bot-chal.patch (text/plain), 5.97 KB, created by
David Cook
on 2025-05-15 06:40:58 UTC
(
hide
)
Description:
Bug 39906: Add a simple quick Apache-level bot challenge
Filename:
MIME Type:
Creator:
David Cook
Created:
2025-05-15 06:40:58 UTC
Size:
5.97 KB
patch
obsolete
>From ac5c1c92d3ffeb54cdc7b87fb0159635ee94219c Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Thu, 15 May 2025 06:39:34 +0000 >Subject: [PATCH] Bug 39906: Add a simple quick Apache-level bot challenge > >This patch adds a fast simple bot challenge via Apache. > >To test: >0. Apply the patch >1. sudo cp debian/templates/apache-shared-opac-antibot.conf /etc/koha/. >2. sudo cp debian/templates/apache-shared-opac-plack.conf /etc/koha/. >3. curl http://localhost:8080/cgi-bin/koha/opac-search.pl >4. Note an instant response with a very simple HTML response >5. Open an incognito browser and go to http://localhost:8080/cgi-bin/koha/opac-search.pl >6. Note a very brief loading animation before the OPAC search page appearing >7. Do a search >8. Note no more loading animation appears >9. Close the incognito browser >10. Open an incognito browser and go to http://localhost:8080/cgi-bin/koha/opac-main.pl >11. Do a search via the "Library catalog" search bar >12. Note no loading animation appears >--- > .../templates/apache-shared-opac-antibot.conf | 18 +++++++++++ > .../templates/apache-shared-opac-plack.conf | 2 ++ > .../lib/koha_fast_challenge/index.html | 11 +++++++ > .../lib/koha_fast_challenge/index.js | 29 +++++++++++++++++ > .../lib/koha_fast_challenge/style.css | 31 +++++++++++++++++++ > 5 files changed, 91 insertions(+) > create mode 100644 debian/templates/apache-shared-opac-antibot.conf > create mode 100644 koha-tmpl/opac-tmpl/lib/koha_fast_challenge/index.html > create mode 100644 koha-tmpl/opac-tmpl/lib/koha_fast_challenge/index.js > create mode 100644 koha-tmpl/opac-tmpl/lib/koha_fast_challenge/style.css > >diff --git a/debian/templates/apache-shared-opac-antibot.conf b/debian/templates/apache-shared-opac-antibot.conf >new file mode 100644 >index 0000000000..9a7502e406 >--- /dev/null >+++ b/debian/templates/apache-shared-opac-antibot.conf >@@ -0,0 +1,18 @@ >+RewriteEngine on >+ >+#NOTE: To override this setting of ANTIBOT_DO, in the parent VirtualHost add the following: SetEnvIf Request_URI ^ ANTIBOT_OVERRIDE=true >+#You can then provide your own conditions for setting the ANTIBOT_DO environmental variable >+RewriteCond %{ENV:ANTIBOT_OVERRIDE} ^$ >+RewriteCond expr "%{REQUEST_URI} =~ m#^/cgi-bin/koha/(opac-detail.pl|opac-export.pl|opac-suggestions.pl|opac-search.pl|opac-authoritiesdetail.pl|opac-ISBDdetail.pl|opac-MARCdetail.pl|opac-shelves.pl)$#" >+RewriteCond %{HTTP:Cookie} !(^|;\s*)CGISESSID= [NC] >+RewriteCond %{HTTP:Cookie} !(^|;\s*)KOHA_INIT= [NC] >+RewriteRule ^ - [E=ANTIBOT_DO:true] >+ >+#NOTE: The below is the core of the antibot action. >+ >+#Set the KOHA_INIT cookie to tag the requester and prevent redirect loops in browsers >+Header always set Set-Cookie "KOHA_INIT=1; Path=/; HttpOnly; SameSite=Lax" env=ANTIBOT_DO >+ >+#NOTE: Internal redirect to our challenge page >+RewriteCond %{ENV:ANTIBOT_DO} ^true$ >+RewriteRule ^ /opac-tmpl/lib/koha_fast_challenge/index.html [L,PT] >diff --git a/debian/templates/apache-shared-opac-plack.conf b/debian/templates/apache-shared-opac-plack.conf >index 5d15a76023..60f89620aa 100644 >--- a/debian/templates/apache-shared-opac-plack.conf >+++ b/debian/templates/apache-shared-opac-plack.conf >@@ -13,6 +13,8 @@ > > RequestHeader set X-FORWARDED-PROTO "https" env=HTTPS > >+ Include "/etc/koha/apache-shared-opac-antibot.conf" >+ > #Â Point the OPAC site to Plack > ProxyPass /cgi-bin/koha "unix:/var/run/koha/${instance}/plack.sock|http://localhost/opac" > ProxyPassReverse /cgi-bin/koha "unix:/var/run/koha/${instance}/plack.sock|http://localhost/opac" >diff --git a/koha-tmpl/opac-tmpl/lib/koha_fast_challenge/index.html b/koha-tmpl/opac-tmpl/lib/koha_fast_challenge/index.html >new file mode 100644 >index 0000000000..a5562170f4 >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/lib/koha_fast_challenge/index.html >@@ -0,0 +1,11 @@ >+<html> >+ <head> >+ <link href="/opac-tmpl/lib/koha_fast_challenge/style.css" rel="stylesheet"/> >+ <script src="/opac-tmpl/lib/koha_fast_challenge/index.js"></script> >+ </head> >+ <body> >+ <div class="loading-overlay"> >+ <div class="spinner"></div> >+ </div> >+ </body> >+</html> >diff --git a/koha-tmpl/opac-tmpl/lib/koha_fast_challenge/index.js b/koha-tmpl/opac-tmpl/lib/koha_fast_challenge/index.js >new file mode 100644 >index 0000000000..9b40aba141 >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/lib/koha_fast_challenge/index.js >@@ -0,0 +1,29 @@ >+document.addEventListener("DOMContentLoaded", event => { >+ const timeout_base = 0; >+ let timeout_incr = 250; >+ >+ if (navigator.webdriver){ >+ timeout_incr += 10000 >+ } >+ if (navigator.plugins.length === 0){ >+ timeout_incr += 5000; >+ } >+ if (navigator.mimeTypes.length === 0){ >+ timeout_incr += 5000; >+ } >+ if (!navigator.languages || navigator.languages.length === 0){ >+ timeout_incr += 5000; >+ } >+ const timestamp1 = performance.now(); >+ requestAnimationFrame(() => { >+ const delay = performance.now() - timestamp1; >+ if (delay < 20){ >+ timeout_incr += 1000; >+ } >+ }); >+ >+ let final_timeout = timeout_base + timeout_incr; >+ setTimeout(() => { >+ location.reload(); >+ }, final_timeout); >+}); >diff --git a/koha-tmpl/opac-tmpl/lib/koha_fast_challenge/style.css b/koha-tmpl/opac-tmpl/lib/koha_fast_challenge/style.css >new file mode 100644 >index 0000000000..0cb3ef926c >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/lib/koha_fast_challenge/style.css >@@ -0,0 +1,31 @@ >+.loading-overlay { >+ display: flex; >+ position: fixed; >+ top: 0; >+ left: 0; >+ width: 100%; >+ height: 100%; >+ background: rgba(0, 0, 0, 0.5); >+ align-items: center; >+ justify-content: center; >+ z-index: 9999; >+ pointer-events: auto; >+} >+ >+.spinner { >+ width: 50px; >+ height: 50px; >+ border: 5px solid rgba(255, 255, 255, 0.2); >+ border-top: 5px solid white; >+ border-radius: 50%; >+ animation: spin 1s linear infinite; >+} >+ >+@keyframes spin { >+ 0% { >+ transform: rotate(0deg); >+ } >+ 100% { >+ transform: rotate(360deg); >+ } >+} >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39906
:
182474
|
182506
|
182507
|
182906
|
183590
|
184784
|
184886
|
184887
|
184890