Page MenuHomePhabricator

D8956.id30875.diff
No OneTemporary

D8956.id30875.diff

diff --git a/keyserver/src/socket/tunnelbroker.js b/keyserver/src/socket/tunnelbroker.js
--- a/keyserver/src/socket/tunnelbroker.js
+++ b/keyserver/src/socket/tunnelbroker.js
@@ -3,6 +3,7 @@
import WebSocket from 'ws';
import {
+ refreshKeysTBMessageValidator,
type TBKeyserverConnectionInitializationMessage,
type TBMessage,
tunnelbrokerMessageTypes,
@@ -28,7 +29,11 @@
}
function handleTBMessageEvent(event: ArrayBuffer): Promise<void> {
- const message: TBMessage = JSON.parse(event.toString());
+ const rawMessage = JSON.parse(event.toString());
+ if (!refreshKeysTBMessageValidator.is(rawMessage)) {
+ throw new ServerError('unsupported_tunnelbroker_message');
+ }
+ const message: TBMessage = rawMessage;
if (message.type === tunnelbrokerMessageTypes.REFRESH_KEYS_REQUEST) {
return uploadNewOneTimeKeys(message.numberOfKeys);
diff --git a/lib/types/tunnelbroker-messages.js b/lib/types/tunnelbroker-messages.js
--- a/lib/types/tunnelbroker-messages.js
+++ b/lib/types/tunnelbroker-messages.js
@@ -1,5 +1,9 @@
// @flow
+import t, { type TInterface } from 'tcomb';
+
+import { tShape, tString } from '../utils/validation-utils.js';
+
type TBSharedConnectionInitializationMessage = {
+type: 'sessionRequest',
+deviceId: string,
@@ -39,6 +43,13 @@
+numberOfKeys: number,
};
+export const refreshKeysTBMessageValidator: TInterface<TBRefreshKeysRequest> =
+ tShape<TBRefreshKeysRequest>({
+ type: tString('RefreshKeyRequest'),
+ deviceId: t.String,
+ numberOfKeys: t.Number,
+ });
+
// Disjoint enumeration of all messages
// Currently, only a single message
export type TBMessage = TBRefreshKeysRequest;

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 5:01 AM (17 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2569020
Default Alt Text
D8956.id30875.diff (1 KB)

Event Timeline