Skip to content

: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.

fix(wordpress): surface actionable error for unexpected REST responses (#72504)

Tom Owers89c35463d45d
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/tests/test_wordpress.py b/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/tests/test_wordpress.py
index 4eb9bbe5831c..5c7d383efa6f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/tests/test_wordpress.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/tests/test_wordpress.py
@@ -276,6 +276,23 @@ class TestValidateCredentials:
else:
assert expected_msg_substr in (msg or "")
+ @pytest.mark.parametrize(
+ "json_data, text, expects_substr, forbidden_substr",
+ [
+ # A bare proxy/WAF status line must not leak; the user gets an actionable message instead.
+ (None, "Bad Request", "unexpected response (HTTP 400)", "Bad Request"),
+ # A genuine WordPress REST error message is still surfaced.
+ ({"message": "rest_invalid_param"}, "", "rest_invalid_param", None),
+ ],
+ )
+ def test_unrecognized_status_does_not_leak_raw_body(self, json_data, text, expects_substr, forbidden_substr):
+ with self._patch_session(_response(status_code=400, json_data=json_data, text=text)):
+ valid, msg = validate_credentials("https://example.com", None, None)
+ assert valid is False
+ assert expects_substr in (msg or "")
+ if forbidden_substr is not None:
+ assert forbidden_substr not in (msg or "")
+
def test_invalid_site_url(self):
valid, msg = validate_credentials("", None, None)
assert valid is False
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/wordpress.py b/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/wordpress.py
index 6bb4c81629e6..e8ea02484d2d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/wordpress.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/wordpress.py
@@ -277,11 +277,22 @@ 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()
- return False, body.get("message", response.text)
+ wp_message = body.get("message") if isinstance(body, dict) else None
except Exception:
- return False, response.text
+ wp_message = None
+
+ if wp_message:
+ return False, wp_message
+ return False, (
+ f"WordPress returned an unexpected response (HTTP {response.status_code}). "
+ "Check the site URL is correct and that the REST API is enabled and reachable, then try again."
+ )
def _parse_retry_after(response: requests.Response) -> float | None: