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(cosmosdb): stop echoing the raw azure error on a refused connection (#127992)

Tom Owersce1d6bcc6031
diff --git a/products/warehouse_sources/sources/cosmosdb/cosmosdb.py b/products/warehouse_sources/sources/cosmosdb/cosmosdb.py
index d46069250753..6a41f270cc9f 100644
--- a/products/warehouse_sources/sources/cosmosdb/cosmosdb.py
+++ b/products/warehouse_sources/sources/cosmosdb/cosmosdb.py
@@ -376,7 +376,7 @@ def validate_credentials(endpoint: str, key: str, database: str, api_version: st
"Azure Cosmos DB rejected the account key. Copy a key from the account's Keys page and try again.",
)
if status == 403:
- return False, FORBIDDEN_MESSAGE + _error_description(error.response)
+ return False, FORBIDDEN_MESSAGE
if status == 404:
return False, f"No database named {database} exists in this account. Check the database name."
return False, f"Azure Cosmos DB returned an error: {error}"
diff --git a/products/warehouse_sources/sources/cosmosdb/tests/test_cosmosdb.py b/products/warehouse_sources/sources/cosmosdb/tests/test_cosmosdb.py
index bed5512e550c..fd58b575017c 100644
--- a/products/warehouse_sources/sources/cosmosdb/tests/test_cosmosdb.py
+++ b/products/warehouse_sources/sources/cosmosdb/tests/test_cosmosdb.py
@@ -8,6 +8,7 @@ import time_machine
from products.warehouse_sources.sources.cosmosdb._config import CosmosDBSourceConfig
from products.warehouse_sources.sources.cosmosdb.cosmosdb import (
+ FORBIDDEN_MESSAGE,
CosmosDBResumeConfig,
CosmosDBRetryableError,
CosmosDBTsCursor,
@@ -354,6 +355,20 @@ class TestValidateCredentials:
assert network.requests_log[0].path == "/dbs/shop/colls"
assert network.requests_log[0].headers["authorization"].startswith("type%3Dmaster%26ver%3D1.0%26sig%3D")
+ def test_forbidden_probe_does_not_echo_the_azure_error_body(self) -> None:
+ response = ScriptedResponse(
+ status=403,
+ json={
+ "code": "Forbidden",
+ "message": "Request blocked by firewall. ActivityId: 00000000-0000-0000-0000-000000000000",
+ },
+ )
+ with scripted_network([response]):
+ ok, message = validate_credentials(ENDPOINT, ACCOUNT_KEY, "shop", "2018-12-31")
+
+ assert ok is False
+ assert message == FORBIDDEN_MESSAGE
+
def test_rejects_a_key_that_is_not_base64_without_a_request(self) -> None:
with scripted_network([]) as network:
ok, message = validate_credentials(ENDPOINT, "not a key", "shop", "2018-12-31")