: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(appsflyer): reject api tokens with non-ascii characters during validation (#117244)
Tom Owers776df28279e9
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/appsflyer/appsflyer.py b/products/warehouse_sources/backend/temporal/data_imports/sources/appsflyer/appsflyer.pyindex 47a4785c0747..68f6abf81945 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/appsflyer/appsflyer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/appsflyer/appsflyer.py@@ -300,6 +300,12 @@ def validate_credentials(api_token: str, app_id: str) -> bool:"The AppsFlyer app id looks invalid. Use your app's identifier from the dashboard ""(e.g. 'id123456789' for iOS or the package name for Android).") from None+ # http.client encodes headers as latin-1, so a smart quote pasted with the token would crash the request.+ if not _normalize_token(api_token).isascii():+ raise AppsFlyerCredentialsError(+ "The AppsFlyer API token contains an unsupported character, such as a smart quote pasted along with it. "+ "Paste only the API token (V2) and try again."+ )today = datetime.now(UTC).strftime("%Y-%m-%d")response = _get_session(api_token).get(f"{APPSFLYER_BASE_URL}/api/agg-data/export/app/{quote(app)}/daily_report/v5"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/appsflyer/tests/test_appsflyer.py b/products/warehouse_sources/backend/temporal/data_imports/sources/appsflyer/tests/test_appsflyer.pyindex 90cc099a039f..f72d3f8b22f5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/appsflyer/tests/test_appsflyer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/appsflyer/tests/test_appsflyer.py@@ -163,11 +163,21 @@ class TestValidateCredentials:assert request.headers["authorization"] == "Bearer token"assert "/app/id123456789/" in request.path- def test_validate_rejects_bad_app_id_without_request(self) -> None:+ @pytest.mark.parametrize(+ "api_token, app_id, expected_substring",+ [+ ("token", "bad app!", "app id"),+ ("token\u201d", "id123", "API token"),+ ("\u201ctoken\u201d", "id123", "API token"),+ ],+ )+ def test_validate_rejects_bad_input_without_request(+ self, api_token: str, app_id: str, expected_substring: str+ ) -> None:with scripted_network([]) as network:with pytest.raises(AppsFlyerCredentialsError) as exc:- validate_credentials("token", "bad app!")- assert "app id" in str(exc.value)+ validate_credentials(api_token, app_id)+ assert expected_substring in str(exc.value)assert network.requests_log == []@pytest.mark.parametrize("status_code", [400, 418, 451])