mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 12:52:25 -05:00 
			
		
		
		
	Fix malformed VAPID sub claim
This commit is contained in:
		
					parent
					
						
							
								3a239fbe5a
							
						
					
				
			
			
				commit
				
					
						464d920cfd
					
				
			
		
					 1 changed files with 15 additions and 1 deletions
				
			
		|  | @ -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()), | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue