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(stripe-app): unblock uploads and request batch export scopes (#89693)

Matt Brookerc9973408a7d0
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py
index 17fe07d284ba..b881d34b4b03 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py
@@ -1586,9 +1586,11 @@ def create_webhook(
if "permission" in error_str.lower() or "403" in error_str or "forbidden" in error_str.lower():
if auth_method == "oauth":
+ # Stripe refuses an app manifest that requests webhook write, so reconnecting
+ # cannot grant it. Manual setup is the only route for an app-connected source.
return WebhookCreationResult(
success=False,
- error="Your Stripe integration doesn't have permission to create webhooks. Set up the webhook manually below, or reconnect your Stripe integration and grant webhook access.",
+ error="The PostHog Stripe app cannot create webhooks. Set up the webhook manually below.",
)
return WebhookCreationResult(
success=False,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
index 9c9deff420d6..7d4d1e627831 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
@@ -1462,24 +1462,29 @@ class TestSchemaWebhookCapability:
class TestCreateWebhookPermissionErrorCopy:
# Regression test: a permission-denied webhook creation used to always tell the user to add
# the "Write" permission to their API key, even when the source was connected via OAuth and
- # has no API key to edit. Stripe's connected-account refusal also reads as a permission
- # error, but neither a wider scope nor a reconnect can lift it.
+ # has no API key to edit. Stripe's connected-account refusal also reads as a permission error,
+ # but neither a wider scope nor a reconnect can lift it, and Stripe never grants an app webhook
+ # write, so `unreachable_phrase` guards against advice the user cannot act on.
@parameterized.expand(
[
(
"api_key",
"forbidden",
"add the 'Write' permission for 'Webhook endpoints' to your API key",
+ None,
),
- ("oauth", "forbidden", "reconnect your Stripe integration"),
+ ("oauth", "forbidden", "cannot create webhooks", "reconnect"),
(
"oauth",
"You do not have permission to configure webhook endpoints on connected accounts.",
"on your platform account in Stripe",
+ "reconnect",
),
]
)
- def test_permission_error_message_matches_auth_method(self, auth_method, stripe_message, expected_phrase):
+ def test_permission_error_message_matches_auth_method(
+ self, auth_method, stripe_message, expected_phrase, unreachable_phrase
+ ):
with patch.object(stripe_module, "StripeClient") as mock_client_cls:
mock_client = mock_client_cls.return_value
mock_client.webhook_endpoints.create.side_effect = stripe_lib.PermissionError(stripe_message)
@@ -1494,6 +1499,8 @@ class TestCreateWebhookPermissionErrorCopy:
assert result.success is False
assert expected_phrase in (result.error or "")
+ if unreachable_phrase:
+ assert unreachable_phrase not in (result.error or "")
class TestCreateWebhookLimitErrorCopy:
@@ -1524,16 +1531,28 @@ class TestStripeAppManifestCoversSourcePermissions:
# in April, rak_coupon_read in July), each time leaving OAuth users unable to create a webhook
# or import coupons while the key path worked. The manifest is the checked-in source of truth
# for the OAuth grant, so it must cover every scope the source asks a key for.
+ # Stripe rejects an app manifest that requests these, with "requesting <name> permission is
+ # disallowed", so the app can never hold them however much the source wants them. A restricted
+ # key still can, and the key-creation form still asks for them. Listing one here says the OAuth
+ # path goes without it, not that the source stopped needing it.
+ MANIFEST_DISALLOWED = {"webhook_write"}
+
def test_every_source_permission_is_requested_by_the_app(self):
manifest_path = Path(settings.BASE_DIR) / "services" / "stripe-app" / "stripe-app.json"
granted = {entry["permission"] for entry in orjson.loads(manifest_path.read_bytes())["permissions"]}
# A restricted-key scope is the app permission name with a `rak_` prefix.
- required = {permission.removeprefix("rak_") for permission in PERMISSIONS}
+ required = {permission.removeprefix("rak_") for permission in PERMISSIONS} - self.MANIFEST_DISALLOWED
assert required, "PERMISSIONS is empty, so this assertion would pass vacuously"
assert required - granted == set()
+ def test_manifest_omits_every_disallowed_permission(self):
+ manifest_path = Path(settings.BASE_DIR) / "services" / "stripe-app" / "stripe-app.json"
+ granted = {entry["permission"] for entry in orjson.loads(manifest_path.read_bytes())["permissions"]}
+
+ assert granted & self.MANIFEST_DISALLOWED == set()
+
class TestStripeWarehouseParentFanout:
"""The `CustomerBalanceTransaction` sweep reading its parent from the warehouse."""
diff --git a/services/stripe-app/README.md b/services/stripe-app/README.md
index 2b7b14790d35..e114047b6966 100644
--- a/services/stripe-app/README.md
+++ b/services/stripe-app/README.md
@@ -184,20 +184,57 @@ The trick is to temporarily route through a production URL and then redirect bac
The full approach is more involved but tests the entire production flow.
For day-to-day development, the quick approach is recommended.
-### Uploading
+### Releasing
-**You must bump the version in `stripe-app.json` before uploading.**
-Stripe rejects uploads with an already-published version number.
-Use semver: bump the patch for fixes, minor for new fields/features, major for breaking changes.
+Merging a manifest change does not ship it. A release is three steps, and an
+uploaded version is not a published one: every install keeps running the last
+published version until someone publishes the new one in the Stripe dashboard.
-```bash
-# 1. Bump "version" in stripe-app.json
-# 2. Upload
-cd services/stripe-app
-pnpm run upload
-```
+1. **Bump the version in both `stripe-app.json` and `package.json`.**
+ Stripe rejects an upload whose version is already published. The upload
+ regenerates `package-lock.json` from `package.json`, so bumping only the
+ manifest sends Stripe a lockfile that disagrees with it.
+ Use semver: patch for fixes, minor for new fields/features, major for breaking changes.
+
+2. **Upload.**
+
+ ```bash
+ cd services/stripe-app
+ pnpm run upload
+ ```
+
+ This creates a `package-lock.json` (required by Stripe) and uploads the app.
+ Stripe then processes the files, which is not instant.
+
+3. **Publish the version in the Stripe dashboard.** Until then, installs stay on
+ the previously published version, whatever this repo says.
+
+Nothing in CI checks that a merged manifest change was ever uploaded or published,
+and a failed upload leaves no trace here. Version 1.4.0 sat unpublished for 18 days
+for exactly that reason. Confirm the version is live in the dashboard before
+treating a manifest change as shipped.
+
+#### Permissions Stripe refuses
+
+Stripe rejects a manifest that requests certain permissions, failing the upload with
+`requesting <name> permission is disallowed`. `webhook_write` is one of them, which is
+why OAuth-connected warehouse sources cannot create webhooks and point the user at
+manual setup instead. A restricted API key can still hold those permissions, so the
+source keeps `rak_webhook_write` in its `PERMISSIONS` list while the manifest omits it.
+
+`MANIFEST_DISALLOWED` in `test_stripe_source.py` tracks the refused set, and a test
+fails if the manifest reintroduces one. When Stripe refuses a new permission, add it
+there rather than dropping it from `PERMISSIONS`.
+
+#### What the two permission lists control
+
+`permissions` is what the app may do inside the user's Stripe account.
-This creates a `package-lock.json` (required by Stripe) and uploads the app.
+`provisioning.oauth_scopes` is the scope set PostHog grants Stripe's own OAuth token
+for provisioning calls. The PostHog personal API key handed to a provisioned Stripe
+Projects user currently copies that token's scopes, so widening this list widens both.
+That key widens only on a fresh account request, because a refresh carries previous
+scopes forward.
## Environment variables
diff --git a/services/stripe-app/package.json b/services/stripe-app/package.json
index fcb5bbefdc7a..a64e051f289f 100644
--- a/services/stripe-app/package.json
+++ b/services/stripe-app/package.json
@@ -1,6 +1,6 @@
{
"name": "@posthog/stripe",
- "version": "1.4.0",
+ "version": "1.5.0",
"description": "PostHog Stripe app",
"license": "MIT",
"scripts": {
diff --git a/services/stripe-app/stripe-app.json b/services/stripe-app/stripe-app.json
index 11ce68ceb63a..f9ee8546cc28 100644
--- a/services/stripe-app/stripe-app.json
+++ b/services/stripe-app/stripe-app.json
@@ -2,7 +2,7 @@
"$schema": "https://stripe.com/stripe-app.schema.json",
"id": "com.posthog.stripe",
"name": "PostHog",
- "version": "1.4.0",
+ "version": "1.5.0",
"icon": "./assets/logomark.png",
"provisioning": {
"base_url": "https://us.posthog.com/api/partners/stripe/",
@@ -12,7 +12,9 @@
"feature_flag:read",
"experiment:read",
"customer_journey:read",
- "insight:read"
+ "insight:read",
+ "batch_export:read",
+ "batch_export:write"
],
"oauth_token_endpoint": "https://us.posthog.com/api/partners/stripe/oauth/token",
"oauth_client_id": "3pFZtlNOg7UEBtr8t0rBAEbI8E4GBf1YqIC2L4jJ",
@@ -168,10 +170,6 @@
"permission": "webhook_read",
"purpose": "Read webhooks for data syncing"
},
- {
- "permission": "webhook_write",
- "purpose": "Create new webhooks for syncing data in real-time"
- },
{
"permission": "provisioning_account_request_write",
"purpose": "Allows PostHog Stripe app to create and sign in to PostHog accounts."