hryvinskyi / magento2-invisible-captcha-bot-verification
Invisible Captcha route protection lets only verified crawlers skip its challenge and reads the client address past trusted proxies, through hryvinskyi/magento2-bot-verification
Package info
github.com/hryvinskyi/magento2-invisible-captcha-bot-verification
Type:magento2-module
pkg:composer/hryvinskyi/magento2-invisible-captcha-bot-verification
Requires
- php: ~8.1.0||~8.2.0||~8.3.0||~8.4.0||~8.5.0
- hryvinskyi/magento2-bot-verification: ^1.0
- hryvinskyi/magento2-invisible-captcha: ^3.5
- magento/framework: *
- magento/module-config: *
- psr/log: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-26 20:57:32 UTC
README
Connects Hryvinskyi_InvisibleCaptcha with Hryvinskyi_BotVerification, so a request that claims a crawler a bot
verification provider module declares (for example Googlebot or bingbot, while the Google or Bing provider is
installed) loses its route-protection exemption when bot verification proves the claim false: the request comes from
a public address outside the crawler owner's published addresses. Excluded User Agents still decides every other
request, as without this module. Neither module depends on the other; this one depends on both, and nothing depends
on it.
What it changes
Route protection lets a request skip its challenge when the User-Agent contains one of the Excluded User Agents
(Googlebot, bingbot, …) or the client IP is on Excluded IPs. Out of the box it takes both at the client's word:
anyone can write Googlebot into a User-Agent, and the client IP is read from CF-Connecting-IP, X-Real-IP or the
left-most X-Forwarded-For entry, which a client reaching the shop directly writes itself.
With this module enabled, two Invisible Captcha contracts are filled from bot verification:
| Invisible Captcha contract | Answered by | Behaviour |
|---|---|---|
Api\CrawlerExemptionInterface |
Model\VerifiedCrawlerExemption, decorating the User-Agent exemption |
see below |
Api\Http\ClientIpResolverInterface |
Model\ResolvedClientIp, decorating the forwarding-header resolver |
the address bot verification's trusted-proxy walk resolves |
Api\Tester\CrawlerExemptionSimulatorInterface |
Model\Tester\VerifiedCrawlerExemptionSimulator |
the rule tester's verdict, see Rule tester |
Crawler exemption
Bot verification judges the request (RequestVerifierInterface::verify()):
- The claim is an impostor (a public address outside every up-to-date list the claimed crawler's owner publishes): the request is never exempt, whatever Excluded User Agents says.
- The claim is genuine: Excluded User Agents decides. Genuine is not enough: a genuine crawler no excluded substring names (with the Google provider: Storebot-Google, GoogleOther, AdsBot-Google, …) is challenged like any other visitor on a protected page.
- The claim cannot be verified (a list not fetched yet, too old or unreadable, an IPv6 bingbot whose owner publishes no IPv6 list, an address that cannot be read): Excluded User Agents decides, as without this module. Missing data accuses nobody, so Googlebot is not challenged just because the lists have not been fetched since a deploy, or because the scheduled refresh failed for longer than the lists' maximum age.
- The User-Agent claims no crawler bot verification knows (a monitoring agent, an end-to-end suite's own token, a crawler no provider declares, such as Applebot, YandexBot or DuckDuckBot): Excluded User Agents decides, exactly as without this module.
- Bot verification throws (a broken crawler declaration, a service that cannot be built): the failure is logged and Excluded User Agents decides, so the challenge keeps working while bot verification is broken.
| Verdict on the claim | Substring matches | Substring does not match |
|---|---|---|
| impostor | challenged | challenged |
| genuine, unverifiable | exempt | challenged |
| no crawler declared | exempt | challenged |
| bot verification throws (logged) | exempt | challenged |
Excluded User Agents therefore still decides which crawlers skip the challenge: remove Googlebot from it and
Googlebot is challenged, genuine or not.
Client IP
The Excluded IPs list, the client_ip rule field, the country rule field's lookup, the remoteip sent with the
token verification and the debug log all see the address the trusted walk reaches: from REMOTE_ADDR leftwards
through X-Forwarded-For, past the shop's own proxies (bot verification's Trusted proxies) and at most one content
delivery network edge server. Consequences:
- Where the walk cannot decide — a proxy list (Cloudflare's) not fetched yet or too old to tell an edge server from
a client, or a chain made only of trusted proxies — and when bot verification fails (logged), the address is the
one route protection reads without this module:
CF-Connecting-IP,X-Real-IP, the left-mostX-Forwarded-Forentry, then the connecting address. The address is therefore never worse than without this module. - The address reached is used as it is; nothing checks whether it is private or loopback. With the default Trusted proxies, loopback and private ranges are the shop's own proxies and are passed, so an excluded private IP (an office LAN address, a monitoring host inside the network) does not match unless Trusted proxies is narrowed so that it no longer covers that address. Otherwise exclude such traffic by User-Agent or another rule.
- The one entry after an edge server is taken as it is, private ranges included. Where the origin can be reached around the content delivery network (no client-certificate check on the origin), code running inside that network can connect straight to the origin and write that entry, so it can match an excluded IP.
CF-Connecting-IPandX-Real-IPare read only in that fallback.- Bot verification reads only the current request's forwarding chain. The admin rule tester simulates a request of its own, so it takes the simulated client IP as given.
Rule tester
The Test Rules panel judges the simulated User-Agent and client IP the way the live gate would
(Model\Tester\VerifiedCrawlerExemptionSimulator fills Api\Tester\CrawlerExemptionSimulatorInterface): an
impostor is reported as challenged even when Excluded User Agents matches, and whenever the User-Agent claims a
crawler bot verification knows, a note under the result says what bot verification found (genuine, impostor, or
cannot be checked yet) and that Excluded User Agents decides otherwise.
Admin wording
The module replaces the comments of the Excluded IPs and Excluded User Agents fields (Stores > Configuration >
Hryvinskyi Extensions > Invisible Captcha & Bot Protection > Route Protection (site-wide gate)) with what holds while it is enabled, translated in i18n/
(en_US, da_DK, de_DE).
Installation
composer require hryvinskyi/magento2-invisible-captcha-bot-verification bin/magento module:enable Hryvinskyi_InvisibleCaptchaBotVerification bin/magento setup:upgrade bin/magento setup:di:compile
Install at least one bot verification provider module (Google, Bing, Cloudflare) for crawler claims and edge-server
ranges to be known. Bot verification fetches its address lists the first time setup:upgrade installs it, and on its
schedule after that (bin/magento bot-verification:refresh fetches them by hand). Until a list has been fetched, the
claims it would judge are unverifiable and Excluded User Agents decides them, as without this module.
Tests
- Unit:
Test/Unit/Model— every verdict with and without a matching substring, the fallbacks of the ports when bot verification cannot decide or fails, the logging of a failure, which request the walk reads, and the rule tester's notes. - Integration:
Test/Integration/Model/BotVerificationWiringTest.php— the container fills Invisible Captcha's ports with this module, the client IP over real forwarding chains, and the exemption over stored address lists, with the substrings each case relies on configured.
License
MIT