From 46395f8095e8624d8f0721a3a9244c95c3f4bcf1 Mon Sep 17 00:00:00 2001 From: Leonid Belyaev Date: Mon, 9 Sep 2024 15:41:26 -0700 Subject: [PATCH] Update server_vote_receiver.js Added params sanitization --- app/server_vote_receiver.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/server_vote_receiver.js b/app/server_vote_receiver.js index 76bf549..bb48238 100644 --- a/app/server_vote_receiver.js +++ b/app/server_vote_receiver.js @@ -21,10 +21,14 @@ async function pdaExists(pda) { // Endpoint to append data and initialize PDA if needed app.post('/', async (req, res) => { const { first_block_id, final_hash, pubkey } = req.body; + if (!first_block_id || !final_hash || !pubkey) { + return res.status(400).json({ error: "Bad request", details: "One or more of required params were not supplied" });; + } console.log(req.body); const block_id = first_block_id; console.log(block_id + " " + pubkey + "\n"); + try { const uniqueId = new BN(block_id); const pubkeyObj = new PublicKey(pubkey); @@ -32,6 +36,9 @@ app.post('/', async (req, res) => { [Buffer.from("pda_account"), uniqueId.toArrayLike(Buffer, "le", 8)], program.programId ); + } catch (err) { + res.status(400).json({ error: "Bad request", details: err.toString() }); + } try { // Check if the PDA already exists