:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(wordpress): say a firewall blocked the request, not the user's role (#128900)
Tom Owers5c6afd0f285b
diff --git a/products/warehouse_sources/sources/wordpress/tests/test_wordpress.py b/products/warehouse_sources/sources/wordpress/tests/test_wordpress.pyindex 0fa4cfc48b3b..7a60f0659762 100644--- a/products/warehouse_sources/sources/wordpress/tests/test_wordpress.py+++ b/products/warehouse_sources/sources/wordpress/tests/test_wordpress.py@@ -148,14 +148,29 @@ class TestParseNextUrl:class TestValidateCredentials:@pytest.mark.parametrize(- "status_code, expected_valid, expected_msg_substr",+ "status_code, json_data, text, with_credentials, expected_valid, expected_msg_substr",[- (404, False, "REST API not found"),+ (404, [], "", False, False, "REST API not found"),+ (403, None, "<html>Access denied</html>", True, False, "firewall, security plugin or bot check"),+ (403, None, "<html>Access denied</html>", False, False, "firewall, security plugin or bot check"),+ (+ 403,+ {"code": "rest_forbidden", "message": "x"},+ "",+ False,+ False,+ "firewall, security plugin or bot check",+ ),+ (403, {"code": "rest_forbidden", "message": "x"}, "", True, False, "Check the user's role"),+ (202, None, "<html>Checking your browser</html>", False, False, "firewall, security plugin or bot check"),],)- def test_status_code_mapping(self, status_code, expected_valid, expected_msg_substr):- with scripted_network(always(_response(status_code=status_code, json_data=[]))):- valid, msg = validate_credentials("https://example.com", None, None)+ def test_status_code_mapping(+ self, status_code, json_data, text, with_credentials, expected_valid, expected_msg_substr+ ):+ username, password = ("admin", "abcd efgh") if with_credentials else (None, None)+ with scripted_network(always(_response(status_code=status_code, json_data=json_data, text=text))):+ valid, msg = validate_credentials("https://example.com", username, password)assert valid is expected_validif expected_msg_substr is None:assert msg is Nonediff --git a/products/warehouse_sources/sources/wordpress/wordpress.py b/products/warehouse_sources/sources/wordpress/wordpress.pyindex a4e52ceadb97..875ab0ecd54f 100644--- a/products/warehouse_sources/sources/wordpress/wordpress.py+++ b/products/warehouse_sources/sources/wordpress/wordpress.py@@ -31,6 +31,10 @@ API_PREFIX = "/wp-json/wp/v2"HOST_NOT_ALLOWED_ERROR = "WordPress site URL is not allowed"HTTP_NOT_ALLOWED_ERROR = "WordPress site URL must use HTTPS when credentials are provided"+BLOCKED_REQUEST_ERROR = (+ "A firewall, security plugin or bot check on your WordPress site blocked PostHog. "+ "Allow PostHog's IP addresses through it, then try again."+)# WordPress `after`/`modified_after` filter on the site-LOCAL post_date/post_modified columns, which# can be non-monotonic across a DST transition. We re-request a small overlap on each incremental run@@ -274,6 +278,22 @@ def validate_credentials(if response.status_code == 401:return False, "Invalid WordPress username or application password"+ # A WordPress REST error carries a JSON `code` and `message`. Anything else — a WAF, reverse+ # proxy, or load balancer answering with a bare status line like "Bad Request" — gives the user+ # nothing to act on, so replace it with an actionable message naming the status code rather+ # than leaking the raw body.+ try:+ body = response.json()+ except Exception:+ body = None+ is_wp_error = isinstance(body, dict) and bool(body.get("code"))+ wp_message = body.get("message") if isinstance(body, dict) else None++ # Any user, and an anonymous caller, can read published posts. So a 403 without a WordPress+ # error body, or a 202 (a common bot-check page), comes from a layer in front of WordPress.+ if response.status_code == 202 or (response.status_code == 403 and not (is_wp_error and has_credentials)):+ return False, BLOCKED_REQUEST_ERROR+if response.status_code == 403:return False, ("Your WordPress credentials lack permission to read this site. Check the user's role and try again."@@ -282,16 +302,6 @@ def validate_credentials(if response.status_code == 404:return False, "WordPress REST API not found at this URL — confirm the site URL and that the REST API is enabled"- # A WordPress REST error carries a JSON `message` worth surfacing. Anything else — a WAF,- # reverse proxy, or load balancer answering with a bare status line like "Bad Request" — gives- # the user nothing to act on, so replace it with an actionable message naming the status code- # rather than leaking the raw body.- try:- body = response.json()- wp_message = body.get("message") if isinstance(body, dict) else None- except Exception:- wp_message = None-if wp_message:return False, wp_messagereturn False, (