You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to handle Net::HTTPBadRequest 400 InvalidTokenFormat? #52
Does InvalidTokenFormat refers to the token in the endpoint URL? Can you try to reproduce that by changing a character inside the endpoint?
If this is the case I agree that Webpush::InvalidSubscription is the right exception.
I did change some parts on p256dh & endpoint. On endpoint I was able to reproduce two exceptions: Net::HTTPBadRequest 400 & Webpush::Unauthorized, whereas wrongp256dh gave OpenSSL::PKey::EC::Point::Error for reason & invalid encoding.
@Rubioli thanks for the information, however can you be more specific?
Net::HTTPBadRequest 400: this is never raised directly... You will see a Webpush::ResponseError, which is the best that we can do with just the status code (400). In order to raise something specific like Webpush::InvalidSubscription we need also a specific status name... what is the name near 400? A general Bad Request or something specific?
Webpush::Unauthorized is already a specific exception and this cannot be further improved
"OpenSSL::PKey::EC::Point::Error for reason & invalid encoding": can you report the exact / full exceptions that you get in this case? Also with the stack trace
1-2: FCM and Autopush have slightly different behaviors and this library reflects that properly. FCM doesn't even check if the endpoint exists when the VAPID key is not associated to that endpoint, and thus returns an authentication failure. Autopush on the other hand first check if the endpoint exists, and thus returns 404. 3-4-5: This library lets the specific Ruby errors propagate. For me this is ok. However if someone believes that we should wrap those errors into a more general exception (e.g. Webpush::BadSubscription), then we should create a separate issue for that. 6: This is absolutely correct. The client will fail to decrypt payload, but no error is raised because everything seems correct from server-side (you can't do anything to prevent that). 7: I agree that we can catch that specific 400 InvalidTokenFormat and return Webpush::InvalidSubscription. You can reproduce this using the endpoint https://fcm.googleapis.com/fcm/send/abc.
Activity
stevenharman commentedon Nov 13, 2018
Seems like this could be added pretty easily:
webpush/lib/webpush/request.rb
Lines 29 to 40 in f380b76
Maybe it was not a known error/response code before now?
collimarco commentedon Nov 28, 2018
Does
InvalidTokenFormatrefers to the token in the endpoint URL? Can you try to reproduce that by changing a character inside the endpoint?If this is the case I agree that
Webpush::InvalidSubscriptionis the right exception.Rubioli commentedon Feb 28, 2019
I did change some parts on
p256dh&endpoint. OnendpointI was able to reproduce two exceptions:Net::HTTPBadRequest 400&Webpush::Unauthorized, whereas wrongp256dhgaveOpenSSL::PKey::EC::Point::Errorfor reason &invalid encoding.collimarco commentedon Feb 28, 2019
@Rubioli thanks for the information, however can you be more specific?
Net::HTTPBadRequest 400: this is never raised directly... You will see aWebpush::ResponseError, which is the best that we can do with just the status code (400). In order to raise something specific likeWebpush::InvalidSubscriptionwe need also a specific status name... what is the name near 400? A generalBad Requestor something specific?Webpush::Unauthorizedis already a specific exception and this cannot be further improvedOpenSSL::PKey::EC::Point::Errorfor reason &invalid encoding": can you report the exact / full exceptions that you get in this case? Also with the stack tracecollimarco commentedon Mar 17, 2019
I have spent some time investigating these issues, here's my results:
Webpush::UnauthorizedWebpush::InvalidSubscriptionURI::InvalidURIErrorOpenSSL::PKey::EC::Point::Errorlib/webpush/encryption.rb:17:in `initialize'ArgumentError: invalid base64lib/webpush.rb:66:in `decode64'Webpush::ResponseError1-2: FCM and Autopush have slightly different behaviors and this library reflects that properly. FCM doesn't even check if the endpoint exists when the VAPID key is not associated to that endpoint, and thus returns an authentication failure. Autopush on the other hand first check if the endpoint exists, and thus returns 404.
3-4-5: This library lets the specific Ruby errors propagate. For me this is ok. However if someone believes that we should wrap those errors into a more general exception (e.g.
Webpush::BadSubscription), then we should create a separate issue for that.6: This is absolutely correct. The client will fail to decrypt payload, but no error is raised because everything seems correct from server-side (you can't do anything to prevent that).
7: I agree that we can catch that specific
400 InvalidTokenFormatand returnWebpush::InvalidSubscription. You can reproduce this using the endpointhttps://fcm.googleapis.com/fcm/send/abc.