Skip to content

A platform for community discussion. Free, open, simple.

FIX: Clean up push subscriptions whose endpoint domain no longer resolves (#39804)

Rafael dos Santos Silva51ef930d1fef
diff --git a/app/services/push_notification_pusher.rb b/app/services/push_notification_pusher.rb
index 791147b5057..c1dad02d62f 100644
--- a/app/services/push_notification_pusher.rb
+++ b/app/services/push_notification_pusher.rb
@@ -182,6 +182,9 @@ class PushNotificationPusher
handle_generic_error(subscription, e, user, endpoint, message)
rescue OpenSSL::SSL::SSLError => e
handle_generic_error(subscription, e, user, endpoint, message)
+ rescue FinalDestination::SSRFDetector::LookupFailedError,
+ FinalDestination::SSRFDetector::DisallowedIpError => e
+ handle_generic_error(subscription, e, user, endpoint, message)
end
end
diff --git a/spec/services/push_notification_pusher_spec.rb b/spec/services/push_notification_pusher_spec.rb
index eba35973767..6e2d8ed9ea0 100644
--- a/spec/services/push_notification_pusher_spec.rb
+++ b/spec/services/push_notification_pusher_spec.rb
@@ -228,6 +228,30 @@ RSpec.describe PushNotificationPusher do
expect(subscription.error_count).to eq(1)
end
+ it "handles DNS lookup failures for endpoints whose domain no longer resolves" do
+ WebPush.expects(:payload_send).raises(
+ FinalDestination::SSRFDetector::LookupFailedError.new("lookup failed"),
+ )
+ subscription = create_subscription
+
+ expect { execute_push }.to_not raise_exception
+
+ subscription.reload
+ expect(subscription.error_count).to eq(1)
+ end
+
+ it "handles endpoints that resolve to disallowed IPs" do
+ WebPush.expects(:payload_send).raises(
+ FinalDestination::SSRFDetector::DisallowedIpError.new("disallowed"),
+ )
+ subscription = create_subscription
+
+ expect { execute_push }.to_not raise_exception
+
+ subscription.reload
+ expect(subscription.error_count).to eq(1)
+ end
+
describe "`watching_category_or_tag` notifications" do
it "Uses the 'watching_first_post' translation when new topic was created" do
message =