Skip to content

Commit

Permalink
Fix data passed over to false positive blockaid report
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri committed Jul 16, 2024
1 parent 2d416bf commit 30a97d8
Showing 1 changed file with 46 additions and 53 deletions.
99 changes: 46 additions & 53 deletions ui/pages/confirmations/hooks/alerts/useBlockaidAlerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ const useBlockaidAlerts = (): Alert[] => {
const securityAlertId = currentConfirmation?.securityAlertResponse
?.securityAlertId as string;

const transactionType = currentConfirmation?.type as TransactionType;

const signatureSecurityAlertResponse = useSelector(
currentSignatureRequestSecurityResponseSelector,
);
Expand All @@ -76,57 +74,58 @@ const useBlockaidAlerts = (): Alert[] => {
)?.securityAlertResponse,
);

const securityAlertResponse =
signatureSecurityAlertResponse || transactionSecurityAlertResponse;
return useMemo<Alert[]>(() => {
const securityAlertResponse =
signatureSecurityAlertResponse || transactionSecurityAlertResponse;

const isTransactionTypeSupported =
SUPPORTED_TRANSACTION_TYPES.includes(transactionType);
if (!securityAlertResponse) {
return [];
}

const isResultTypeIgnored = IGNORED_RESULT_TYPES.includes(
securityAlertResponse?.result_type as BlockaidResultType,
);
const transactionType = currentConfirmation?.type as TransactionType;

let stringifiedJSONData: string | undefined;

if (securityAlertResponse && currentConfirmation) {
const {
block,
features,
reason,
result_type: resultType,
} = securityAlertResponse as SecurityAlertResponse;
const { chainId, msgParams, origin, type, txParams } = currentConfirmation;

const isFailedResultType = resultType === BlockaidResultType.Errored;

const reportData = {
blockNumber: block,
blockaidVersion: BlockaidPackage.version,
chain: (NETWORK_TO_NAME_MAP as Record<string, string>)[
chainId ?? selectorChainId
],
classification: isFailedResultType ? 'error' : reason,
domain: origin ?? msgParams?.origin ?? origin,
jsonRpcMethod: type,
jsonRpcParams: JSON.stringify(txParams ?? msgParams),
resultType: isFailedResultType ? BlockaidResultType.Errored : resultType,
reproduce: JSON.stringify(features),
};

stringifiedJSONData = JSON.stringify(reportData);
}
const isResultTypeIgnored = IGNORED_RESULT_TYPES.includes(
securityAlertResponse?.result_type as BlockaidResultType,
);

return useMemo<Alert[]>(() => {
if (
!isTransactionTypeSupported ||
isResultTypeIgnored ||
!securityAlertResponse
) {
const isTransactionTypeSupported =
SUPPORTED_TRANSACTION_TYPES.includes(transactionType);

if (!isTransactionTypeSupported || isResultTypeIgnored) {
return [];
}

let reportUrl = ZENDESK_URLS.SUPPORT_URL;
if (stringifiedJSONData) {

if (securityAlertResponse && currentConfirmation) {
const {
block,
features,
reason,
result_type: resultType,
} = securityAlertResponse as SecurityAlertResponse;

const { chainId, msgParams, origin, type, txParams } =
currentConfirmation;

const isFailedResultType = resultType === BlockaidResultType.Errored;

const reportData = {
blockNumber: block,
blockaidVersion: BlockaidPackage.version,
chain: (NETWORK_TO_NAME_MAP as Record<string, string>)[
chainId ?? selectorChainId
],
classification: isFailedResultType ? 'error' : reason,
domain: origin ?? msgParams?.origin ?? origin,
jsonRpcMethod: type,
jsonRpcParams: JSON.stringify(txParams ?? msgParams),
resultType: isFailedResultType
? BlockaidResultType.Errored
: resultType,
reproduce: JSON.stringify(features),
};

const stringifiedJSONData = JSON.stringify(reportData);
const encodedData =
zlib?.gzipSync?.(stringifiedJSONData) ?? stringifiedJSONData;

Expand All @@ -136,13 +135,7 @@ const useBlockaidAlerts = (): Alert[] => {
}

return [normalizeProviderAlert(securityAlertResponse, t, reportUrl)];
}, [
isTransactionTypeSupported,
isResultTypeIgnored,
securityAlertResponse,
stringifiedJSONData,
t,
]);
}, [signatureSecurityAlertResponse, transactionSecurityAlertResponse, t]);
};

export default useBlockaidAlerts;

0 comments on commit 30a97d8

Please sign in to comment.