diff --git a/index.html b/index.html index 55fb2fc..05b0338 100644 --- a/index.html +++ b/index.html @@ -11512,6 +11512,66 @@ } + + + + + + @@ -13096,9 +13156,6 @@ }; - @@ -14532,6 +14688,48 @@ return Math.floor(Math.random(a, b) * multiple); } + function quarantineCoronaElements(str = '') { + try { + patt = /^[ A-Za-z0-9_@#!./{}\[\]""`',:+-\\]*$/ + let no_unwanted_chars = patt.test(str); + let hasHtml = hasHTMLTags(str); + let has_text_script = str.search('script'); + let has_text_eval = str.search('eval'); + let has_text_alert = str.search('alert'); + + if (no_unwanted_chars === true + && hasHtml === -1 + && has_text_script === -1 + && has_text_eval === -1 + && has_text_alert === -1) { + // secure request + str = DOMPurify.sanitize(str); + var sanitized_str = cloneForSanitization(str); + return sanitized_str; + } else return true; + + } catch (error) { + throw new Error(error) + } + } + + function hasHTMLTags(str) { + if ((str === null) || (str === '')) + return false; + else + str = str.toString(); + return str.search(/(<([^>]+)>)/ig, ''); + } + + // https://www.tutorialspoint.com/how-to-remove-html-tags-from-a-string-in-javascript + function replaceHTMLTags(str) { + if ((str === null) || (str === '')) + return false; + else + str = str.toString(); + return str.replace(/(<([^>]+)>)/ig, ''); + } + /*https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze*/ function deepFreeze(object) { // Retrieve the property names defined on object @@ -15319,6 +15517,18 @@ }); } }); + + // Refresh reserved cryptos balances if more than a day has passed + localbitcoinplusplus.kademlia.determineClosestSupernode(params.trader_flo_address) + .then(su=>{ + let last_updated = localStorage.getItem(`refresh_reserved_cryptos_prices_time_${su[0].data.id}`); + let today = new Date().getTime(); + var yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000)); + if(last_updated==null + || (today - last_updated > (24 * 60 * 60 * 1000))) { + reactor.dispatchEvent("refresh_reserved_crypto_balances", params.trader_flo_address); + } + }); } RM_RPC.filter_legit_requests( @@ -16662,7 +16872,7 @@ doSend(delRequestObject) ); }); - +x // AND DO THE SAME ABOVE 2 IN BACKUP RECEIVE RPC } else { // Do not delete these data instantly as the data @@ -16893,6 +17103,18 @@ } }); } + + // Refresh reserved cryptos balances if more than a day has passed + localbitcoinplusplus.kademlia.determineClosestSupernode(params.trader_flo_address) + .then(su=>{ + let last_updated = localStorage.getItem(`refresh_reserved_cryptos_prices_time_${su[0].data.id}`); + let today = new Date().getTime(); + var yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000)); + if(last_updated==null + || (today - last_updated > (24 * 60 * 60 * 1000))) { + reactor.dispatchEvent("refresh_reserved_crypto_balances", params.trader_flo_address); + } + }); } ); return; @@ -20911,6 +21133,8 @@ this.ws_connection.onmessage = function(evt) { let response = evt.data; console.log(`backup message: ${response}`); + let is_corona_positive = quarantineCoronaElements(response); + if(is_corona_positive===true) throw new Error("Response failed sanitization test."); let isItANodeLeavingMessage = response.search(`\\-- left`); if (isItANodeLeavingMessage >= 0) { @@ -20936,6 +21160,16 @@ res_obj.method === "retrieve_shamirs_secret_btc_pvtkey" || res_obj.method === "do_you_have_latest_data_for_this_supernode" ) { + if(res_obj.method === "retrieve_shamirs_secret_btc_pvtkey" + && typeof btc_pvt_arr=="object" + && typeof res_obj.params[0].private_key_chunk=="object" + && typeof res_obj.params[0].private_key_chunk.id=="string" + ) { + let btc_pvt_arr_str = JSON.stringify(Object.values(btc_pvt_arr)); + if(btc_pvt_arr_str.search(res_obj.params[0].private_key_chunk.id)>=0) { + return false; // This id is already sent by some other node + } + } handle_backup_server_messages(response); return; } @@ -21197,6 +21431,11 @@ async function onMessage(evt) { var response = evt.data || evt; console.log("RESPONSE: " + response); + + // Check if request is clean or not + let is_corona_positive = quarantineCoronaElements(response); + if(is_corona_positive===true) throw new Error("Response failed sanitization test."); + // If the message is about leaving of a node determine its FLO Id // and fire respective events let isItANodeLeavingMessage = response.search(`\\-- left`); @@ -21454,7 +21693,7 @@ case "supernode_message": if ( localbitcoinplusplus.master_configurations.supernodesPubKeys - .includes(nodePubKey) && + .includes(res_obj.nodePubKey) && typeof res_obj.params == "object" && typeof res_obj.params[0] == "object" ) { @@ -26337,11 +26576,11 @@ localbitcoinplusplus.wallets.my_local_flo_address ) { // This message was for Primary Supernode and is meant to be run in onMessage() - if ( - res_obj.params[0].db_inst == - localbitcoinplusplus.wallets.my_local_flo_address - ) - return; + // if ( + // res_obj.params[0].db_inst == + // localbitcoinplusplus.wallets.my_local_flo_address + // ) + // return; let shamirs_shares_response = res_obj.params[0]; let retrieve_pvtkey_req_id = @@ -26358,11 +26597,17 @@ let seen_chunk_id_list = []; btc_pvt_arr[retrieve_pvtkey_req_id].filter(function(item) { - return seen_chunk_id_list.hasOwnProperty( - item.private_key_chunk.id - ) - ? false - : seen_chunk_id_list.push(item.private_key_chunk.id); + // return seen_chunk_id_list.hasOwnProperty( + // item.private_key_chunk.id + // ) + // ? false + // : seen_chunk_id_list.push(item.private_key_chunk.id); + if(!seen_chunk_id_list.hasOwnProperty( + item.private_key_chunk.id + ) && typeof item.private_key_chunk.id=="string") { + return seen_chunk_id_list.push(item.private_key_chunk.id); + } + }); if ( @@ -26388,6 +26633,16 @@ ); res_obj.params[0].trader_flo_address = localbitcoinplusplus.wallets.my_local_flo_address; + + // This response was sent by a backup (right direction) supernode + if(res_obj.params[0].db_inst==localbitcoinplusplus.wallets.my_local_flo_address) { + RM_RPC.receive_rpc_response.call( + this, + JSON.stringify(res_obj) + ); + return; + } + RM_RPC.backup_receive_rpc_response.call( this, JSON.stringify(res_obj)