Skip to content

Commit

Permalink
codacy error being resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
Snafkin547 committed Jun 7, 2024
1 parent 4877adf commit 9a0b1c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions lib/client/socket/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SocketEvent {

// parse message
const json_msg = JSON.parse(msg);
const sender_id = json_msg['party_id'];
const sender_id = String(json_msg['party_id']);

if (this.jiffClient.keymap[sender_id] != null) {
this.jiffClient.handlers.receive_share(json_msg);
Expand Down Expand Up @@ -66,7 +66,7 @@ class SocketEvent {
callback(true); // send ack to server

const json_msg = JSON.parse(msg);
const sender_id = json_msg['party_id'];
const sender_id = String(json_msg['party_id']);
const encrypted = json_msg['encrypted'];

if (this.jiffClient.keymap[sender_id] != null || encrypted !== true) {

Check warning on line 72 in lib/client/socket/events.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/socket/events.js#L72

Generic Object Injection Sink
Expand All @@ -82,15 +82,15 @@ class SocketEvent {

this.jiffClient.socket.on('crypto_provider', (msg, callback) => {
callback(true); // send ack to server
this.jiffClient.handlers.receive_crypto_provider(JSON.parse(msg));
this.jiffClient.handlers.receive_crypto_provider(JSON.parse(String(msg)));

Check failure on line 85 in lib/client/socket/events.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/socket/events.js#L85

Passing untrusted user input in `xpath.parse()` can result in XPATH injection vulnerability.
});

this.jiffClient.socket.on('error', (msg) => {
this.jiffClient.socket.on('error', (_msg) => {

Check warning on line 88 in lib/client/socket/events.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/socket/events.js#L88

Detect inappropriate function body content
try {
msg = JSON.parse(msg);
const msg = JSON.parse(_msg);
this.jiffClient.handlers.error(msg['label'], msg['error']);
} catch (error) {
this.jiffClient.handlers.error('socket.io', msg);
this.jiffClient.handlers.error('socket.io', _msg);
}
});

Expand Down Expand Up @@ -122,8 +122,8 @@ class SocketEvent {
// Check if the parties to wait for are now known
let parties_satisfied = this.jiffClient.__initialized || !initialization;
for (let j = 0; j < parties.length; j++) {
const party_id = parties[j];
if (this.jiffClient.keymap == null || this.jiffClient.keymap[party_id] == null) {
const party_id = parties[parseInt(j, 10)];
if (this.jiffClient.keymap == null || this.jiffClient.keymap[String(party_id)] == null) {
parties_satisfied = false;
break;
}
Expand All @@ -145,7 +145,7 @@ class SocketEvent {
*/
resolve_messages_waiting_for_keys() {
for (let party_id in this.jiffClient.keymap) {
if (!this.jiffClient.keymap.hasOwnProperty(party_id)) {
if (!this.jiffClient.keymap.hasOwnProperty(String(party_id))) {

Check failure on line 148 in lib/client/socket/events.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/socket/events.js#L148

Do not access Object.prototype method 'hasOwnProperty' from target object.
continue;
}

Expand All @@ -166,7 +166,7 @@ class SocketEvent {
}
}

this.jiffClient.messagesWaitingKeys[party_id] = null;
this.jiffClient.messagesWaitingKeys[String(party_id)] = null;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ext/jiff-client-websockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* not have as many protocols. Instead these functions are routed to
* when a message is received and a protocol is manually parsed.
*/
jiff.initSocket = function () {
jiff.socketEvent.initSocket = function () {
const jiffClient = this;

/* ws uses the 'open' protocol on connection. Should not conflict with the
Expand Down Expand Up @@ -222,7 +222,7 @@
JIFFClientInstance.socket.send(JSON.stringify({ socketProtocol: 'initialization', data: msg }));
};

JIFFClientInstance.initSocket();
JIFFClientInstance.socketEvent.initSocket();
};

/* Functions that overwrite client/socket/mailbox.js functionality */
Expand Down

0 comments on commit 9a0b1c6

Please sign in to comment.