Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { emitPostedOrderEvent } from 'modules/orders'
import { addPendingOrderStep } from 'modules/trade/utils/addPendingOrderStep'
import { logTradeFlow } from 'modules/trade/utils/logger'
import { TradeFlowAnalytics } from 'modules/trade/utils/tradeFlowAnalytics'
import { TradeFlowContext } from 'modules/tradeFlow'
import { assertValidBridgeRecipient, TradeFlowContext } from 'modules/tradeFlow'
import { isQuoteExpired } from 'modules/tradeQuote'

import { ethFlowEnv } from 'common/hooks/useContract'
Expand Down Expand Up @@ -91,6 +91,7 @@ export async function ethFlow({
}

logTradeFlow('ETH FLOW', 'STEP 3: sign order')
assertValidBridgeRecipient(tradeQuoteState)

const signingStepManager: SigningStepManager = {
beforeBridgingSign() {
Expand Down
1 change: 1 addition & 0 deletions apps/cowswap-frontend/src/modules/tradeFlow/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { useHandleSwap } from './hooks/useHandleSwap'
export { useTradeFlowContext } from './hooks/useTradeFlowContext'
export { useTradeFlowType } from './hooks/useTradeFlowType'
export { assertValidBridgeRecipient } from './services/assertValidBridgeRecipient.service'
export * from './types/TradeFlowContext'
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { isNonEvmPlaceholderRecipient } from 'modules/tradeQuote'
import type { TradeQuoteState } from 'modules/tradeQuote'

export function assertValidBridgeRecipient(tradeQuoteState: TradeQuoteState): void {
/**
* Safety guard: placeholder addresses injected into quote requests so that routes and prices can
* be fetched before the user has entered a real non-EVM destination address. They must never reach
* an actual order.
*
* The UI already blocks order submission via the RecipientNotSet form validation, but this check
* is a last-resort defence against any path (race condition, future refactor, etc.) that could
* bypass that gate and call postSwapOrderFromQuote with a stale quote still holding a placeholder.
*/
const bridgeRecipient = tradeQuoteState.bridgeQuote?.tradeParameters.bridgeRecipient

if (isNonEvmPlaceholderRecipient(bridgeRecipient)) {
throw new Error('Bridge recipient is a placeholder address. Please set a valid recipient before proceeding.')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { shouldZeroApprove as shouldZeroApproveFn } from 'modules/zeroApproval'
import { getSwapErrorMessage } from 'common/utils/getSwapErrorMessage'

import { SafeBundleFlowContext, TradeFlowContext } from '../../types/TradeFlowContext'
import { assertValidBridgeRecipient } from '../assertValidBridgeRecipient.service'

const LOG_PREFIX = 'SAFE APPROVAL BUNDLE FLOW'

Expand Down Expand Up @@ -83,6 +84,8 @@ export async function safeBundleApprovalFlow({
orderParams.appData = await removePermitHookFromAppData(orderParams.appData, typedHooks)

logTradeFlow(LOG_PREFIX, 'STEP 3: post order')
assertValidBridgeRecipient(tradeContext.tradeQuoteState)

const {
orderId,
signingScheme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { TradeFlowAnalytics } from 'modules/trade/utils/tradeFlowAnalytics'
import { getSwapErrorMessage } from 'common/utils/getSwapErrorMessage'

import { SafeBundleFlowContext, TradeFlowContext } from '../../types/TradeFlowContext'
import { assertValidBridgeRecipient } from '../assertValidBridgeRecipient.service'

const LOG_PREFIX = 'SAFE BUNDLE ETH FLOW'

Expand Down Expand Up @@ -100,6 +101,7 @@ export async function safeBundleEthFlow(
orderParams.appData = await removePermitHookFromAppData(orderParams.appData, typedHooks)

logTradeFlow(LOG_PREFIX, 'STEP 4: post order')
assertValidBridgeRecipient(tradeContext.tradeQuoteState)

const {
orderId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import { callDataContainsPermitSigner, handlePermit } from 'modules/permit'
import { addPendingOrderStep } from 'modules/trade/utils/addPendingOrderStep'
import { logTradeFlow } from 'modules/trade/utils/logger'
import { TradeFlowAnalytics } from 'modules/trade/utils/tradeFlowAnalytics'
import { isNonEvmPlaceholderRecipient } from 'modules/tradeQuote'

import { getSwapErrorMessage } from 'common/utils/getSwapErrorMessage'

import { TradeFlowContext } from '../../types/TradeFlowContext'
import { assertValidBridgeRecipient } from '../assertValidBridgeRecipient.service'

import type { Hex } from 'viem'

Expand Down Expand Up @@ -151,19 +151,7 @@ export async function swapFlow(
},
}

/**
* Safety guard: placeholder addresses injected into quote requests so that routes and prices can
* be fetched before the user has entered a real non-EVM destination address. They must never reach
* an actual order.
*
* The UI already blocks order submission via the RecipientNotSet form validation, but this check
* is a last-resort defence against any path (race condition, future refactor, etc.) that could
* bypass that gate and call postSwapOrderFromQuote with a stale quote still holding a placeholder.
*/
const bridgeRecipient = tradeQuoteState.bridgeQuote?.tradeParameters.bridgeRecipient
if (isNonEvmPlaceholderRecipient(bridgeRecipient)) {
throw new Error('Bridge recipient is a placeholder address. Please set a valid recipient before proceeding.')
}
assertValidBridgeRecipient(tradeQuoteState)

const {
orderId,
Expand Down
Loading