diff --git a/packages/web/src/pages/Submissions/SubmissionFormPage/submissionsService.api.ts b/packages/web/src/pages/Submissions/SubmissionFormPage/submissionsService.api.ts
index 1a7b22d4b..87579c9d3 100644
--- a/packages/web/src/pages/Submissions/SubmissionFormPage/submissionsService.api.ts
+++ b/packages/web/src/pages/Submissions/SubmissionFormPage/submissionsService.api.ts
@@ -1,8 +1,9 @@
import { IVault } from "@hats-finance/shared";
import { axiosClient } from "config/axiosClient";
+import { auditWizardVerifyService } from "constants/constants";
import { BASE_SERVICE_URL } from "settings";
import { getGithubIssueDescription } from "../SubmissionFormPage/FormSteps/SubmissionDescriptions/utils";
-import { ISubmissionData, ISubmitSubmissionRequest } from "./types";
+import { IAuditWizardSubmissionData, ISubmissionData, ISubmitSubmissionRequest } from "./types";
/**
* Submits a new vulnerability submission
@@ -46,3 +47,15 @@ export async function submitVulnerabilitySubmission(
return { success: false };
}
}
+
+/**
+ * Verifies the signature sent by Audit Wizard
+ */
+export async function verifyAuditWizardSignature(auditWizardSubmission: IAuditWizardSubmissionData): Promise {
+ try {
+ const res = await axiosClient.put(`${auditWizardVerifyService}`, auditWizardSubmission);
+ return res.status === 200;
+ } catch (error) {
+ return false;
+ }
+}
diff --git a/packages/web/src/pages/Submissions/SubmissionFormPage/types.ts b/packages/web/src/pages/Submissions/SubmissionFormPage/types.ts
index a438a4dcb..05a0855b2 100644
--- a/packages/web/src/pages/Submissions/SubmissionFormPage/types.ts
+++ b/packages/web/src/pages/Submissions/SubmissionFormPage/types.ts
@@ -32,7 +32,7 @@ export interface ISubmissionsDescriptionsData {
description: string;
severity: string;
files: ISavedFile[];
- sessionKey: SessionKey;
+ sessionKey?: SessionKey;
isEncrypted?: boolean;
}[];
}
@@ -51,13 +51,14 @@ export interface ISubmissionResultData {
}
export interface ISubmissionData {
- version: string;
+ version?: string;
project?: ISubmissionProjectData;
contact?: ISubmissionContactData;
submissionsDescriptions: ISubmissionsDescriptionsData;
terms?: ISubmissionTermsData;
submissionResult?: ISubmissionResultData;
ref?: "audit-wizard";
+ auditWizardData?: IAuditWizardSubmissionData;
}
export enum SubmissionOpStatus {
@@ -80,3 +81,47 @@ export interface ISubmitSubmissionRequest {
issueFiles: string[];
}[];
}
+
+export interface IAuditWizardSubmissionData {
+ signature: string;
+ contact: {
+ beneficiary: string;
+ communicationChannel: string;
+ communicationChannelType: ISubmissionContactData["communicationChannelType"];
+ };
+ project: { projectId: string };
+ submissionsDescriptions: { descriptions: { title: string; severity: string; description: string }[] };
+}
+
+/**
+ * This functions puts the current state of the form into the AuditWizard format in order to
+ * verify it with their API. The from should have exactly the same values as the received from
+ * audit wizard.
+ */
+export const getCurrentAuditwizardSubmission = (
+ awSubmission: IAuditWizardSubmissionData,
+ form: ISubmissionData
+): IAuditWizardSubmissionData => {
+ return {
+ ...awSubmission,
+ contact: {
+ ...awSubmission.contact,
+ beneficiary: form.contact?.beneficiary ?? "",
+ communicationChannel: form.contact?.communicationChannel ?? "",
+ communicationChannelType: form.contact?.communicationChannelType ?? "email",
+ },
+ project: {
+ ...awSubmission.project,
+ projectId: form.project?.projectId ?? "",
+ },
+ submissionsDescriptions: {
+ ...awSubmission.submissionsDescriptions,
+ descriptions:
+ form.submissionsDescriptions?.descriptions.map((d, idx) => ({
+ title: d.title,
+ description: d.description,
+ severity: awSubmission.submissionsDescriptions.descriptions[idx].severity,
+ })) ?? [],
+ },
+ };
+};
From 14370c094693740f8b34ce880d23b0ba4351fc38 Mon Sep 17 00:00:00 2001
From: Carlos Fontes
Date: Mon, 11 Sep 2023 19:23:59 +0100
Subject: [PATCH 5/9] fixes
---
.../SubmissionFormPage/SubmissionFormPage.tsx | 36 ++++++++++---------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx b/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
index ab3317998..6f868df20 100644
--- a/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
+++ b/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
@@ -152,11 +152,7 @@ export const SubmissionFormPage = () => {
} else if (cachedData.version !== getAppVersion()) {
setSubmissionData(SUBMISSION_INIT_DATA);
} else {
- if (cachedData.ref === "audit-wizard") {
- setAllFormDisabled(true);
- setReceivedSubmissionAuditwizard(cachedData.auditWizardData);
- }
-
+ if (cachedData.ref === "audit-wizard") setAllFormDisabled(true);
setSubmissionData(cachedData);
}
} catch (e) {
@@ -219,11 +215,11 @@ export const SubmissionFormPage = () => {
const calculatedCid = await calcCid(submission);
if (submissionData.ref === "audit-wizard") {
- if (!receivedSubmissionAuditwizard) return;
+ if (!submissionData.auditWizardData) return;
// Verify if the submission was not changed and validate the signature
- const auditwizardSubmission = getCurrentAuditwizardSubmission(receivedSubmissionAuditwizard, submissionData);
+ const auditwizardSubmission = getCurrentAuditwizardSubmission(submissionData.auditWizardData, submissionData);
- if (JSON.stringify(receivedSubmissionAuditwizard) !== JSON.stringify(auditwizardSubmission)) {
+ if (JSON.stringify(submissionData.auditWizardData) !== JSON.stringify(auditwizardSubmission)) {
return confirm({
title: t("submissionChanged"),
titleIcon: ,
@@ -244,7 +240,7 @@ export const SubmissionFormPage = () => {
}
sendVulnerabilityOnChain(calculatedCid);
- }, [sendVulnerabilityOnChain, submissionData, receivedSubmissionAuditwizard, confirm, t]);
+ }, [sendVulnerabilityOnChain, submissionData, confirm, t]);
const handleClearSubmission = async () => {
const wantsToClear = await confirm({
@@ -259,14 +255,6 @@ export const SubmissionFormPage = () => {
reset();
};
- window.addEventListener("message", function (event) {
- if (IS_PROD && !event.origin.includes("auditwizard.io")) return;
-
- if (receivedSubmissionAuditwizard) return;
- if (!event.data.signature || !event.data.project || !event.data.contact) return;
- setReceivedSubmissionAuditwizard(event.data);
- });
-
const populateDataFromAuditWizard = async (auditWizardSubmission: IAuditWizardSubmissionData) => {
if (!vaultsReadyAllChains) return;
@@ -328,6 +316,20 @@ export const SubmissionFormPage = () => {
setAllFormDisabled(true);
};
+ useEffect(() => {
+ const checkEvent = (event: MessageEvent) => {
+ if (IS_PROD && !event.origin.includes("auditwizard.io")) return;
+ if (!event.data.signature || !event.data.project || !event.data.contact) return;
+ setReceivedSubmissionAuditwizard(event.data);
+ };
+
+ window.addEventListener("message", checkEvent);
+
+ return () => {
+ window.removeEventListener("message", checkEvent);
+ };
+ }, []);
+
// Populate data from audit wizard once vaults are ready
useEffect(() => {
if (!vaultsReadyAllChains) return;
From 949c54d49b77a5654db0045cdd5f293b2f544086 Mon Sep 17 00:00:00 2001
From: Carlos Fontes
Date: Fri, 15 Sep 2023 08:56:22 -0700
Subject: [PATCH 6/9] Removed commented code
---
.../SubmissionFormPage/SubmissionFormPage.tsx | 26 -------------------
1 file changed, 26 deletions(-)
diff --git a/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx b/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
index 6f868df20..bf9a4d7e6 100644
--- a/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
+++ b/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
@@ -32,32 +32,6 @@ import {
getCurrentAuditwizardSubmission,
} from "./types";
-// const auditWizardExample = JSON.parse(`{
-// "signature": "47732adf56d4ff7e4b0d0d6d8f09217044a0b8c9d22c06fd2713f7ffc27d210816dcfd35ef3e51a54a4be82027e88bfbd2dd58c36364d51002668e21fe8a4fe2b05baa673fc7152903166b5ac19b5641772327b7567f169888f7214d0a42f219652c17c5da70cf2c1a02319b139875a1aac9405ef9f2fb9058c89e00381cfabf154751853a0e406086ad0faa82b2bd8b03ec0e4b844c954eef3e9226772258bc5de5d7b2d0b4f731dc3763b9632288595ae3b2e505fb8f4e69969f82d1c6988de485dffdb2de553918c97eb7adf50a1e2680880dce59706869eec758f12c457a1d57a24032d02e7ec027584e63ffa5921cffea10bf26d32a3ab3cfea45216488",
-// "project": {
-// "projectId": "0x18fbe473b99b3d68f5ad35881149ea0e1b56e091"
-// },
-// "contact": {
-// "beneficiary": "0x6085fBB553F125C0234b28dE7D4228F2873B3428",
-// "communicationChannel": "test@auditware.io",
-// "communicationChannelType": "email"
-// },
-// "submissionDescriptions": {
-// "descriptions": [
-// {
-// "title": "Malicious pair can re-enter 'VeryFastRouter' to drain funds",
-// "description": "VeryFastRouter::swap is the main entry point for a user to perform a batch of sell and buy orders on the new Sudoswap router, allowing partial fill conditions to be specified. Sell orders are executed first, followed by buy orders. The LSSVMPair contracts themselves are implemented in such a way that re-entrancy is not possible, but the same is not true of the VeryFastRouter. Assuming a user calls VeryFastRouter::swap, selling some NFTs and passing in some additional ETH value for subsequent buy orders, an attacker can re-enter this function under certain conditions to steal the original caller's funds. Given that this function does not check whether the user input contains valid pairs, an attacker can use this to manipulate",
-// "severity": "Critical"
-// },
-// {
-// "title": "Lack of Input Validation in Transfer Function",
-// "description": "The smart contract being audited exhibits a low severity issue related to the lack of input validation in the transfer function. The contract allows users to transfer tokens between addresses, but it fails to adequately validate the input parameters, which can lead to potential vulnerabilities.",
-// "severity": "Low"
-// }
-// ]
-// }
-// }`);
-
export const SubmissionFormPage = () => {
const { t } = useTranslation();
const confirm = useConfirm();
From c0129b02b70f25b63ece62b0176e421cc76dcb88 Mon Sep 17 00:00:00 2001
From: Carlos Fontes
Date: Mon, 18 Sep 2023 08:51:49 -0700
Subject: [PATCH 7/9] improved auditwzard origin validation
---
.../pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx b/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
index 6f868df20..3c76d1b03 100644
--- a/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
+++ b/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
@@ -318,7 +318,7 @@ export const SubmissionFormPage = () => {
useEffect(() => {
const checkEvent = (event: MessageEvent) => {
- if (IS_PROD && !event.origin.includes("auditwizard.io")) return;
+ if (IS_PROD && event.origin !== "https://www.auditwizard.io") return;
if (!event.data.signature || !event.data.project || !event.data.contact) return;
setReceivedSubmissionAuditwizard(event.data);
};
From 20419cf7da58e98e8a3facc82b483a9c316a8b54 Mon Sep 17 00:00:00 2001
From: Carlos Fontes
Date: Mon, 18 Sep 2023 13:12:23 -0700
Subject: [PATCH 8/9] URL verification fix
---
.../Submissions/SubmissionFormPage/SubmissionFormPage.tsx | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx b/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
index c75656c36..941cded64 100644
--- a/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
+++ b/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
@@ -292,8 +292,10 @@ export const SubmissionFormPage = () => {
useEffect(() => {
const checkEvent = (event: MessageEvent) => {
- if (IS_PROD && event.origin !== "https://www.auditwizard.io") return;
+ const host = new URL(event.origin).host;
+ if (IS_PROD && !host.includes("auditwizard.io")) return;
if (!event.data.signature || !event.data.project || !event.data.contact) return;
+
setReceivedSubmissionAuditwizard(event.data);
};
From 1106905339e473bced4ab66a497742980f519ed3 Mon Sep 17 00:00:00 2001
From: Carlos Fontes
Date: Mon, 18 Sep 2023 13:21:33 -0700
Subject: [PATCH 9/9] final fix for host verification
---
.../pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx b/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
index 941cded64..4ea212768 100644
--- a/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
+++ b/packages/web/src/pages/Submissions/SubmissionFormPage/SubmissionFormPage.tsx
@@ -293,7 +293,7 @@ export const SubmissionFormPage = () => {
useEffect(() => {
const checkEvent = (event: MessageEvent) => {
const host = new URL(event.origin).host;
- if (IS_PROD && !host.includes("auditwizard.io")) return;
+ if (IS_PROD && host !== "app.auditwizard.io") return;
if (!event.data.signature || !event.data.project || !event.data.contact) return;
setReceivedSubmissionAuditwizard(event.data);