From f92b945a3b77e9a0e027d0d82a8bee6bc158ee8c Mon Sep 17 00:00:00 2001 From: Kyle Den Hartog Date: Fri, 21 Feb 2025 15:50:47 +1300 Subject: [PATCH] Mostly working. Need to fix image rendering from untrusted frames --- .../brave_wallet_ui/common/async/base-query-cache.ts | 2 +- .../slices/endpoints/token_suggestions.endpoints.ts | 4 ++-- .../components/asset-name-and-icon/index.tsx | 4 +++- .../add-account-modal/account-type-item/index.tsx | 2 +- .../desktop/views/explore_web3/dapp_list_item.tsx | 2 +- .../desktop/views/explore_web3/web3_dapp_details.tsx | 2 +- .../components/shared/buy-option/buy-option-item.tsx | 2 +- .../components/shared/create-network-icon/index.tsx | 8 ++++++-- .../components/shared/create-placeholder-icon/index.tsx | 5 ++--- .../components/shared/nft-icon/nft-icon.tsx | 9 ++++++--- .../nft/components/nft-details/nft-screen.tsx | 2 +- .../fund-wallet/components/buy_quote/buy_quote.tsx | 2 +- .../fund-wallet/components/select_asset/select_asset.tsx | 2 +- .../select_asset_button/select_asset_button.tsx | 6 +++--- .../components/select_currency/select_currency.tsx | 4 ++-- .../page/screens/fund-wallet/fund_wallet_v2.tsx | 4 ++-- .../brave_wallet_ui/page/screens/swap/swap.utils.ts | 2 +- 17 files changed, 35 insertions(+), 27 deletions(-) diff --git a/components/brave_wallet_ui/common/async/base-query-cache.ts b/components/brave_wallet_ui/common/async/base-query-cache.ts index dcdff437e25c..f2a0937f5df4 100644 --- a/components/brave_wallet_ui/common/async/base-query-cache.ts +++ b/components/brave_wallet_ui/common/async/base-query-cache.ts @@ -333,7 +333,7 @@ export class BaseQueryCache { } return token.logo.startsWith('ipfs://') ? (await this.getIpfsGatewayTranslatedNftUrl(token.logo)) || '' - : `chrome://erc-token-images/${encodeURIComponent(token.logo)}` + : token.logo } getEnabledCoinTypes = async () => { diff --git a/components/brave_wallet_ui/common/slices/endpoints/token_suggestions.endpoints.ts b/components/brave_wallet_ui/common/slices/endpoints/token_suggestions.endpoints.ts index 6703b82aac43..d94cc5d2c39d 100644 --- a/components/brave_wallet_ui/common/slices/endpoints/token_suggestions.endpoints.ts +++ b/components/brave_wallet_ui/common/slices/endpoints/token_suggestions.endpoints.ts @@ -33,11 +33,11 @@ export const tokenSuggestionsEndpoints = ({ if (logo !== '' && !isRemoteImageURL(logo)) { try { // attempt property reassignment - request.token.logo = `chrome://erc-token-images/${encodeURIComponent(logo)}` + request.token.logo = `chrome://image/?url=${encodeURIComponent(logo)}&staticEncode=true` } catch { request.token = { ...request.token, - logo: `chrome://erc-token-images/${encodeURIComponent(logo)}` + logo: `chrome://image/?url=${encodeURIComponent(logo)}&staticEncode=true` } } } diff --git a/components/brave_wallet_ui/components/asset-name-and-icon/index.tsx b/components/brave_wallet_ui/components/asset-name-and-icon/index.tsx index 8e6f8e6e8937..b7a6eac4a443 100644 --- a/components/brave_wallet_ui/components/asset-name-and-icon/index.tsx +++ b/components/brave_wallet_ui/components/asset-name-and-icon/index.tsx @@ -25,7 +25,9 @@ export const AssetNameAndIcon = (props: Props) => { return ( diff --git a/components/brave_wallet_ui/components/desktop/popup-modals/add-account-modal/account-type-item/index.tsx b/components/brave_wallet_ui/components/desktop/popup-modals/add-account-modal/account-type-item/index.tsx index 65cde2b9b3c6..b8eb1e31a4f3 100644 --- a/components/brave_wallet_ui/components/desktop/popup-modals/add-account-modal/account-type-item/index.tsx +++ b/components/brave_wallet_ui/components/desktop/popup-modals/add-account-modal/account-type-item/index.tsx @@ -30,7 +30,7 @@ const AccountTypeItem = (props: Props) => { return ( - + {title} {description} diff --git a/components/brave_wallet_ui/components/desktop/views/explore_web3/dapp_list_item.tsx b/components/brave_wallet_ui/components/desktop/views/explore_web3/dapp_list_item.tsx index 89d44af4877c..a8ca3ea9e909 100644 --- a/components/brave_wallet_ui/components/desktop/views/explore_web3/dapp_list_item.tsx +++ b/components/brave_wallet_ui/components/desktop/views/explore_web3/dapp_list_item.tsx @@ -40,7 +40,7 @@ export const DappListItem = React.forwardRef< {isHttpsUrl(dapp.logo) ? ( {dapp.name} { > {isHttpsUrl(dapp.logo) ? ( diff --git a/components/brave_wallet_ui/components/shared/buy-option/buy-option-item.tsx b/components/brave_wallet_ui/components/shared/buy-option/buy-option-item.tsx index 14c79cd5312d..e08841a68b35 100644 --- a/components/brave_wallet_ui/components/shared/buy-option/buy-option-item.tsx +++ b/components/brave_wallet_ui/components/shared/buy-option/buy-option-item.tsx @@ -37,7 +37,7 @@ export const BuyOptionItem = (props: Props) => { return ( - + {name} {description} diff --git a/components/brave_wallet_ui/components/shared/create-network-icon/index.tsx b/components/brave_wallet_ui/components/shared/create-network-icon/index.tsx index 3e440c6a4612..8ce93d304669 100644 --- a/components/brave_wallet_ui/components/shared/create-network-icon/index.tsx +++ b/components/brave_wallet_ui/components/shared/create-network-icon/index.tsx @@ -92,7 +92,7 @@ export const CreateNetworkIcon = ({ network, marginRight, size }: Props) => { // complex compute + render const networkIcon = network.iconUrls[0] - const isSandboxUrl = networkIcon?.startsWith('chrome://erc-token-images/') + const isSandboxUrl = networkIcon?.startsWith('chrome://image/') const networkImageURL = isSandboxUrl ? stripERC20TokenImageURL(networkIcon) : networkIcon @@ -124,7 +124,11 @@ export const CreateNetworkIcon = ({ network, marginRight, size }: Props) => { > ) diff --git a/components/brave_wallet_ui/components/shared/create-placeholder-icon/index.tsx b/components/brave_wallet_ui/components/shared/create-placeholder-icon/index.tsx index 8dddf92e3444..c11edc03cd73 100644 --- a/components/brave_wallet_ui/components/shared/create-placeholder-icon/index.tsx +++ b/components/brave_wallet_ui/components/shared/create-placeholder-icon/index.tsx @@ -18,7 +18,6 @@ import { isValidIconExtension, isDataURL, isComponentInStorybook, - stripChromeImageURL } from '../../../utils/string-utils' import { isNativeAsset } from '../../../utils/asset-utils' @@ -118,7 +117,7 @@ export function withPlaceholderIcon< const remoteImage = React.useMemo(() => { if (isRemoteURL) { - return isStorybook ? tokenImageURL || '' : `chrome://image?${encodeURIComponent(tokenImageURL)}` + return isStorybook ? tokenImageURL || '' : `chrome://image?url=${encodeURIComponent(tokenImageURL)}&staticEncode=true` } return '' }, [isRemoteURL, tokenImageURL]) @@ -157,7 +156,7 @@ export function withPlaceholderIcon< {...(wrappedComponentProps as PROPS_FOR_FUNCTION & { icon?: undefined })} - icon={isStorybook ? stripChromeImageURL(tokenImageURL) : icon} + icon={isStorybook ? tokenImageURL : icon} /> ) diff --git a/components/brave_wallet_ui/components/shared/nft-icon/nft-icon.tsx b/components/brave_wallet_ui/components/shared/nft-icon/nft-icon.tsx index 27523ea2f8dd..c70142634883 100644 --- a/components/brave_wallet_ui/components/shared/nft-icon/nft-icon.tsx +++ b/components/brave_wallet_ui/components/shared/nft-icon/nft-icon.tsx @@ -11,7 +11,8 @@ import { skipToken } from '@reduxjs/toolkit/query' import { isComponentInStorybook, isIpfs, - stripERC20TokenImageURL + stripERC20TokenImageURL, + stripChromeImageURL } from '../../../utils/string-utils' // hooks @@ -54,7 +55,9 @@ export const NftIcon = (props: NftIconProps) => { const nftIframeUrl = React.useMemo(() => { const urlParams = new URLSearchParams({ displayMode: 'icon', - icon: encodeURIComponent(remoteImage || '') + // appears to still be broken. Seems this is being used in brave://wallet/crypto/accounts//nfts to display nft images + // seems to be not working because we're trying to load from chrome-untrusted://nft-display frame which might not be allowed even with the CSP set correctly + icon: `chrome://image?url=${encodeURIComponent(remoteImage)}&staticEncode=true&test=8` }) return `chrome-untrusted://nft-display?${urlParams.toString()}` }, [remoteImage]) @@ -97,7 +100,7 @@ export const NftIcon = (props: NftIconProps) => { export const StorybookNftIcon = (props: NftIconProps) => { const { icon, responsive, iconStyles } = props - const tokenImageURL = icon ? stripERC20TokenImageURL(icon) : '' + const tokenImageURL = icon ? stripChromeImageURL(icon) : '' return responsive ? ( { ) : ( {providerImageUrl ? ( - + ) : null} diff --git a/components/brave_wallet_ui/page/screens/fund-wallet/components/select_asset/select_asset.tsx b/components/brave_wallet_ui/page/screens/fund-wallet/components/select_asset/select_asset.tsx index d1a43b7e7168..151a52210bf3 100644 --- a/components/brave_wallet_ui/page/screens/fund-wallet/components/select_asset/select_asset.tsx +++ b/components/brave_wallet_ui/page/screens/fund-wallet/components/select_asset/select_asset.tsx @@ -148,7 +148,7 @@ export const AssetListItem = ({ gap='16px' > - + { {tokensNetwork && ( diff --git a/components/brave_wallet_ui/page/screens/fund-wallet/components/select_currency/select_currency.tsx b/components/brave_wallet_ui/page/screens/fund-wallet/components/select_currency/select_currency.tsx index 946dd5e2bd46..dd1f3b9d61b5 100644 --- a/components/brave_wallet_ui/page/screens/fund-wallet/components/select_currency/select_currency.tsx +++ b/components/brave_wallet_ui/page/screens/fund-wallet/components/select_currency/select_currency.tsx @@ -63,9 +63,9 @@ export const CurrencyListItem = ({ gap='16px' > {currency.name} diff --git a/components/brave_wallet_ui/page/screens/fund-wallet/fund_wallet_v2.tsx b/components/brave_wallet_ui/page/screens/fund-wallet/fund_wallet_v2.tsx index 3fa7b962d8d3..2ee7cc4bb889 100644 --- a/components/brave_wallet_ui/page/screens/fund-wallet/fund_wallet_v2.tsx +++ b/components/brave_wallet_ui/page/screens/fund-wallet/fund_wallet_v2.tsx @@ -245,9 +245,9 @@ export const FundWalletScreen = ({ isAndroid }: Props) => { src={ isStorybook ? logoUrl ?? '' - : `chrome://image?${encodeURIComponent( + : `chrome://image?url=${encodeURIComponent( logoUrl ?? '' - )}` + )}&staticEncode=true` } /> {paymentMethod.name} diff --git a/components/brave_wallet_ui/page/screens/swap/swap.utils.ts b/components/brave_wallet_ui/page/screens/swap/swap.utils.ts index f88ae4ddeb86..46762381f928 100644 --- a/components/brave_wallet_ui/page/screens/swap/swap.utils.ts +++ b/components/brave_wallet_ui/page/screens/swap/swap.utils.ts @@ -410,7 +410,7 @@ export const getLPIcon = (source: Pick) => { return iconFromMetadata } if (source.logo) { - return `chrome://image?${encodeURIComponent(source.logo)}` + return `chrome://image?url=${encodeURIComponent(source.logo)}&staticEncode=true` } return '' }