Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: restrict safe pass safe app access for ofac blocked addresses #4066

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

schmanu
Copy link
Member

@schmanu schmanu commented Aug 13, 2024

What this PR changes

  • Reuses ofac detection for Safe{Pass} Safe app
  • Reject WalletConnect request from Safe{Pass} for sanctioned addresses.

How to test it

  • Impersonate a blocked address
    • Try to open the Safe{Pass} app (community.safe.global)
    • Try to connect via WalletConnect to community.safe.global

Screenshots

Screenshot 2024-08-13 at 17 57 00

Open Task

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

Copy link

github-actions bot commented Aug 13, 2024

Copy link

github-actions bot commented Aug 13, 2024

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

Copy link

github-actions bot commented Aug 13, 2024

📦 Next.js Bundle Analysis for safe-wallet-web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 940.53 KB (🟡 +125 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Three Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/apps/open 56.73 KB (🟡 +1.99 KB) 997.25 KB
/home 60.28 KB (🟡 +25 B) 1000.81 KB
/stake 593 B (🟡 +4 B) 941.11 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

Copy link

github-actions bot commented Aug 13, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
78.27% (+0.02% 🔼)
12003/15336
🔴 Branches
58.17% (-0.03% 🔻)
3068/5274
🟡 Functions
65.35% (-0.03% 🔻)
1892/2895
🟡 Lines
79.77% (+0.02% 🔼)
10833/13581
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / useSanctionedAddress.ts
100% 100% 100% 100%
🔴
... / index.tsx
46.67% 0% 0% 53.85%
🟢
... / index.tsx
62.5% 0% 0% 83.33%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / index.tsx
82.35% (-8.82% 🔻)
66.67% (-16.67% 🔻)
50% (-12.5% 🔻)
83.87% (-9.68% 🔻)
🟡
... / index.tsx
76.25% (+2.28% 🔼)
55.26% (-5.34% 🔻)
40%
76.32% (+2.4% 🔼)

Test suite run success

1490 tests passing in 204 suites.

Report generated by 🧪jest coverage report action from c3a6485

Copy link

Comment on lines +14 to +19
if (isSafeSanctioned) {
return safeAddress
}
if (isWalletSanctioned) {
return wallet?.address
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data contains the error message in case the useGetIsSanctionedQuery throws so I think it would falsely say that an address is sanctioned if the network request fails.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is not true. The error seems to be transformed and returned in the error field of useGetIsSanctionedQuery

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the data assignment on error then inside the ofacApi query?

return { error: { status: 'CUSTOM_ERROR', data: (error as Error).message } }

Copy link

github-actions bot commented Aug 15, 2024

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@schmanu schmanu requested a review from katspaugh August 19, 2024 13:57
@@ -43,6 +45,8 @@ const AppFrame = ({ appUrl, allowedFeaturesList, safeAppFromManifest }: AppFrame
const chainId = useChainId()
const chain = useCurrentChain()
const router = useRouter()
const sanctionedAddress = useSanctionedAddress()
Copy link
Member

@katspaugh katspaugh Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make a request for all apps, not just SAP app.

@@ -43,6 +45,8 @@ const AppFrame = ({ appUrl, allowedFeaturesList, safeAppFromManifest }: AppFrame
const chainId = useChainId()
const chain = useCurrentChain()
const router = useRouter()
const sanctionedAddress = useSanctionedAddress()
const isSafePassApp = appUrl.startsWith('https://community.safe.global')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use isSafePassApp here?

@@ -38,13 +41,22 @@ const WcProposalForm = ({ proposal, setProposal, onApprove }: ProposalFormProps)
const { isScam, origin } = proposal.verifyContext.verified
const url = proposer.metadata.url || origin

const sanctionedAddress = useSanctionedAddress()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this will make a request for any connected dapp.

@@ -50,6 +50,10 @@ export const isBlockedBridge = (origin: string) => {
return BlockedBridges.some((bridge) => origin.includes(bridge))
}

export const isSafePassApp = (origin: string) => {
return origin.includes('community.safe.global')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we if not avoid hardcode then at least make it a constant?

@katspaugh
Copy link
Member

I think checking blocked addresses from within apps/open and WalletConnect is a bit excessive. It would be better if we just hide all links to this app, and inside the app itself check for blocked addresses (would have to port that hook there).

@schmanu
Copy link
Member Author

schmanu commented Aug 19, 2024

I think checking blocked addresses from within apps/open and WalletConnect is a bit excessive. It would be better if we just hide all links to this app, and inside the app itself check for blocked addresses (would have to port that hook there).

You cannot receive the connected wallet within the Safe app. We only get the safeAddress. That's why the check is within Safe{Wallet}.

@katspaugh
Copy link
Member

Geoblocking is now in place, so it would be good to hide the header widget if the app cannot be loaded.

Copy link

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants