diff --git a/src/middleware/index.ts b/src/middleware/index.ts index 24aa57f..faf3ae2 100644 --- a/src/middleware/index.ts +++ b/src/middleware/index.ts @@ -10,9 +10,9 @@ export const validateDataTimeStamp = async (req: Request, res: Response, next: N const { set_data: setData }: SetDataInput = req.body; const { timestamp } = setData; const timeParsed = parseInt(timestamp, 16); - if (~~(Date.now() / 1000) - timeParsed > 90) { - log.error("[validateDataTimeStamp] Message has been signed more than 60s ago", { currentTime: ~~(Date.now() / 1000), timeParsed }); - return res.status(403).json({ error: { timestamp: "Message has been signed more than 90s ago" }, success: false }); + if (~~(Date.now() / 1000) - timeParsed > 600) { + log.error("[validateDataTimeStamp] Message has been signed more than 600s ago", { currentTime: ~~(Date.now() / 1000), timeParsed }); + return res.status(403).json({ error: { timestamp: "Message has been signed more than 600s ago" }, success: false }); } return next(); }; @@ -24,8 +24,8 @@ export const validateMetadataLoopInput = (key: string) => (req: Request, res: Re const { set_data: setData } = param; const { timestamp } = setData; const timeParsed = parseInt(timestamp, 16); - if (~~(Date.now() / 1000) - timeParsed > 90) { - const errors = { index, timestamp: "Message has been signed more than 90s ago" }; + if (~~(Date.now() / 1000) - timeParsed > 600) { + const errors = { index, timestamp: "Message has been signed more than 600s ago" }; log.error("[validateMetadataLoopInput]", { currentTime: ~~(Date.now() / 1000), timeParsed, errors }); return res.status(403).json({ error: errors, success: false }); } @@ -101,9 +101,9 @@ export const validateLockData = (req: Request, res: Response, next: NextFunction } const { timestamp } = val.data; const timeParsed = parseInt(timestamp, 16); - if (~~(Date.now() / 1000) - timeParsed > 90) { - log.error("[validateLockData] Message has been signed more than 90s ago", { currentTime: ~~(Date.now() / 1000), timeParsed }); - return res.status(403).json({ error: { message: "Message has been signed more than 90s ago" }, success: false }); + if (~~(Date.now() / 1000) - timeParsed > 600) { + log.error("[validateLockData] Message has been signed more than 600s ago", { currentTime: ~~(Date.now() / 1000), timeParsed }); + return res.status(403).json({ error: { message: "Message has been signed more than 600s ago" }, success: false }); } return next(); } catch (error) { @@ -140,9 +140,9 @@ export const validateGetOrSetNonceSetInput = async (req: Request, res: Response, return res.status(403).json({ error: { data: "Should be equal to 'getOrSetNonce' or 'getNonce'" }, success: false }); } const timeParsed = parseInt(timestamp, 16); - if (~~(Date.now() / 1000) - timeParsed > 90) { - log.error("[validateGetOrSetNonceSetInput] Message has been signed more than 90s ago", { currentTime: ~~(Date.now() / 1000), timeParsed }); - return res.status(403).json({ error: { timestamp: "Message has been signed more than 90s ago" }, success: false }); + if (~~(Date.now() / 1000) - timeParsed > 600) { + log.error("[validateGetOrSetNonceSetInput] Message has been signed more than 600s ago", { currentTime: ~~(Date.now() / 1000), timeParsed }); + return res.status(403).json({ error: { timestamp: "Message has been signed more than 600s ago" }, success: false }); } return next(); }; diff --git a/test/api.js b/test/api.js index 94d0cc8..3c2832a 100644 --- a/test/api.js +++ b/test/api.js @@ -116,12 +116,12 @@ describe("API-calls", function () { const serializedEncryptedDetails = globalThis.btoa(stringify(encryptedDetails)); const metadataParams = storageLayer.generateMetadataParams(serializedEncryptedDetails, undefined, PRIVATE_KEY); - metadataParams.set_data.timestamp = new BN(~~(Date.now() / 1000) - 95).toString(16); + metadataParams.set_data.timestamp = new BN(~~(Date.now() / 1000) - 605).toString(16); try { await post(`${server}/set`, metadataParams); } catch (err) { const val = await err.json(); - assert.deepStrictEqual(val.error.timestamp, "Message has been signed more than 90s ago"); // same goes for pubkeyY + assert.deepStrictEqual(val.error.timestamp, "Message has been signed more than 600s ago"); // same goes for pubkeyY } }); @@ -227,7 +227,7 @@ describe("API-calls", function () { }); it("#it should reject if one of the shares has an old timestamp", async function () { - finalMetadataParams[0].set_data.timestamp = new BN(~~(Date.now() / 1000) - 95).toString(16); + finalMetadataParams[0].set_data.timestamp = new BN(~~(Date.now() / 1000) - 605).toString(16); const FD = new FormData(); finalMetadataParams.forEach((el, index) => { FD.append(index.toString(), JSON.stringify(el)); @@ -237,7 +237,7 @@ describe("API-calls", function () { await post(`${server}/bulk_set_stream`, FD, options, customOptions); } catch (err) { const { error } = await err.json(); - assert.deepStrictEqual(error.timestamp, "Message has been signed more than 90s ago"); // same goes for pubkeyY + assert.deepStrictEqual(error.timestamp, "Message has been signed more than 600s ago"); // same goes for pubkeyY } });