Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate - Push subscription has unsubscribed or expired. #3

Closed
dbrennand opened this issue Oct 12, 2021 · 14 comments
Closed

Investigate - Push subscription has unsubscribed or expired. #3

dbrennand opened this issue Oct 12, 2021 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@dbrennand
Copy link
Owner

dbrennand commented Oct 12, 2021

The logs for the consumer contain several errors which I haven't seen before. The errors indicate that push notifications are not being delivered.

{"level":"error","time":1634065886760,"msg":"push subscription has unsubscribed or expired.\n"}
{"level":"error","time":1634065886761,"msg":"push subscription has unsubscribed or expired.\n"}
{"level":"error","time":1634065886761,"msg":"push subscription has unsubscribed or expired.\n"}

This needs to be investigated further.

Users are highly likely to not be receiving push notifications due to this.

Seems to only be occuring for subscriptions that come from Chromium based browsers.

@dbrennand dbrennand added the bug Something isn't working label Oct 12, 2021
@dbrennand dbrennand self-assigned this Oct 12, 2021
@dbrennand
Copy link
Owner Author

@dbrennand dbrennand added the help wanted Extra attention is needed label Oct 12, 2021
@dbrennand
Copy link
Owner Author

dbrennand commented Oct 12, 2021

Tasks

  • Add event listener for pushsubscriptionchange in sw.js - Commit: 1169420
  • Add new endpoint /edit-subscription to backend/index.js - Commit: a81472c
  • Investigate how/if CSRF protection can be implemented with service worker when pushsubscriptionchange event occurs.
  • Test pushsubscriptionchange works correctly.

@dbrennand dbrennand pinned this issue Oct 12, 2021
@dbrennand
Copy link
Owner Author

dbrennand commented Oct 12, 2021

Work for this is being done in v2.1 branch.

@dbrennand
Copy link
Owner Author

A good example of a push notification service worker from PushPad doesn't seem to implement any CSRF protections when a pushsubscriptionchange event occurs.

@dbrennand
Copy link
Owner Author

@dbrennand
Copy link
Owner Author

Tested the /edit-subscription API route using curl.

Replicated payload that would be sent by the service worker. HTTP 200 OK response 👍🏻

Unfortunately, I couldn't get Firefox or Chrome to trigger the pushsubscriptionchange event when altering the browser permissions 😞

@dbrennand
Copy link
Owner Author

Deployed to production. Will monitor in the coming days.

dbrennand added a commit that referenced this issue Oct 30, 2021
@dbrennand dbrennand reopened this Feb 23, 2022
@dbrennand
Copy link
Owner Author

dbrennand commented Feb 23, 2022

I've been looking a little deeper into the pushsubscriptionchange event. Much of the push APIs (PushEvent, PushManager etc are experimental and due to their experimental nature, the findings below are not that suprising.

Here is the current (working draft) W3 specification for the pushsubscriptionchange event.

The specification indicates that the PushSubscriptionChangeEvent interface should have two attributes: newSubscription and oldSubscription. However, conversations in push-api/issues/325 show that when pushsubscriptionchange fires in Firefox, these two attributes are undefined as it has not been implemented yet:

Taken from: w3c/push-api#325 (comment)

Here's the code inside of Firefox that creates and triggers pushsubscriptionchange - you can see it's creating a regular ExtendableEvent instead of a PushSubcriptionChangeEvent that the spec says we should create.

I'm not expert in cpp but it appears to still be that way today:

Commit hash: 9b0bdcc3
File: ServiceWorkerOp.cpp

This presents an issue for users of Firefox who use PS2Alert.me. When the subscription eventually expires, there is no quick/easy way of sending the new subscription data to the server. Luckily, there is a workaround documented here that I could try implementing.

Looking to Chrome, the PushSubscriptionChangeEvent is not implemented at the time of writing this comment. Further evidence for this can be found in this chromium issue. However, for now Chrome seems to be OK for expiring subscriptions as the push provider it uses (Firebase Cloud Messaging) does not expire subscriptions:

It's on our roadmap, but not a major priority for us right now. FCM (our push provider) does not expire subscriptions.

Peter's final comment hints that pushsubscriptionchange may be coming to Chrome sometime this year:

We still plan to ship this, but it most likely will be delayed until 2022.

Looking to Microsoft Edge, the status page points to the Push API being supported. However, to what extent I'm not sure (e.g. Is PushSubscriptionChangeEvent supported).

@dbrennand dbrennand removed the help wanted Extra attention is needed label Feb 23, 2022
@dbrennand
Copy link
Owner Author

dbrennand commented Feb 23, 2022

The recommended library: https://github.com/RyotaSugawara/serviceworker-storage from the medium post is now readonly.

Looking into using: https://github.com/jakearchibald/idb

EDIT: I only need to set and get to IndexedDB. Now looking at: https://www.npmjs.com/package/idb-keyval

dbrennand added a commit that referenced this issue Feb 24, 2022
Handle setting, deleting and updating subscription.
@dbrennand
Copy link
Owner Author

Further work is being done in branch v2.2 - Changes to be implemented to production soon.

@dbrennand
Copy link
Owner Author

Changes implemented into production. To monitor over the coming days again.

@dbrennand
Copy link
Owner Author

dbrennand commented Mar 6, 2022

Testing with Firefox, the pushsubscriptionchange event fired however, the following error was thrown by the service worker:

Screenshot 2022-03-06 113638

Screenshot 2022-03-06 110452

At line 26 indicating that newSubscription was null. Furthermore, this indicates that Firefox does not re-create the subscription when it expires and a new subscription needs to be created manually.

The service worker will need the Public VAPID key and urlBase64ToUint8Array function to do this.

@dbrennand dbrennand reopened this Mar 6, 2022
@dbrennand
Copy link
Owner Author

Changes deployed to production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant