Skip to content

Commit

Permalink
Fix address validation in row component (#2257)
Browse files Browse the repository at this point in the history
Fixes address validation in the address row component. Before this
change the regex was flawed and would allow addresses longer than 42
characters.

---------

Co-authored-by: MetaMask Bot <[email protected]>
  • Loading branch information
FrederikBolding and metamaskbot authored Mar 8, 2024
1 parent 43d8903 commit 8b461ef
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/examples/packages/bip32/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "DtqCkGevlAXjYPpejmh0PW3OXNVm4zYi/PHYVu1U+is=",
"shasum": "6g87K+NnEehFnghqk0s8wWv6NnGkeaAAOq+eemGJndQ=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/bip44/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "lzjiI94y3QWSHvxvwWPJ3QiLoVpRoDK9aI0KfiFGaO0=",
"shasum": "h9Unyy6nfIB+2Dri5Hn6fNMJEtEu6e4lmoBRk7SqGqY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/cronjobs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "+RV6eu1bUJwI64Ia+87nzVt7w5hEvGG+DjvWRd1ds3E=",
"shasum": "hXFQrGOJ+ScAdetboaVpVTv9jHS9ZbeGTSF6jQ8P8yM=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/dialogs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "HrY2Q07bwZLKbP7UYbLU2fVMVMjGWgwhmlTGUgEQNMo=",
"shasum": "N2zhh1oUTEL5T4B+XYJz46f5ip9YEa9vTVnteSz8CC4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/ethers-js/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "75eFrFWMaWVoN+SB0Dx6zuMuW6wkW9TAyfTJ2pmkXxU=",
"shasum": "D/6w/eOgde9NmCfVoCnwLGDZSihAK7UNMHoj7llQKSU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/get-entropy/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "Bk/N5TeC923rK569D6o7eEusaTZ4ENeqakMXPcAR/tY=",
"shasum": "CrlL6w+qKhC0Zonm8KGeAHz4crnegl5IyAUBWMtobIo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/home-page/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "g97yy0ykpflNFVzBfFablH4DsLNr+eZKCEoDbLQpmgY=",
"shasum": "tO3oJ/EasOvT1aoAsoOgxbDQZFI+6ol6Mh1NpACGYFI=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/images/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "AI+NqKyNjL6pvJv2CapYwFbHSm9EoTINoXl/ZLnZP0E=",
"shasum": "j6DESLoBQHNUMM0XD2dLJ6vj/s/icJNw/5bFaHSB950=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "PPCmPNzFzjg4596Rs/LnTuHAaJq3oAqv+XMSjpTjq0w=",
"shasum": "59cpZd9t58yrxzku0e1XEEnX2UB/zOG3rraPcADBs3Y=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "Af0qYFlaZB9ublbw/EdKs/zKfWsSXAG2Mi/XTRmAHOU=",
"shasum": "2BJWlCMx68q5XYjLG9Huixag1V4Uyrl+JeGcYN/6r9Y=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "DSVf2LLECYZqXVe8EInjs5uZ7Ey+UA/ANfbe+XYlCOs=",
"shasum": "AJ2WrMJafmZcGcKwcRvDHKD/lzwUuBiGbpXWW9HCRvo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/manage-state/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "D1RxlgTDi5cCPn6Cf2hO2WzvBnn56ipuSGf6Z96HhIE=",
"shasum": "eEGWFgMCsUE2ExTUxL1tT47fpYVXltudfQ2cfeeSB/Q=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "HcZ87SrdWWI7kPX5pId8h8wNMgltlMXqXjGnG+7nN8k=",
"shasum": "tW8C+DzAdDnN1qryrtDErAgIsm76cMlgs5TI9MUH/R0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "yisG8u7h5r9IBpGfapBj8RM2wr5YQh5QA/3cjrBCklU=",
"shasum": "4o53LPuk/bQ5liPZOgvkRjo8qMQhIMRD/hVwRFUfzrA=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "sV8xD5zSmYjW5L6L0cY7kZS3UyzlScEyk13lSkYCRhA=",
"shasum": "x5KDoChPS3pUwoYmOi94B0/OzB9EuXK7YH1MQVYCLC0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
9 changes: 8 additions & 1 deletion packages/snaps-sdk/src/ui/components/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ describe('address', () => {
});

it('validates the args', () => {
// @ts-expect-error - Invalid args.
expect(() => address({ value: 'foo' })).toThrow(
'Invalid address component: At path: value -- Expected a string matching `/0x[a-fA-F0-9]{40}/` but received "foo"',
'Invalid address component: At path: value -- Expected a string matching `/^0x[0-9a-fA-F]{40}$/` but received "foo"',
);

expect(() =>
address({ value: '0x4bbeEB066eD09B7AEd07bF39EEe0460DFa2615200' }),
).toThrow(
'Invalid address component: At path: value -- Expected a string matching `/^0x[0-9a-fA-F]{40}$/` but received "0x4bbeEB066eD09B7AEd07bF39EEe0460DFa2615200"',
);

// @ts-expect-error - Invalid args.
Expand Down
5 changes: 3 additions & 2 deletions packages/snaps-sdk/src/ui/components/address.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HexChecksumAddressStruct } from '@metamask/utils';
import type { Infer } from 'superstruct';
import { assign, literal, object, pattern, string } from 'superstruct';
import { assign, literal, object } from 'superstruct';

import { createBuilder } from '../builder';
import { LiteralStruct, NodeType } from '../nodes';
Expand All @@ -8,7 +9,7 @@ export const AddressStruct = assign(
LiteralStruct,
object({
type: literal(NodeType.Address),
value: pattern(string(), /0x[a-fA-F0-9]{40}/u),
value: HexChecksumAddressStruct,
}),
);

Expand Down

0 comments on commit 8b461ef

Please sign in to comment.