Skip to content

Commit 3a90c57

Browse files
authored
Ensure customer ID matches in StripeManager#cancelAllActiveSubscriptions
1 parent eab3c36 commit 3a90c57

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/StripeManager.java

+9
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,17 @@ public CompletableFuture<Void> cancelAllActiveSubscriptions(String customerId) {
385385
if (customer == null) {
386386
throw ExceptionUtils.wrap(new IOException("no customer record found for id " + customerId));
387387
}
388+
if (StringUtils.isBlank(customer.getId()) || (!customer.getId().equals(customerId))) {
389+
logger.error("customer ID returned by Stripe ({}) did not match query ({})", customerId, customer.getSubscriptions());
390+
throw ExceptionUtils.wrap(new IOException("unexpected customer ID returned by Stripe"));
391+
}
388392
return listNonCanceledSubscriptions(customer);
389393
}).thenCompose(subscriptions -> {
394+
if (subscriptions.stream()
395+
.anyMatch(subscription -> !subscription.getCustomer().equals(customerId))) {
396+
logger.error("Subscription did not match expected customer ID: {}", customerId);
397+
throw ExceptionUtils.wrap( new IOException("mismatched customer ID"));
398+
}
390399
@SuppressWarnings("unchecked")
391400
CompletableFuture<Subscription>[] futures = (CompletableFuture<Subscription>[]) subscriptions.stream()
392401
.map(this::endSubscription).toArray(CompletableFuture[]::new);

0 commit comments

Comments
 (0)