summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-09-14 13:46:42 +0200
committerErik Larkö <erik@mullvad.net>2017-09-14 13:46:42 +0200
commitb2093638b1e6c4b80ddeacceec52bae8b90e24cf (patch)
tree14595c114556ce7da033a8f3824d20bf33196f6b
parent754af96a12716152f2ddb9e56836e29f28720614 (diff)
downloadmullvadvpn-b2093638b1e6c4b80ddeacceec52bae8b90e24cf.tar.xz
mullvadvpn-b2093638b1e6c4b80ddeacceec52bae8b90e24cf.zip
Replace object dicts with Maps to increase security
-rw-r--r--app/lib/jsonrpc-ws-ipc.js24
1 files changed, 12 insertions, 12 deletions
diff --git a/app/lib/jsonrpc-ws-ipc.js b/app/lib/jsonrpc-ws-ipc.js
index 46ccf51668..89ccc0c44e 100644
--- a/app/lib/jsonrpc-ws-ipc.js
+++ b/app/lib/jsonrpc-ws-ipc.js
@@ -70,8 +70,8 @@ export default class Ipc {
_connectionString: ?string;
_onConnect: Array<{resolve: ()=>void}>;
- _unansweredRequests: {[string]: UnansweredRequest};
- _subscriptions: {[string|number]: (mixed) => void};
+ _unansweredRequests: Map<string, UnansweredRequest>;
+ _subscriptions: Map<string|number, (mixed) => void>;
_websocket: WebSocket;
_backoff: ReconnectionBackoff;
_websocketFactory: (string) => WebSocket;
@@ -79,8 +79,8 @@ export default class Ipc {
constructor(connectionString: string, websocketFactory: ?(string)=>WebSocket) {
this._connectionString = connectionString;
this._onConnect = [];
- this._unansweredRequests = {};
- this._subscriptions = {};
+ this._unansweredRequests = new Map();
+ this._subscriptions = new Map();
this._websocketFactory = websocketFactory || (connectionString => new WebSocket(connectionString));
this._backoff = new ReconnectionBackoff();
@@ -97,7 +97,7 @@ export default class Ipc {
return this.send(event + '_subscribe')
.then(subscriptionId => {
if (typeof subscriptionId === 'string' || typeof subscriptionId === 'number') {
- this._subscriptions[subscriptionId] = listener;
+ this._subscriptions.set(subscriptionId, listener);
} else {
throw new InvalidReply(subscriptionId, 'The subscription id was not a string or a number');
}
@@ -114,12 +114,12 @@ export default class Ipc {
const params = this._prepareParams(data);
const timerId = setTimeout(() => this._onTimeout(id), timeout);
const jsonrpcMessage = jsonrpc.request(id, action, params);
- this._unansweredRequests[id] = {
+ this._unansweredRequests.set(id, {
resolve: resolve,
reject: reject,
timerId: timerId,
message: jsonrpcMessage,
- };
+ });
this._getWebSocket()
.then(ws => {
@@ -161,8 +161,8 @@ export default class Ipc {
}
_onTimeout(requestId) {
- const request = this._unansweredRequests[requestId];
- delete this._unansweredRequests[requestId];
+ const request = this._unansweredRequests.get(requestId);
+ this._unansweredRequests.delete(requestId);
if (!request) {
log.debug(requestId, 'timed out but it seems to already have been answered');
@@ -186,7 +186,7 @@ export default class Ipc {
_onNotification(message: JsonRpcNotification) {
const subscriptionId = message.payload.params.subscription;
- const listener = this._subscriptions[subscriptionId];
+ const listener = this._subscriptions.get(subscriptionId);
if (listener) {
log.debug('Got notification', message.payload.method, message.payload.params.result);
@@ -198,8 +198,8 @@ export default class Ipc {
_onReply(message: JsonRpcError | JsonRpcSuccess) {
const id = message.payload.id;
- const request = this._unansweredRequests[id];
- delete this._unansweredRequests[id];
+ const request = this._unansweredRequests.get(id);
+ this._unansweredRequests.delete(id);
if (!request) {
log.warn('Got reply to', id, 'but no one was waiting for it');