-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into getWeiHexFromDecimalValue-error
- Loading branch information
Showing
32 changed files
with
1,051 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ListNames, PhishingController } from '@metamask/phishing-controller'; | ||
import { isBlockedUrl } from './isBlockedUrl'; | ||
|
||
describe('isBlockedUrl', () => { | ||
const phishingController = new PhishingController( | ||
{}, | ||
{ | ||
phishingLists: [ | ||
{ | ||
blocklist: ['https://metamask.test'], | ||
allowlist: [], | ||
fuzzylist: [], | ||
tolerance: 0, | ||
version: 1, | ||
lastUpdated: 0, | ||
name: ListNames.MetaMask, | ||
}, | ||
], | ||
}, | ||
); | ||
|
||
it.each([ | ||
['http://metamask.io', false], | ||
['https://metamask.io', false], | ||
['https://metamask.test', true], | ||
['sftp://metamask.io', true], | ||
['', true], | ||
['1', true], | ||
[undefined, true], | ||
[null, true], | ||
[1, true], | ||
[0, true], | ||
[-1, true], | ||
])('"%s" is blocked: %s', async (url: any, expected: boolean) => { | ||
const result = await isBlockedUrl(url, phishingController); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { PhishingController } from '@metamask/phishing-controller'; | ||
import { isProtocolAllowed } from '../../keyring-snaps-permissions'; | ||
|
||
/** | ||
* Checks whether a given URL is blocked due to not using HTTPS or being | ||
* recognized as a phishing URL. | ||
* | ||
* @param url - The URL to check. | ||
* @param phishingController - An instance of PhishingController to verify | ||
* against known phishing URLs. | ||
* @returns Returns a promise which resolves to `true` if the URL is blocked | ||
* either due to using an insecure protocol (not HTTPS) or being recognized as | ||
* a phishing URL. Otherwise, resolves to `false`. | ||
*/ | ||
export const isBlockedUrl = async ( | ||
url: string, | ||
phishingController: PhishingController, | ||
): Promise<boolean> => { | ||
try { | ||
// check if the URL is HTTPS | ||
if (!isProtocolAllowed(url)) { | ||
return true; | ||
} | ||
|
||
// check if the url is in the phishing list | ||
await phishingController.maybeUpdateState(); | ||
return phishingController.test(url).result; | ||
} catch (error) { | ||
console.error('Invalid URL passed into snap-keyring:', error); | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.