Skip to content

Commit fce2031

Browse files
authored
feat: validate same origin domain for signin (#434)
If the `domain` is different than `origin` an alert shows tot he user on the confirmation <img width="395" alt="Screenshot 2025-06-27 at 14 47 32" src="https://github.com/user-attachments/assets/4fbcfc3c-35a7-4f08-9043-040bdba65545" /> <img width="400" alt="Screenshot 2025-06-27 at 14 46 44" src="https://github.com/user-attachments/assets/2cbe70a8-c90f-49ec-904d-8952442f0038" />
1 parent 70aa1c5 commit fce2031

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

packages/snap/locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@
250250
"confirmation.signIn.resources": {
251251
"message": "Resources"
252252
},
253+
"confirmation.signIn.badDomain": {
254+
"message": "This site is asking you to sign in using the wrong domain."
255+
},
253256
"transactionScan.errors.accountAlreadyInUse": {
254257
"message": "An account with the same address already exists."
255258
},

packages/snap/messages.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"confirmation.signIn.notBefore": "Not before",
8383
"confirmation.signIn.requestId": "Request ID",
8484
"confirmation.signIn.resources": "Resources",
85+
"confirmation.signIn.badDomain": "This site is asking you to sign in using the wrong domain.",
8586
"transactionScan.errors.accountAlreadyInUse": "An account with the same address already exists.",
8687
"transactionScan.errors.insufficientSol": "Account does not have enough SOL to perform the operation.",
8788
"transactionScan.errors.slippageToleranceExceeded": "The transaction was reverted because the slippage tolerance was exceeded.",

packages/snap/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snap-solana-wallet.git"
88
},
99
"source": {
10-
"shasum": "Lu8ZjslFGAsh8xSiKiOPdzbyxIG8Hrp7h6ijDea9oVo=",
10+
"shasum": "CGJCQcU/gwXmG51oX44op5db6mwEBogWvzfbBJZ26bs=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snap/src/features/confirmation/views/ConfirmSignIn/ConfirmSignIn.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const ConfirmSignIn: SnapComponent<ConfirmSignInProps> = ({
7474
const signInAddressCaip10 = address ? addressToCaip10(scope, address) : null;
7575

7676
const isBadAccount = signInAddressCaip10 !== accountAddressCaip10;
77+
const isBadDomain = domain !== originHostname;
7778

7879
return (
7980
<Container>
@@ -104,7 +105,15 @@ export const ConfirmSignIn: SnapComponent<ConfirmSignInProps> = ({
104105
<Text>{originHostname}</Text>
105106
</Row>
106107
) : null}
107-
<Row label={translate('confirmation.signIn.domain')}>
108+
<Row
109+
variant={isBadDomain ? 'critical' : 'default'}
110+
label={translate('confirmation.signIn.domain')}
111+
tooltip={
112+
isBadDomain
113+
? translate('confirmation.signIn.badDomain')
114+
: undefined
115+
}
116+
>
108117
<Text>
109118
{domain ?? translate('confirmation.signIn.unknownDomain')}
110119
</Text>
@@ -212,7 +221,10 @@ export const ConfirmSignIn: SnapComponent<ConfirmSignInProps> = ({
212221
<Button name={ConfirmSignInFormNames.Cancel}>
213222
{translate('confirmation.cancelButton')}
214223
</Button>
215-
<Button name={ConfirmSignInFormNames.Confirm}>
224+
<Button
225+
name={ConfirmSignInFormNames.Confirm}
226+
variant={isBadDomain ? 'destructive' : 'primary'}
227+
>
216228
{translate('confirmation.confirmButton')}
217229
</Button>
218230
</Footer>

0 commit comments

Comments
 (0)