From c7a02cc7ee0a795373d197222fb927038899552d Mon Sep 17 00:00:00 2001 From: Andreas Richter <708186+richtera@users.noreply.github.com> Date: Tue, 20 Feb 2024 04:30:39 -0500 Subject: [PATCH] fix: crlf was not working correctly. --- src/lib/getDataFromExternalSources.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/getDataFromExternalSources.ts b/src/lib/getDataFromExternalSources.ts index 06bbd2e5..2ab10bae 100644 --- a/src/lib/getDataFromExternalSources.ts +++ b/src/lib/getDataFromExternalSources.ts @@ -101,6 +101,9 @@ export const getDataFromExternalSources = ( // - check whether those could represent valid JSON data. // - then validate the data as JSON // - then verfiy the data against the verification method + + // Improved JSON detection. We now check the first and up to the last 3 bytes. + // The 3 bytes can be `]` or '}' with either SPACE, LF or CRLF at the end. const capture: number[] = []; capture.push(receivedData[0]); if (receivedData.length > 3) { @@ -121,7 +124,7 @@ export const getDataFromExternalSources = ( // Check if the beginning or end are // { and } => JSON.stringify({...}) => pretty much 100% of our JSON will be this. // [ and ] => JSON.stringify([...]) - if (/^(\[.*\]|\{.*\})\s?$/.test(key)) { + if (/^(\[.*\]|\{.*\})\s*$/.test(key)) { const json = Buffer.from(receivedData).toString(); const value = JSON.parse(json); if (isDataAuthentic(value, urlDataWithHash.verification)) {