From 87c65e4beab98b9660fd0a8058a24ca3f050c025 Mon Sep 17 00:00:00 2001 From: Rishab <33950743+rishabjasrotia@users.noreply.github.com> Date: Wed, 22 Nov 2023 06:20:02 +0000 Subject: [PATCH 1/2] #204 - Fix issue due to Signature URL validation --- microfrontends/SignDocuments/package-lock.json | 9 +++++++++ microfrontends/SignDocuments/package.json | 1 + .../SignDocuments/src/Component/PdfRequestFiles.js | 7 ++++--- .../SignDocuments/src/Component/SignYourselfPdf.js | 6 +++--- .../SignDocuments/src/Component/recipientSignPdf.js | 7 ++++--- microfrontends/SignDocuments/src/utils/Utils.js | 6 ++++++ 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/microfrontends/SignDocuments/package-lock.json b/microfrontends/SignDocuments/package-lock.json index 30f707e44..d087684f9 100644 --- a/microfrontends/SignDocuments/package-lock.json +++ b/microfrontends/SignDocuments/package-lock.json @@ -36,6 +36,7 @@ "react-scrollbars-custom": "^4.1.1", "react-signature-canvas": "^1.0.6", "reactour": "^1.19.1", + "validator": "^13.11.0", "web-vitals": "^2.1.4" } }, @@ -20502,6 +20503,14 @@ "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==" }, + "node_modules/validator": { + "version": "13.11.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.11.0.tgz", + "integrity": "sha512-Ii+sehpSfZy+At5nPdnyMhx78fEoPDkR2XW/zimHEL3MyGJQOCQ7WeP20jPYRz7ZCpcKLB21NxuXHF3bxjStBQ==", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/microfrontends/SignDocuments/package.json b/microfrontends/SignDocuments/package.json index 97970e988..8389bf007 100644 --- a/microfrontends/SignDocuments/package.json +++ b/microfrontends/SignDocuments/package.json @@ -32,6 +32,7 @@ "react-scrollbars-custom": "^4.1.1", "react-signature-canvas": "^1.0.6", "reactour": "^1.19.1", + "validator": "^13.11.0", "web-vitals": "^2.1.4" }, "scripts": { diff --git a/microfrontends/SignDocuments/src/Component/PdfRequestFiles.js b/microfrontends/SignDocuments/src/Component/PdfRequestFiles.js index bfcfd7cb3..214999207 100644 --- a/microfrontends/SignDocuments/src/Component/PdfRequestFiles.js +++ b/microfrontends/SignDocuments/src/Component/PdfRequestFiles.js @@ -14,7 +14,8 @@ import RenderAllPdfPage from "./component/renderAllPdfPage"; import { contractDocument, getBase64FromIMG, - getBase64FromUrl + getBase64FromUrl, + urlValidator } from "../utils/Utils"; import Loader from "./component/loader"; import HandleError from "./component/HandleError"; @@ -346,7 +347,7 @@ function PdfRequestFiles() { imgUrlList.map(async (data) => { //cheking signUrl is defau;t signature url of custom url let ImgUrl = data.SignUrl; - const checkUrl = ImgUrl.includes("https:"); + const checkUrl = urlValidator(ImgUrl); //if default signature url then convert it in base 64 if (checkUrl) { @@ -434,7 +435,7 @@ function PdfRequestFiles() { imgUrlList.map(async (url) => { let signUrl = url.SignUrl; - const checkUrl = url.SignUrl.includes("https:"); + const checkUrl = urlValidator(signUrl); if (checkUrl) { signUrl = signUrl + "?get"; } diff --git a/microfrontends/SignDocuments/src/Component/SignYourselfPdf.js b/microfrontends/SignDocuments/src/Component/SignYourselfPdf.js index 2b5eebdc8..9044b38d9 100644 --- a/microfrontends/SignDocuments/src/Component/SignYourselfPdf.js +++ b/microfrontends/SignDocuments/src/Component/SignYourselfPdf.js @@ -24,7 +24,7 @@ import HandleError from "./component/HandleError"; import Nodata from "./component/Nodata"; import Header from "./component/header"; import RenderPdf from "./component/renderPdf"; -import { contractUsers, contactBook } from "../utils/Utils"; +import { contractUsers, contactBook, urlValidator } from "../utils/Utils"; //For signYourself inProgress section signer can add sign and complete doc sign. function SignYourSelf() { const [pdfDetails, setPdfDetails] = useState([]); @@ -444,7 +444,7 @@ function SignYourSelf() { imgUrlList.map(async (data) => { let ImgUrl = data.SignUrl; //cheking signUrl is defau;t signature url of custom url - const checkUrl = ImgUrl.includes("https:"); + const checkUrl = urlValidator(ImgUrl); //if default signature url then convert it in base 64 if (checkUrl) { @@ -524,7 +524,7 @@ function SignYourSelf() { imgUrlList.map(async (url) => { let signUrl = url.SignUrl; - const checkUrl = url.SignUrl.includes("https:"); + const checkUrl = urlValidator(signUrl); if (checkUrl) { signUrl = signUrl + "?get"; } diff --git a/microfrontends/SignDocuments/src/Component/recipientSignPdf.js b/microfrontends/SignDocuments/src/Component/recipientSignPdf.js index 0b9a106c9..840db9409 100644 --- a/microfrontends/SignDocuments/src/Component/recipientSignPdf.js +++ b/microfrontends/SignDocuments/src/Component/recipientSignPdf.js @@ -16,7 +16,8 @@ import { getBase64FromIMG, contractUsers, contactBook, - contractDocument + contractDocument, + urlValidator } from "../utils/Utils"; import Tour from "reactour"; import Signedby from "./component/signedby"; @@ -445,7 +446,7 @@ function EmbedPdfImage() { imgUrlList.map(async (data) => { //cheking signUrl is defau;t signature url of custom url let ImgUrl = data.SignUrl; - const checkUrl = ImgUrl.includes("https:"); + const checkUrl = urlValidator(ImgUrl); //if default signature url then convert it in base 64 if (checkUrl) { @@ -523,7 +524,7 @@ function EmbedPdfImage() { const images = await Promise.all( imgUrlList.map(async (url) => { let signUrl = url.SignUrl; - const checkUrl = url.SignUrl.includes("https:"); + const checkUrl = urlValidator(signUrl); if (checkUrl) { signUrl = signUrl + "?get"; } diff --git a/microfrontends/SignDocuments/src/utils/Utils.js b/microfrontends/SignDocuments/src/utils/Utils.js index ecf6d0359..0413c7d87 100644 --- a/microfrontends/SignDocuments/src/utils/Utils.js +++ b/microfrontends/SignDocuments/src/utils/Utils.js @@ -1,4 +1,5 @@ import axios from "axios"; +import validator from 'validator'; export async function getBase64FromUrl(url) { const data = await fetch(url); @@ -299,3 +300,8 @@ export const contactBook = async (objectId) => { }); return result; }; + +// function for validating URLs +export function urlValidator(url) { + return validator.isURL(url); +}; \ No newline at end of file From 1b3508a9ef34ce454e3637201cf2c9d2a340e39c Mon Sep 17 00:00:00 2001 From: rishabjasrotia Date: Wed, 22 Nov 2023 18:57:18 +0530 Subject: [PATCH 2/2] Replace npm package with manual valiadation --- microfrontends/SignDocuments/package-lock.json | 9 --------- microfrontends/SignDocuments/package.json | 1 - microfrontends/SignDocuments/src/utils/Utils.js | 8 ++++++-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/microfrontends/SignDocuments/package-lock.json b/microfrontends/SignDocuments/package-lock.json index d087684f9..30f707e44 100644 --- a/microfrontends/SignDocuments/package-lock.json +++ b/microfrontends/SignDocuments/package-lock.json @@ -36,7 +36,6 @@ "react-scrollbars-custom": "^4.1.1", "react-signature-canvas": "^1.0.6", "reactour": "^1.19.1", - "validator": "^13.11.0", "web-vitals": "^2.1.4" } }, @@ -20503,14 +20502,6 @@ "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==" }, - "node_modules/validator": { - "version": "13.11.0", - "resolved": "https://registry.npmjs.org/validator/-/validator-13.11.0.tgz", - "integrity": "sha512-Ii+sehpSfZy+At5nPdnyMhx78fEoPDkR2XW/zimHEL3MyGJQOCQ7WeP20jPYRz7ZCpcKLB21NxuXHF3bxjStBQ==", - "engines": { - "node": ">= 0.10" - } - }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/microfrontends/SignDocuments/package.json b/microfrontends/SignDocuments/package.json index 8389bf007..97970e988 100644 --- a/microfrontends/SignDocuments/package.json +++ b/microfrontends/SignDocuments/package.json @@ -32,7 +32,6 @@ "react-scrollbars-custom": "^4.1.1", "react-signature-canvas": "^1.0.6", "reactour": "^1.19.1", - "validator": "^13.11.0", "web-vitals": "^2.1.4" }, "scripts": { diff --git a/microfrontends/SignDocuments/src/utils/Utils.js b/microfrontends/SignDocuments/src/utils/Utils.js index 0413c7d87..f7d42f214 100644 --- a/microfrontends/SignDocuments/src/utils/Utils.js +++ b/microfrontends/SignDocuments/src/utils/Utils.js @@ -1,5 +1,4 @@ import axios from "axios"; -import validator from 'validator'; export async function getBase64FromUrl(url) { const data = await fetch(url); @@ -303,5 +302,10 @@ export const contactBook = async (objectId) => { // function for validating URLs export function urlValidator(url) { - return validator.isURL(url); + try { + const newUrl = new URL(url); + return newUrl.protocol === 'http:' || newUrl.protocol === 'https:'; + } catch (err) { + return false; + } }; \ No newline at end of file