Skip to content

Commit d7b68bd

Browse files
rk-for-zulipgnprice
authored andcommitted
APNs: log invalid device tokens, rather than sending them
APNs device tokens, as received through out iOS notifications library, should be a hex string. Unfortunately, they're sometimes being sent to the server as "[Object object]". This is most likely due to the argument of `handleDeviceToken` actually being an object, despite its typing as `string`, and being improperly stringified by `encodeParamsForUrl`. However, it may alternatively be the case that someone is mis-stringifying the object before we get our hands on it, so log that case too. This is work toward the resolution of #3672.
1 parent d74696b commit d7b68bd

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/notification/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import NotificationsIOS from 'react-native-notifications';
44

55
import type { Auth, Dispatch, Identity, Narrow, User } from '../types';
66
import { topicNarrow, privateNarrow, groupNarrow } from '../utils/narrow';
7+
import type { JSONable } from '../utils/jsonable';
78
import * as api from '../api';
89
import * as logging from '../utils/logging';
910
import {
@@ -209,7 +210,16 @@ export class NotificationListener {
209210
};
210211

211212
/** Private. */
212-
handleDeviceToken = async (deviceToken: string) => {
213+
handleDeviceToken = async (deviceToken: mixed) => {
214+
// A device token should normally be a string of hex digits. Sometimes,
215+
// however, we appear to receive objects here. Log this. (See issue #3672.)
216+
if (typeof deviceToken !== 'string' || deviceToken === '[Object object]') {
217+
// $FlowFixMe: deviceToken probably _is_ JSONable, but we can only hope
218+
const token: JSONable = deviceToken;
219+
logging.error('Received invalid device token', { token });
220+
return;
221+
}
222+
213223
this.dispatch(gotPushToken(deviceToken));
214224
await this.dispatch(sendAllPushToken());
215225
};

0 commit comments

Comments
 (0)