Repository navigation
fix: BotDetector no longer trusts forwarded headers it was never told to trust - #111
Merged
Merged
Conversation
… to trust When signals arrived without ip_address, BotDetector::analyze() fell back to a private resolver that took CF-Connecting-IP or the leftmost X-Forwarded-For from any client. That address is the one a claimed good bot is verified against. It now uses SignalCollector::getIP(), the trusted-proxy-aware resolver the rest of the plugin uses. A valid supplied ip_address is still kept. WebDecoy_Detector also built its BotDetector without the trusted proxies, so on a site behind Cloudflare it verified good bots against the edge address. It now passes the configured proxies. Closes #85. Refs WebDecoy/app#875.
Merged
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #85. Refs WebDecoy/app#875.
What was wrong
BotDetector::analyze()falls back to its own resolver when the signals it gets have noip_address. That privategetClientIP()tookCF-Connecting-IP, then the leftmostX-Forwarded-For, thenX-Real-IP, from any client, with no trusted-proxy check. The resolved address is the one a claimed good bot is reverse-DNS verified against.While checking that both entry points resolve the same request identically, I found a second gap.
WebDecoy_Detector(used by WooCommerce checkout andwebdecoy.php:1207; the plugin's ownget_detector()already passed them) built itsBotDetectorwithouttrusted_proxies. On a site behind Cloudflare it collected the edge address asip_address, so a real Googlebot was checked against a Cloudflare IP.Change
analyze()keeps a suppliedip_addressonly when it is a valid IP. Otherwise it calls$this->signalCollector->getIP(). The second resolver is deleted. There is no cURL and no new dependency.WebDecoy_Detectorpasseswebdecoy_plugin_trusted_proxies(), the same listget_client_ip()and the blocker use.Compatibility: a site with no trusted proxies configured now verifies bots against
REMOTE_ADDRinstead of a client-supplied header. That is the intended secure default and matchesSignalCollector. A site behind an unconfigured proxy already gets the existing misconfiguration notice.Tests
tests/BotDetectorIpTest.phpobserves the IP that analyze() verifies against, through aGoodBotListspy, so no DNS lookups run. It covers:ip_addressbeing kept, and an invalid one being resolvedAll 7 of the new tests fail on
main. With this change the full suite passes, 203 of 203. PHPStan reports no errors, and phpcs shows no new warnings on the touched files.