: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(workflows): fix stuff for emails (#62287)
Meikel Ratzfd4de8bbded7
diff --git a/posthog/api/integration.py b/posthog/api/integration.pyindex 2464ab90b604..ee4dd82fb1b3 100644--- a/posthog/api/integration.py+++ b/posthog/api/integration.py@@ -150,6 +150,9 @@ class NativeEmailIntegrationSerializer(serializers.Serializer):provider = serializers.ChoiceField(choices=["ses", "maildev"] if settings.DEBUG else ["ses"])mail_from_subdomain = serializers.CharField(required=False, allow_blank=True)+ def validate_email(self, value: str) -> str:+ return value.lower()+class GitHubRepoSerializer(serializers.Serializer):id = serializers.IntegerField()diff --git a/posthog/models/integration.py b/posthog/models/integration.pyindex e72a52cee0f6..c64ceaa8fc40 100644--- a/posthog/models/integration.py+++ b/posthog/models/integration.py@@ -1991,7 +1991,7 @@ class EmailIntegration:def create_native_integration(cls, config: dict, team_id: int, organization_id: str, created_by: User | None = None) -> Integration:- email_address: str = config["email"]+ email_address: str = config["email"].lower()name: str = config["name"]domain: str = email_address.split("@")[1]mail_from_subdomain: str = config.get("mail_from_subdomain", "feedback")diff --git a/posthog/models/test/test_integration_model.py b/posthog/models/test/test_integration_model.pyindex 8981159472f7..820b6f81cab1 100644--- a/posthog/models/test/test_integration_model.py+++ b/posthog/models/test/test_integration_model.py@@ -2169,6 +2169,58 @@ class TestEmailIntegrationDomainValidation(BaseTest):assert disposable_domain in str(exc.value)assert "not supported" in str(exc.value)+ @patch("products.workflows.backend.providers.SESProvider.create_email_domain")+ def test_cross_org_guard_blocks_mixed_case_domain(self, mock_create_email_domain):+ mock_create_email_domain.return_value = {"status": "success", "domain": "example.com"}+ other_org = Organization.objects.create(name="other org")+ other_team = Team.objects.create(organization=other_org, name="other team")+ EmailIntegration.create_native_integration(+ {"email": "[email protected]", "name": "Owner"},+ team_id=other_team.id,+ organization_id=str(other_org.id),+ created_by=self.user,+ )++ with pytest.raises(ValidationError) as exc:+ EmailIntegration.create_native_integration(+ {"email": "[email protected]", "name": "Attacker"},+ team_id=self.team.id,+ organization_id=str(self.organization.id),+ created_by=self.user,+ )+ assert "already exists in another organization" in str(exc.value)++ @patch("products.workflows.backend.providers.SESProvider.create_email_domain")+ def test_stored_domain_is_lowercased(self, mock_create_email_domain):+ mock_create_email_domain.return_value = {"status": "success", "domain": "successdomain.com"}+ integration = EmailIntegration.create_native_integration(+ {"email": "[email protected]", "name": "Test User", "provider": "ses"},+ team_id=self.team.id,+ organization_id=str(self.organization.id),+ created_by=self.user,+ )+ assert integration.config["domain"] == "successdomain.com"++ @parameterized.expand(+ [+ ("gmail_titlecase", "[email protected]"),+ ("gmail_uppercase", "[email protected]"),+ ("gmail_mixed", "[email protected]"),+ ("yahoo_titlecase", "[email protected]"),+ ("hotmail_uppercase", "[email protected]"),+ ]+ )+ def test_free_email_block_is_case_insensitive(self, _name, email):+ config = {"email": email, "name": "Test User"}+ with pytest.raises(ValidationError) as exc:+ EmailIntegration.create_native_integration(+ config,+ team_id=self.team.id,+ organization_id=str(self.organization.id),+ created_by=self.user,+ )+ assert "not supported" in str(exc.value)+class TestGitLabIntegrationSSRFProtection:"""Test SSRF protections in GitLabIntegration."""