Fix malformed VAPID sub claim

This commit is contained in:
Vyr Cossont 2024-12-19 23:32:42 -08:00
parent 74e30f06d2
commit 86c686b5d6

View file

@ -134,6 +134,18 @@ func (r *realSender) Send(
return gtserror.Newf("error getting VAPID key pair: %w", err) return gtserror.Newf("error getting VAPID key pair: %w", err)
} }
// Get contact email for this instance, if available.
domain := config.GetHost()
instance, err := r.state.DB.GetInstance(ctx, domain)
if err != nil {
return gtserror.Newf("error getting current instance: %w", err)
}
vapidSubjectEmail := instance.ContactEmail
if vapidSubjectEmail == "" {
// Instance contact email not configured. Use a dummy address.
vapidSubjectEmail = "admin@" + domain
}
// Get API representations of notification and accounts involved. // Get API representations of notification and accounts involved.
// This also loads the target account's settings. // This also loads the target account's settings.
apiNotification, err := r.tc.NotificationToAPINotification(ctx, notification, filters, mutes) apiNotification, err := r.tc.NotificationToAPINotification(ctx, notification, filters, mutes)
@ -147,6 +159,7 @@ func (r *realSender) Send(
if err := r.sendToSubscription( if err := r.sendToSubscription(
ctx, ctx,
vapidKeyPair, vapidKeyPair,
vapidSubjectEmail,
subscription, subscription,
notification.TargetAccount, notification.TargetAccount,
apiNotification, apiNotification,
@ -168,6 +181,7 @@ func (r *realSender) Send(
func (r *realSender) sendToSubscription( func (r *realSender) sendToSubscription(
ctx context.Context, ctx context.Context,
vapidKeyPair *gtsmodel.VAPIDKeyPair, vapidKeyPair *gtsmodel.VAPIDKeyPair,
vapidSubjectEmail string,
subscription *gtsmodel.WebPushSubscription, subscription *gtsmodel.WebPushSubscription,
targetAccount *gtsmodel.Account, targetAccount *gtsmodel.Account,
apiNotification *apimodel.Notification, apiNotification *apimodel.Notification,
@ -226,7 +240,7 @@ func (r *realSender) sendToSubscription(
}, },
&webpushgo.Options{ &webpushgo.Options{
HTTPClient: r.httpClient, HTTPClient: r.httpClient,
Subscriber: "https://" + config.GetHost(), Subscriber: vapidSubjectEmail,
VAPIDPublicKey: vapidKeyPair.Public, VAPIDPublicKey: vapidKeyPair.Public,
VAPIDPrivateKey: vapidKeyPair.Private, VAPIDPrivateKey: vapidKeyPair.Private,
TTL: int(TTL.Seconds()), TTL: int(TTL.Seconds()),