Repository navigation
Improved: forward Accept-Language and Sec-CH-UA* headers in proxied requests - #336
Conversation
Plausible's bot detection relies on these headers, which weren't passed on for requests sent through the proxy (or server-side events).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Change: Bug fix Merge Risk: ⚪ Minimal · up to
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Plausible's infrastructure uses
Accept-Languageand the User-Agent Client Hints (Sec-CH-UA*) headers to detect and block bots. Requests sent through the WordPress proxy only carried the User-Agent andX-Forwarded-For, so bots couldn't be detected there.Change
Proxy::get_forwarded_headers()collects the visitor'sAccept-Languageand everySec-CH-UA*header present (e.g.Sec-CH-UA,Sec-CH-UA-Mobile,Sec-CH-UA-Platform, and high-entropy hints likeSec-CH-UA-Full-Version-Listwhen the browser sends them). Values are sanitized like the User-Agent and empty headers are skipped.Proxy::send_event()merges them into the request to Plausible, so this also applies to server-side events (WooCommerce, EDD, Contact Form 7, Gravity Forms).Note: browsers only send the low-entropy hints (
Sec-CH-UA,-Mobile,-Platform) by default; high-entropy ones only arrive if the site requests them viaAccept-CH, which the plugin doesn't do (yet). I've asked whether that's needed.Tests
testGetForwardedHeaders(header name mapping, empty and unrelated headers skipped) andtestSendEventForwardsHeaders(headers end up in the outgoing request, viapre_http_request).AssetsTesterrors I get locally also occur on a cleandevelop.Summary by CodeRabbit