@metamask-previews/phishing-controller 12.4.0-preview-4fbfa93f → 12.4.0-preview-b08aa8e7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/PhishingController.cjs +4 -1
- package/dist/PhishingController.cjs.map +1 -1
- package/dist/PhishingController.d.cts.map +1 -1
- package/dist/PhishingController.d.mts.map +1 -1
- package/dist/PhishingController.mjs +4 -1
- package/dist/PhishingController.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Fixed an edge case in `PhishingController` where empty phishing lists could trigger API requests with invalid `-Infinity` timestamps ([#5385](https://github.com/MetaMask/core/pull/5385))
|
|
13
|
+
|
|
10
14
|
## [12.4.0]
|
|
11
15
|
|
|
12
16
|
### Added
|
|
@@ -434,9 +434,12 @@ async function _PhishingController_updateStalelist() {
|
|
|
434
434
|
* this function that prevents redundant configuration updates.
|
|
435
435
|
*/
|
|
436
436
|
async function _PhishingController_updateHotlist() {
|
|
437
|
-
const lastDiffTimestamp = Math.max(...this.state.phishingLists.map(({ lastUpdated }) => lastUpdated));
|
|
438
437
|
let hotlistResponse;
|
|
439
438
|
try {
|
|
439
|
+
if (this.state.phishingLists.length === 0) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const lastDiffTimestamp = Math.max(...this.state.phishingLists.map(({ lastUpdated }) => lastUpdated));
|
|
440
443
|
hotlistResponse = await __classPrivateFieldGet(this, _PhishingController_instances, "m", _PhishingController_queryConfig).call(this, `${exports.METAMASK_HOTLIST_DIFF_URL}/${lastDiffTimestamp}`);
|
|
441
444
|
}
|
|
442
445
|
finally {
|
|
@@ -1 +1 @@
|
|
|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I,EAAE,CAAC;SAC9B;QAED,OAAO,CAAC,CAAC;YACP,OAAO,IAAI,CAAC;SACb;KACF;AACH,CAAC;AAGH,kBAAe,kBAAkB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport {\n safelyExecute,\n safelyExecuteWithTimeout,\n} from '@metamask/controller-utils';\nimport { toASCII } from 'punycode/punycode.js';\n\nimport { PhishingDetector } from './PhishingDetector';\nimport {\n PhishingDetectorResultType,\n type PhishingDetectorResult,\n type PhishingDetectionScanResult,\n RecommendedAction,\n} from './types';\nimport {\n applyDiffs,\n fetchTimeNow,\n getHostnameFromUrl,\n roundToNearestMinute,\n getHostnameFromWebUrl,\n} from './utils';\n\nexport const PHISHING_CONFIG_BASE_URL =\n 'https://phishing-detection.api.cx.metamask.io';\nexport const METAMASK_STALELIST_FILE = '/v1/stalelist';\nexport const METAMASK_HOTLIST_DIFF_FILE = '/v1/diffsSince';\n\nexport const CLIENT_SIDE_DETECION_BASE_URL =\n 'https://client-side-detection.api.cx.metamask.io';\nexport const C2_DOMAIN_BLOCKLIST_ENDPOINT = '/v1/request-blocklist';\n\nexport const PHISHING_DETECTION_BASE_URL =\n 'https://dapp-scanning.api.cx.metamask.io';\nexport const PHISHING_DETECTION_SCAN_ENDPOINT = 'scan';\n\nexport const C2_DOMAIN_BLOCKLIST_REFRESH_INTERVAL = 5 * 60; // 5 mins in seconds\nexport const HOTLIST_REFRESH_INTERVAL = 5 * 60; // 5 mins in seconds\nexport const STALELIST_REFRESH_INTERVAL = 30 * 24 * 60 * 60; // 30 days in seconds\n\nexport const METAMASK_STALELIST_URL = `${PHISHING_CONFIG_BASE_URL}${METAMASK_STALELIST_FILE}`;\nexport const METAMASK_HOTLIST_DIFF_URL = `${PHISHING_CONFIG_BASE_URL}${METAMASK_HOTLIST_DIFF_FILE}`;\nexport const C2_DOMAIN_BLOCKLIST_URL = `${CLIENT_SIDE_DETECION_BASE_URL}${C2_DOMAIN_BLOCKLIST_ENDPOINT}`;\n\n/**\n * @type ListTypes\n *\n * Type outlining the types of lists provided by aggregating different source lists\n */\nexport type ListTypes =\n | 'fuzzylist'\n | 'blocklist'\n | 'allowlist'\n | 'c2DomainBlocklist';\n\n/**\n * @type EthPhishingResponse\n *\n * Configuration response from the eth-phishing-detect package\n * consisting of approved and unapproved website origins\n * @property blacklist - List of unapproved origins\n * @property fuzzylist - List of fuzzy-matched unapproved origins\n * @property tolerance - Fuzzy match tolerance level\n * @property version - Version number of this configuration\n * @property whitelist - List of approved origins\n */\nexport type EthPhishingResponse = {\n blacklist: string[];\n fuzzylist: string[];\n tolerance: number;\n version: number;\n whitelist: string[];\n};\n\n/**\n * @type C2DomainBlocklistResponse\n *\n * Response for blocklist update requests\n * @property recentlyAdded - List of c2 domains recently added to the blocklist\n * @property recentlyRemoved - List of c2 domains recently removed from the blocklist\n * @property lastFetchedAt - Timestamp of the last fetch request\n */\nexport type C2DomainBlocklistResponse = {\n recentlyAdded: string[];\n recentlyRemoved: string[];\n lastFetchedAt: string;\n};\n\n/**\n * @type PhishingStalelist\n *\n * type defining expected type of the stalelist.json file.\n * @property eth_phishing_detect_config - Stale list sourced from eth-phishing-detect's config.json.\n * @property tolerance - Fuzzy match tolerance level\n * @property lastUpdated - Timestamp of last update.\n * @property version - Stalelist data structure iteration.\n */\nexport type PhishingStalelist = {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n eth_phishing_detect_config: Record<ListTypes, string[]>;\n tolerance: number;\n version: number;\n lastUpdated: number;\n};\n\n/**\n * @type PhishingListState\n *\n * type defining the persisted list state. This is the persisted state that is updated frequently with `this.maybeUpdateState()`.\n * @property allowlist - List of approved origins (legacy naming \"whitelist\")\n * @property blocklist - List of unapproved origins (legacy naming \"blacklist\")\n * @property c2DomainBlocklist - List of hashed hostnames that C2 requests are blocked against.\n * @property fuzzylist - List of fuzzy-matched unapproved origins\n * @property tolerance - Fuzzy match tolerance level\n * @property lastUpdated - Timestamp of last update.\n * @property version - Version of the phishing list state.\n * @property name - Name of the list. Used for attribution.\n */\nexport type PhishingListState = {\n allowlist: string[];\n blocklist: string[];\n c2DomainBlocklist: string[];\n fuzzylist: string[];\n tolerance: number;\n version: number;\n lastUpdated: number;\n name: ListNames;\n};\n\n/**\n * @type HotlistDiff\n *\n * type defining the expected type of the diffs in hotlist.json file.\n * @property url - Url of the diff entry.\n * @property timestamp - Timestamp at which the diff was identified.\n * @property targetList - The list name where the diff was identified.\n * @property isRemoval - Was the diff identified a removal type.\n */\nexport type HotlistDiff = {\n url: string;\n timestamp: number;\n targetList: `${ListKeys}.${ListTypes}`;\n isRemoval?: boolean;\n};\n\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type DataResultWrapper<T> = {\n data: T;\n};\n\n/**\n * @type Hotlist\n *\n * Type defining expected hotlist.json file.\n * @property url - Url of the diff entry.\n * @property timestamp - Timestamp at which the diff was identified.\n * @property targetList - The list name where the diff was identified.\n * @property isRemoval - Was the diff identified a removal type.\n */\nexport type Hotlist = HotlistDiff[];\n\n/**\n * Enum containing upstream data provider source list keys.\n * These are the keys denoting lists consumed by the upstream data provider.\n */\nexport enum ListKeys {\n EthPhishingDetectConfig = 'eth_phishing_detect_config',\n}\n\n/**\n * Enum containing downstream client attribution names.\n */\nexport enum ListNames {\n MetaMask = 'MetaMask',\n}\n\n/**\n * Maps from downstream client attribution name\n * to list key sourced from upstream data provider.\n */\nconst phishingListNameKeyMap = {\n [ListNames.MetaMask]: ListKeys.EthPhishingDetectConfig,\n};\n\n/**\n * Maps from list key sourced from upstream data\n * provider to downstream client attribution name.\n */\nexport const phishingListKeyNameMap = {\n [ListKeys.EthPhishingDetectConfig]: ListNames.MetaMask,\n};\n\nconst controllerName = 'PhishingController';\n\nconst metadata = {\n phishingLists: { persist: true, anonymous: false },\n whitelist: { persist: true, anonymous: false },\n hotlistLastFetched: { persist: true, anonymous: false },\n stalelistLastFetched: { persist: true, anonymous: false },\n c2DomainBlocklistLastFetched: { persist: true, anonymous: false },\n};\n\n/**\n * Get a default empty state for the controller.\n * @returns The default empty state.\n */\nconst getDefaultState = (): PhishingControllerState => {\n return {\n phishingLists: [],\n whitelist: [],\n hotlistLastFetched: 0,\n stalelistLastFetched: 0,\n c2DomainBlocklistLastFetched: 0,\n };\n};\n\n/**\n * @type PhishingControllerState\n *\n * Phishing controller state\n * @property phishing - eth-phishing-detect configuration\n * @property whitelist - array of temporarily-approved origins\n */\nexport type PhishingControllerState = {\n phishingLists: PhishingListState[];\n whitelist: string[];\n hotlistLastFetched: number;\n stalelistLastFetched: number;\n c2DomainBlocklistLastFetched: number;\n};\n\n/**\n * @type PhishingControllerOptions\n *\n * Phishing controller options\n * @property stalelistRefreshInterval - Polling interval used to fetch stale list.\n * @property hotlistRefreshInterval - Polling interval used to fetch hotlist diff list.\n * @property c2DomainBlocklistRefreshInterval - Polling interval used to fetch c2 domain blocklist.\n */\nexport type PhishingControllerOptions = {\n stalelistRefreshInterval?: number;\n hotlistRefreshInterval?: number;\n c2DomainBlocklistRefreshInterval?: number;\n messenger: PhishingControllerMessenger;\n state?: Partial<PhishingControllerState>;\n};\n\nexport type MaybeUpdateState = {\n type: `${typeof controllerName}:maybeUpdateState`;\n handler: PhishingController['maybeUpdateState'];\n};\n\nexport type TestOrigin = {\n type: `${typeof controllerName}:testOrigin`;\n handler: PhishingController['test'];\n};\n\nexport type PhishingControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n PhishingControllerState\n>;\n\nexport type PhishingControllerActions =\n | PhishingControllerGetStateAction\n | MaybeUpdateState\n | TestOrigin;\n\nexport type PhishingControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n PhishingControllerState\n>;\n\nexport type PhishingControllerEvents = PhishingControllerStateChangeEvent;\n\nexport type PhishingControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n PhishingControllerActions,\n PhishingControllerEvents,\n never,\n never\n>;\n\n/**\n * Controller that manages community-maintained lists of approved and unapproved website origins.\n */\nexport class PhishingController extends BaseController<\n typeof controllerName,\n PhishingControllerState,\n PhishingControllerMessenger\n> {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #detector: any;\n\n #stalelistRefreshInterval: number;\n\n #hotlistRefreshInterval: number;\n\n #c2DomainBlocklistRefreshInterval: number;\n\n #inProgressHotlistUpdate?: Promise<void>;\n\n #inProgressStalelistUpdate?: Promise<void>;\n\n #isProgressC2DomainBlocklistUpdate?: Promise<void>;\n\n /**\n * Construct a Phishing Controller.\n *\n * @param config - Initial options used to configure this controller.\n * @param config.stalelistRefreshInterval - Polling interval used to fetch stale list.\n * @param config.hotlistRefreshInterval - Polling interval used to fetch hotlist diff list.\n * @param config.c2DomainBlocklistRefreshInterval - Polling interval used to fetch c2 domain blocklist.\n * @param config.messenger - The controller restricted messenger.\n * @param config.state - Initial state to set on this controller.\n */\n constructor({\n stalelistRefreshInterval = STALELIST_REFRESH_INTERVAL,\n hotlistRefreshInterval = HOTLIST_REFRESH_INTERVAL,\n c2DomainBlocklistRefreshInterval = C2_DOMAIN_BLOCKLIST_REFRESH_INTERVAL,\n messenger,\n state = {},\n }: PhishingControllerOptions) {\n super({\n name: controllerName,\n metadata,\n messenger,\n state: {\n ...getDefaultState(),\n ...state,\n },\n });\n\n this.#stalelistRefreshInterval = stalelistRefreshInterval;\n this.#hotlistRefreshInterval = hotlistRefreshInterval;\n this.#c2DomainBlocklistRefreshInterval = c2DomainBlocklistRefreshInterval;\n this.#registerMessageHandlers();\n\n this.updatePhishingDetector();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:maybeUpdateState` as const,\n this.maybeUpdateState.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:testOrigin` as const,\n this.test.bind(this),\n );\n }\n\n /**\n * Updates this.detector with an instance of PhishingDetector using the current state.\n */\n updatePhishingDetector() {\n this.#detector = new PhishingDetector(this.state.phishingLists);\n }\n\n /**\n * Set the interval at which the stale phishing list will be refetched.\n * Fetching will only occur on the next call to test/bypass.\n * For immediate update to the phishing list, call {@link updateStalelist} directly.\n *\n * @param interval - the new interval, in ms.\n */\n setStalelistRefreshInterval(interval: number) {\n this.#stalelistRefreshInterval = interval;\n }\n\n /**\n * Set the interval at which the hot list will be refetched.\n * Fetching will only occur on the next call to test/bypass.\n * For immediate update to the phishing list, call {@link updateHotlist} directly.\n *\n * @param interval - the new interval, in ms.\n */\n setHotlistRefreshInterval(interval: number) {\n this.#hotlistRefreshInterval = interval;\n }\n\n /**\n * Set the interval at which the C2 domain blocklist will be refetched.\n * Fetching will only occur on the next call to test/bypass.\n * For immediate update to the phishing list, call {@link updateHotlist} directly.\n *\n * @param interval - the new interval, in ms.\n */\n setC2DomainBlocklistRefreshInterval(interval: number) {\n this.#c2DomainBlocklistRefreshInterval = interval;\n }\n\n /**\n * Determine if an update to the stalelist configuration is needed.\n *\n * @returns Whether an update is needed\n */\n isStalelistOutOfDate() {\n return (\n fetchTimeNow() - this.state.stalelistLastFetched >=\n this.#stalelistRefreshInterval\n );\n }\n\n /**\n * Determine if an update to the hotlist configuration is needed.\n *\n * @returns Whether an update is needed\n */\n isHotlistOutOfDate() {\n return (\n fetchTimeNow() - this.state.hotlistLastFetched >=\n this.#hotlistRefreshInterval\n );\n }\n\n /**\n * Determine if an update to the C2 domain blocklist is needed.\n *\n * @returns Whether an update is needed\n */\n isC2DomainBlocklistOutOfDate() {\n return (\n fetchTimeNow() - this.state.c2DomainBlocklistLastFetched >=\n this.#c2DomainBlocklistRefreshInterval\n );\n }\n\n /**\n * Conditionally update the phishing configuration.\n *\n * If the stalelist configuration is out of date, this function will call `updateStalelist`\n * to update the configuration. This will automatically grab the hotlist,\n * so it isn't necessary to continue on to download the hotlist and the c2 domain blocklist.\n *\n */\n async maybeUpdateState() {\n const staleListOutOfDate = this.isStalelistOutOfDate();\n if (staleListOutOfDate) {\n await this.updateStalelist();\n return;\n }\n const hotlistOutOfDate = this.isHotlistOutOfDate();\n if (hotlistOutOfDate) {\n await this.updateHotlist();\n }\n const c2DomainBlocklistOutOfDate = this.isC2DomainBlocklistOutOfDate();\n if (c2DomainBlocklistOutOfDate) {\n await this.updateC2DomainBlocklist();\n }\n }\n\n /**\n * Determines if a given origin is unapproved.\n *\n * It is strongly recommended that you call {@link maybeUpdateState} before calling this,\n * to check whether the phishing configuration is up-to-date. It will be updated if necessary\n * by calling {@link updateStalelist} or {@link updateHotlist}.\n *\n * @param origin - Domain origin of a website.\n * @returns Whether the origin is an unapproved origin.\n */\n test(origin: string): PhishingDetectorResult {\n const punycodeOrigin = toASCII(origin);\n const hostname = getHostnameFromUrl(punycodeOrigin);\n if (this.state.whitelist.includes(hostname || punycodeOrigin)) {\n return { result: false, type: PhishingDetectorResultType.All }; // Same as whitelisted match returned by detector.check(...).\n }\n return this.#detector.check(punycodeOrigin);\n }\n\n /**\n * Checks if a request URL's domain is blocked against the request blocklist.\n *\n * This method is used to determine if a specific request URL is associated with a malicious\n * command and control (C2) domain. The URL's hostname is hashed and checked against a configured\n * blocklist of known malicious domains.\n *\n * @param origin - The full request URL to be checked.\n * @returns An object indicating whether the URL's domain is blocked and relevant metadata.\n */\n isBlockedRequest(origin: string): PhishingDetectorResult {\n const punycodeOrigin = toASCII(origin);\n const hostname = getHostnameFromUrl(punycodeOrigin);\n if (this.state.whitelist.includes(hostname || punycodeOrigin)) {\n return { result: false, type: PhishingDetectorResultType.All }; // Same as whitelisted match returned by detector.check(...).\n }\n return this.#detector.isMaliciousC2Domain(punycodeOrigin);\n }\n\n /**\n * Temporarily marks a given origin as approved.\n *\n * @param origin - The origin to mark as approved.\n */\n bypass(origin: string) {\n const punycodeOrigin = toASCII(origin);\n const hostname = getHostnameFromUrl(punycodeOrigin);\n const { whitelist } = this.state;\n if (whitelist.includes(hostname || punycodeOrigin)) {\n return;\n }\n this.update((draftState) => {\n draftState.whitelist.push(hostname || punycodeOrigin);\n });\n }\n\n /**\n * Update the C2 domain blocklist.\n *\n * If an update is in progress, no additional update will be made. Instead this will wait until\n * the in-progress update has finished.\n */\n async updateC2DomainBlocklist() {\n if (this.#isProgressC2DomainBlocklistUpdate) {\n await this.#isProgressC2DomainBlocklistUpdate;\n return;\n }\n\n try {\n this.#isProgressC2DomainBlocklistUpdate = this.#updateC2DomainBlocklist();\n await this.#isProgressC2DomainBlocklistUpdate;\n } finally {\n this.#isProgressC2DomainBlocklistUpdate = undefined;\n }\n }\n\n /**\n * Update the hotlist.\n *\n * If an update is in progress, no additional update will be made. Instead this will wait until\n * the in-progress update has finished.\n */\n async updateHotlist() {\n if (this.#inProgressHotlistUpdate) {\n await this.#inProgressHotlistUpdate;\n return;\n }\n\n try {\n this.#inProgressHotlistUpdate = this.#updateHotlist();\n await this.#inProgressHotlistUpdate;\n } finally {\n this.#inProgressHotlistUpdate = undefined;\n }\n }\n\n /**\n * Update the stalelist.\n *\n * If an update is in progress, no additional update will be made. Instead this will wait until\n * the in-progress update has finished.\n */\n async updateStalelist() {\n if (this.#inProgressStalelistUpdate) {\n await this.#inProgressStalelistUpdate;\n return;\n }\n\n try {\n this.#inProgressStalelistUpdate = this.#updateStalelist();\n await this.#inProgressStalelistUpdate;\n } finally {\n this.#inProgressStalelistUpdate = undefined;\n }\n }\n\n /**\n * Scan a URL for phishing. It will only scan the hostname of the URL. It also only supports\n * web URLs.\n *\n * @param url - The URL to scan.\n * @returns The phishing detection scan result.\n */\n scanUrl = async (url: string): Promise<PhishingDetectionScanResult> => {\n const [hostname, ok] = getHostnameFromWebUrl(url);\n if (!ok) {\n return {\n domainName: '',\n recommendedAction: RecommendedAction.None,\n fetchError: 'url is not a valid web URL',\n };\n }\n\n const apiResponse = await safelyExecuteWithTimeout(\n async () => {\n const res = await fetch(\n `${PHISHING_DETECTION_BASE_URL}/${PHISHING_DETECTION_SCAN_ENDPOINT}?url=${encodeURIComponent(hostname)}`,\n {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n },\n );\n if (!res.ok) {\n return {\n error: `${res.status} ${res.statusText}`,\n };\n }\n const data = await res.json();\n return data;\n },\n true,\n 8000,\n );\n\n // Need to do it this way because safelyExecuteWithTimeout returns undefined for both timeouts and errors.\n if (!apiResponse) {\n return {\n domainName: '',\n recommendedAction: RecommendedAction.None,\n fetchError: 'timeout of 8000ms exceeded',\n };\n } else if ('error' in apiResponse) {\n return {\n domainName: '',\n recommendedAction: RecommendedAction.None,\n fetchError: apiResponse.error,\n };\n }\n\n return {\n domainName: hostname,\n recommendedAction: apiResponse.recommendedAction,\n } as PhishingDetectionScanResult;\n };\n\n /**\n * Update the stalelist configuration.\n *\n * This should only be called from the `updateStalelist` function, which is a wrapper around\n * this function that prevents redundant configuration updates.\n */\n async #updateStalelist() {\n let stalelistResponse: DataResultWrapper<PhishingStalelist> | null = null;\n let hotlistDiffsResponse: DataResultWrapper<Hotlist> | null = null;\n let c2DomainBlocklistResponse: C2DomainBlocklistResponse | null = null;\n try {\n const stalelistPromise = this.#queryConfig<\n DataResultWrapper<PhishingStalelist>\n >(METAMASK_STALELIST_URL);\n\n const c2DomainBlocklistPromise =\n this.#queryConfig<C2DomainBlocklistResponse>(C2_DOMAIN_BLOCKLIST_URL);\n\n [stalelistResponse, c2DomainBlocklistResponse] = await Promise.all([\n stalelistPromise,\n c2DomainBlocklistPromise,\n ]);\n // Fetching hotlist diffs relies on having a lastUpdated timestamp to do `GET /v1/diffsSince/:timestamp`,\n // so it doesn't make sense to call if there is not a timestamp to begin with.\n if (stalelistResponse?.data && stalelistResponse.data.lastUpdated > 0) {\n hotlistDiffsResponse = await this.#queryConfig<\n DataResultWrapper<Hotlist>\n >(`${METAMASK_HOTLIST_DIFF_URL}/${stalelistResponse.data.lastUpdated}`);\n }\n } finally {\n // Set `stalelistLastFetched` and `hotlistLastFetched` even for failed requests to prevent server\n // from being overwhelmed with traffic after a network disruption.\n const timeNow = fetchTimeNow();\n this.update((draftState) => {\n draftState.stalelistLastFetched = timeNow;\n draftState.hotlistLastFetched = timeNow;\n draftState.c2DomainBlocklistLastFetched = timeNow;\n });\n }\n\n if (!stalelistResponse || !hotlistDiffsResponse) {\n return;\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const { eth_phishing_detect_config, ...partialState } =\n stalelistResponse.data;\n\n const metamaskListState: PhishingListState = {\n ...eth_phishing_detect_config,\n ...partialState,\n c2DomainBlocklist: c2DomainBlocklistResponse\n ? c2DomainBlocklistResponse.recentlyAdded\n : [],\n name: phishingListKeyNameMap.eth_phishing_detect_config,\n };\n\n const newMetaMaskListState: PhishingListState = applyDiffs(\n metamaskListState,\n hotlistDiffsResponse.data,\n ListKeys.EthPhishingDetectConfig,\n );\n\n this.update((draftState) => {\n draftState.phishingLists = [newMetaMaskListState];\n });\n this.updatePhishingDetector();\n }\n\n /**\n * Update the stalelist configuration.\n *\n * This should only be called from the `updateStalelist` function, which is a wrapper around\n * this function that prevents redundant configuration updates.\n */\n async #updateHotlist() {\n const lastDiffTimestamp = Math.max(\n ...this.state.phishingLists.map(({ lastUpdated }) => lastUpdated),\n );\n let hotlistResponse: DataResultWrapper<Hotlist> | null;\n\n try {\n hotlistResponse = await this.#queryConfig<DataResultWrapper<Hotlist>>(\n `${METAMASK_HOTLIST_DIFF_URL}/${lastDiffTimestamp}`,\n );\n } finally {\n // Set `hotlistLastFetched` even for failed requests to prevent server from being overwhelmed with\n // traffic after a network disruption.\n this.update((draftState) => {\n draftState.hotlistLastFetched = fetchTimeNow();\n });\n }\n\n if (!hotlistResponse?.data) {\n return;\n }\n const hotlist = hotlistResponse.data;\n const newPhishingLists = this.state.phishingLists.map((phishingList) => {\n const updatedList = applyDiffs(\n phishingList,\n hotlist,\n phishingListNameKeyMap[phishingList.name],\n [],\n [],\n );\n\n return updatedList;\n });\n\n this.update((draftState) => {\n draftState.phishingLists = newPhishingLists;\n });\n this.updatePhishingDetector();\n }\n\n /**\n * Update the C2 domain blocklist.\n *\n * This should only be called from the `updateC2DomainBlocklist` function, which is a wrapper around\n * this function that prevents redundant configuration updates.\n */\n async #updateC2DomainBlocklist() {\n let c2DomainBlocklistResponse: C2DomainBlocklistResponse | null = null;\n\n try {\n c2DomainBlocklistResponse =\n await this.#queryConfig<C2DomainBlocklistResponse>(\n `${C2_DOMAIN_BLOCKLIST_URL}?timestamp=${roundToNearestMinute(\n this.state.c2DomainBlocklistLastFetched,\n )}`,\n );\n } finally {\n // Set `c2DomainBlocklistLastFetched` even for failed requests to prevent server from being overwhelmed with\n // traffic after a network disruption.\n this.update((draftState) => {\n draftState.c2DomainBlocklistLastFetched = fetchTimeNow();\n });\n }\n\n if (!c2DomainBlocklistResponse) {\n return;\n }\n\n const recentlyAddedC2Domains = c2DomainBlocklistResponse.recentlyAdded;\n const recentlyRemovedC2Domains = c2DomainBlocklistResponse.recentlyRemoved;\n\n const newPhishingLists = this.state.phishingLists.map((phishingList) => {\n const updatedList = applyDiffs(\n phishingList,\n [],\n phishingListNameKeyMap[phishingList.name],\n recentlyAddedC2Domains,\n recentlyRemovedC2Domains,\n );\n\n return updatedList;\n });\n\n this.update((draftState) => {\n draftState.phishingLists = newPhishingLists;\n });\n this.updatePhishingDetector();\n }\n\n async #queryConfig<ResponseType>(\n input: RequestInfo,\n ): Promise<ResponseType | null> {\n const response = await safelyExecute(\n () => fetch(input, { cache: 'no-cache' }),\n true,\n );\n\n switch (response?.status) {\n case 200: {\n return await response.json();\n }\n\n default: {\n return null;\n }\n }\n }\n}\n\nexport default PhishingController;\n\nexport type { PhishingDetectorResult };\n"]}
|
|
1
|
+
{"version":3,"file":"PhishingController.cjs","sourceRoot":"","sources":["../src/PhishingController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAC3D,iEAGoC;AACpC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AAC;YACP,OAAO,IAAI,CAAC;SACb;KACF;AACH,CAAC;AAGH,kBAAe,kBAAkB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport {\n safelyExecute,\n safelyExecuteWithTimeout,\n} from '@metamask/controller-utils';\nimport { toASCII } from 'punycode/punycode.js';\n\nimport { PhishingDetector } from './PhishingDetector';\nimport {\n PhishingDetectorResultType,\n type PhishingDetectorResult,\n type PhishingDetectionScanResult,\n RecommendedAction,\n} from './types';\nimport {\n applyDiffs,\n fetchTimeNow,\n getHostnameFromUrl,\n roundToNearestMinute,\n getHostnameFromWebUrl,\n} from './utils';\n\nexport const PHISHING_CONFIG_BASE_URL =\n 'https://phishing-detection.api.cx.metamask.io';\nexport const METAMASK_STALELIST_FILE = '/v1/stalelist';\nexport const METAMASK_HOTLIST_DIFF_FILE = '/v1/diffsSince';\n\nexport const CLIENT_SIDE_DETECION_BASE_URL =\n 'https://client-side-detection.api.cx.metamask.io';\nexport const C2_DOMAIN_BLOCKLIST_ENDPOINT = '/v1/request-blocklist';\n\nexport const PHISHING_DETECTION_BASE_URL =\n 'https://dapp-scanning.api.cx.metamask.io';\nexport const PHISHING_DETECTION_SCAN_ENDPOINT = 'scan';\n\nexport const C2_DOMAIN_BLOCKLIST_REFRESH_INTERVAL = 5 * 60; // 5 mins in seconds\nexport const HOTLIST_REFRESH_INTERVAL = 5 * 60; // 5 mins in seconds\nexport const STALELIST_REFRESH_INTERVAL = 30 * 24 * 60 * 60; // 30 days in seconds\n\nexport const METAMASK_STALELIST_URL = `${PHISHING_CONFIG_BASE_URL}${METAMASK_STALELIST_FILE}`;\nexport const METAMASK_HOTLIST_DIFF_URL = `${PHISHING_CONFIG_BASE_URL}${METAMASK_HOTLIST_DIFF_FILE}`;\nexport const C2_DOMAIN_BLOCKLIST_URL = `${CLIENT_SIDE_DETECION_BASE_URL}${C2_DOMAIN_BLOCKLIST_ENDPOINT}`;\n\n/**\n * @type ListTypes\n *\n * Type outlining the types of lists provided by aggregating different source lists\n */\nexport type ListTypes =\n | 'fuzzylist'\n | 'blocklist'\n | 'allowlist'\n | 'c2DomainBlocklist';\n\n/**\n * @type EthPhishingResponse\n *\n * Configuration response from the eth-phishing-detect package\n * consisting of approved and unapproved website origins\n * @property blacklist - List of unapproved origins\n * @property fuzzylist - List of fuzzy-matched unapproved origins\n * @property tolerance - Fuzzy match tolerance level\n * @property version - Version number of this configuration\n * @property whitelist - List of approved origins\n */\nexport type EthPhishingResponse = {\n blacklist: string[];\n fuzzylist: string[];\n tolerance: number;\n version: number;\n whitelist: string[];\n};\n\n/**\n * @type C2DomainBlocklistResponse\n *\n * Response for blocklist update requests\n * @property recentlyAdded - List of c2 domains recently added to the blocklist\n * @property recentlyRemoved - List of c2 domains recently removed from the blocklist\n * @property lastFetchedAt - Timestamp of the last fetch request\n */\nexport type C2DomainBlocklistResponse = {\n recentlyAdded: string[];\n recentlyRemoved: string[];\n lastFetchedAt: string;\n};\n\n/**\n * @type PhishingStalelist\n *\n * type defining expected type of the stalelist.json file.\n * @property eth_phishing_detect_config - Stale list sourced from eth-phishing-detect's config.json.\n * @property tolerance - Fuzzy match tolerance level\n * @property lastUpdated - Timestamp of last update.\n * @property version - Stalelist data structure iteration.\n */\nexport type PhishingStalelist = {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n eth_phishing_detect_config: Record<ListTypes, string[]>;\n tolerance: number;\n version: number;\n lastUpdated: number;\n};\n\n/**\n * @type PhishingListState\n *\n * type defining the persisted list state. This is the persisted state that is updated frequently with `this.maybeUpdateState()`.\n * @property allowlist - List of approved origins (legacy naming \"whitelist\")\n * @property blocklist - List of unapproved origins (legacy naming \"blacklist\")\n * @property c2DomainBlocklist - List of hashed hostnames that C2 requests are blocked against.\n * @property fuzzylist - List of fuzzy-matched unapproved origins\n * @property tolerance - Fuzzy match tolerance level\n * @property lastUpdated - Timestamp of last update.\n * @property version - Version of the phishing list state.\n * @property name - Name of the list. Used for attribution.\n */\nexport type PhishingListState = {\n allowlist: string[];\n blocklist: string[];\n c2DomainBlocklist: string[];\n fuzzylist: string[];\n tolerance: number;\n version: number;\n lastUpdated: number;\n name: ListNames;\n};\n\n/**\n * @type HotlistDiff\n *\n * type defining the expected type of the diffs in hotlist.json file.\n * @property url - Url of the diff entry.\n * @property timestamp - Timestamp at which the diff was identified.\n * @property targetList - The list name where the diff was identified.\n * @property isRemoval - Was the diff identified a removal type.\n */\nexport type HotlistDiff = {\n url: string;\n timestamp: number;\n targetList: `${ListKeys}.${ListTypes}`;\n isRemoval?: boolean;\n};\n\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type DataResultWrapper<T> = {\n data: T;\n};\n\n/**\n * @type Hotlist\n *\n * Type defining expected hotlist.json file.\n * @property url - Url of the diff entry.\n * @property timestamp - Timestamp at which the diff was identified.\n * @property targetList - The list name where the diff was identified.\n * @property isRemoval - Was the diff identified a removal type.\n */\nexport type Hotlist = HotlistDiff[];\n\n/**\n * Enum containing upstream data provider source list keys.\n * These are the keys denoting lists consumed by the upstream data provider.\n */\nexport enum ListKeys {\n EthPhishingDetectConfig = 'eth_phishing_detect_config',\n}\n\n/**\n * Enum containing downstream client attribution names.\n */\nexport enum ListNames {\n MetaMask = 'MetaMask',\n}\n\n/**\n * Maps from downstream client attribution name\n * to list key sourced from upstream data provider.\n */\nconst phishingListNameKeyMap = {\n [ListNames.MetaMask]: ListKeys.EthPhishingDetectConfig,\n};\n\n/**\n * Maps from list key sourced from upstream data\n * provider to downstream client attribution name.\n */\nexport const phishingListKeyNameMap = {\n [ListKeys.EthPhishingDetectConfig]: ListNames.MetaMask,\n};\n\nconst controllerName = 'PhishingController';\n\nconst metadata = {\n phishingLists: { persist: true, anonymous: false },\n whitelist: { persist: true, anonymous: false },\n hotlistLastFetched: { persist: true, anonymous: false },\n stalelistLastFetched: { persist: true, anonymous: false },\n c2DomainBlocklistLastFetched: { persist: true, anonymous: false },\n};\n\n/**\n * Get a default empty state for the controller.\n * @returns The default empty state.\n */\nconst getDefaultState = (): PhishingControllerState => {\n return {\n phishingLists: [],\n whitelist: [],\n hotlistLastFetched: 0,\n stalelistLastFetched: 0,\n c2DomainBlocklistLastFetched: 0,\n };\n};\n\n/**\n * @type PhishingControllerState\n *\n * Phishing controller state\n * @property phishing - eth-phishing-detect configuration\n * @property whitelist - array of temporarily-approved origins\n */\nexport type PhishingControllerState = {\n phishingLists: PhishingListState[];\n whitelist: string[];\n hotlistLastFetched: number;\n stalelistLastFetched: number;\n c2DomainBlocklistLastFetched: number;\n};\n\n/**\n * @type PhishingControllerOptions\n *\n * Phishing controller options\n * @property stalelistRefreshInterval - Polling interval used to fetch stale list.\n * @property hotlistRefreshInterval - Polling interval used to fetch hotlist diff list.\n * @property c2DomainBlocklistRefreshInterval - Polling interval used to fetch c2 domain blocklist.\n */\nexport type PhishingControllerOptions = {\n stalelistRefreshInterval?: number;\n hotlistRefreshInterval?: number;\n c2DomainBlocklistRefreshInterval?: number;\n messenger: PhishingControllerMessenger;\n state?: Partial<PhishingControllerState>;\n};\n\nexport type MaybeUpdateState = {\n type: `${typeof controllerName}:maybeUpdateState`;\n handler: PhishingController['maybeUpdateState'];\n};\n\nexport type TestOrigin = {\n type: `${typeof controllerName}:testOrigin`;\n handler: PhishingController['test'];\n};\n\nexport type PhishingControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n PhishingControllerState\n>;\n\nexport type PhishingControllerActions =\n | PhishingControllerGetStateAction\n | MaybeUpdateState\n | TestOrigin;\n\nexport type PhishingControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n PhishingControllerState\n>;\n\nexport type PhishingControllerEvents = PhishingControllerStateChangeEvent;\n\nexport type PhishingControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n PhishingControllerActions,\n PhishingControllerEvents,\n never,\n never\n>;\n\n/**\n * Controller that manages community-maintained lists of approved and unapproved website origins.\n */\nexport class PhishingController extends BaseController<\n typeof controllerName,\n PhishingControllerState,\n PhishingControllerMessenger\n> {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #detector: any;\n\n #stalelistRefreshInterval: number;\n\n #hotlistRefreshInterval: number;\n\n #c2DomainBlocklistRefreshInterval: number;\n\n #inProgressHotlistUpdate?: Promise<void>;\n\n #inProgressStalelistUpdate?: Promise<void>;\n\n #isProgressC2DomainBlocklistUpdate?: Promise<void>;\n\n /**\n * Construct a Phishing Controller.\n *\n * @param config - Initial options used to configure this controller.\n * @param config.stalelistRefreshInterval - Polling interval used to fetch stale list.\n * @param config.hotlistRefreshInterval - Polling interval used to fetch hotlist diff list.\n * @param config.c2DomainBlocklistRefreshInterval - Polling interval used to fetch c2 domain blocklist.\n * @param config.messenger - The controller restricted messenger.\n * @param config.state - Initial state to set on this controller.\n */\n constructor({\n stalelistRefreshInterval = STALELIST_REFRESH_INTERVAL,\n hotlistRefreshInterval = HOTLIST_REFRESH_INTERVAL,\n c2DomainBlocklistRefreshInterval = C2_DOMAIN_BLOCKLIST_REFRESH_INTERVAL,\n messenger,\n state = {},\n }: PhishingControllerOptions) {\n super({\n name: controllerName,\n metadata,\n messenger,\n state: {\n ...getDefaultState(),\n ...state,\n },\n });\n\n this.#stalelistRefreshInterval = stalelistRefreshInterval;\n this.#hotlistRefreshInterval = hotlistRefreshInterval;\n this.#c2DomainBlocklistRefreshInterval = c2DomainBlocklistRefreshInterval;\n this.#registerMessageHandlers();\n\n this.updatePhishingDetector();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:maybeUpdateState` as const,\n this.maybeUpdateState.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:testOrigin` as const,\n this.test.bind(this),\n );\n }\n\n /**\n * Updates this.detector with an instance of PhishingDetector using the current state.\n */\n updatePhishingDetector() {\n this.#detector = new PhishingDetector(this.state.phishingLists);\n }\n\n /**\n * Set the interval at which the stale phishing list will be refetched.\n * Fetching will only occur on the next call to test/bypass.\n * For immediate update to the phishing list, call {@link updateStalelist} directly.\n *\n * @param interval - the new interval, in ms.\n */\n setStalelistRefreshInterval(interval: number) {\n this.#stalelistRefreshInterval = interval;\n }\n\n /**\n * Set the interval at which the hot list will be refetched.\n * Fetching will only occur on the next call to test/bypass.\n * For immediate update to the phishing list, call {@link updateHotlist} directly.\n *\n * @param interval - the new interval, in ms.\n */\n setHotlistRefreshInterval(interval: number) {\n this.#hotlistRefreshInterval = interval;\n }\n\n /**\n * Set the interval at which the C2 domain blocklist will be refetched.\n * Fetching will only occur on the next call to test/bypass.\n * For immediate update to the phishing list, call {@link updateHotlist} directly.\n *\n * @param interval - the new interval, in ms.\n */\n setC2DomainBlocklistRefreshInterval(interval: number) {\n this.#c2DomainBlocklistRefreshInterval = interval;\n }\n\n /**\n * Determine if an update to the stalelist configuration is needed.\n *\n * @returns Whether an update is needed\n */\n isStalelistOutOfDate() {\n return (\n fetchTimeNow() - this.state.stalelistLastFetched >=\n this.#stalelistRefreshInterval\n );\n }\n\n /**\n * Determine if an update to the hotlist configuration is needed.\n *\n * @returns Whether an update is needed\n */\n isHotlistOutOfDate() {\n return (\n fetchTimeNow() - this.state.hotlistLastFetched >=\n this.#hotlistRefreshInterval\n );\n }\n\n /**\n * Determine if an update to the C2 domain blocklist is needed.\n *\n * @returns Whether an update is needed\n */\n isC2DomainBlocklistOutOfDate() {\n return (\n fetchTimeNow() - this.state.c2DomainBlocklistLastFetched >=\n this.#c2DomainBlocklistRefreshInterval\n );\n }\n\n /**\n * Conditionally update the phishing configuration.\n *\n * If the stalelist configuration is out of date, this function will call `updateStalelist`\n * to update the configuration. This will automatically grab the hotlist,\n * so it isn't necessary to continue on to download the hotlist and the c2 domain blocklist.\n *\n */\n async maybeUpdateState() {\n const staleListOutOfDate = this.isStalelistOutOfDate();\n if (staleListOutOfDate) {\n await this.updateStalelist();\n return;\n }\n const hotlistOutOfDate = this.isHotlistOutOfDate();\n if (hotlistOutOfDate) {\n await this.updateHotlist();\n }\n const c2DomainBlocklistOutOfDate = this.isC2DomainBlocklistOutOfDate();\n if (c2DomainBlocklistOutOfDate) {\n await this.updateC2DomainBlocklist();\n }\n }\n\n /**\n * Determines if a given origin is unapproved.\n *\n * It is strongly recommended that you call {@link maybeUpdateState} before calling this,\n * to check whether the phishing configuration is up-to-date. It will be updated if necessary\n * by calling {@link updateStalelist} or {@link updateHotlist}.\n *\n * @param origin - Domain origin of a website.\n * @returns Whether the origin is an unapproved origin.\n */\n test(origin: string): PhishingDetectorResult {\n const punycodeOrigin = toASCII(origin);\n const hostname = getHostnameFromUrl(punycodeOrigin);\n if (this.state.whitelist.includes(hostname || punycodeOrigin)) {\n return { result: false, type: PhishingDetectorResultType.All }; // Same as whitelisted match returned by detector.check(...).\n }\n return this.#detector.check(punycodeOrigin);\n }\n\n /**\n * Checks if a request URL's domain is blocked against the request blocklist.\n *\n * This method is used to determine if a specific request URL is associated with a malicious\n * command and control (C2) domain. The URL's hostname is hashed and checked against a configured\n * blocklist of known malicious domains.\n *\n * @param origin - The full request URL to be checked.\n * @returns An object indicating whether the URL's domain is blocked and relevant metadata.\n */\n isBlockedRequest(origin: string): PhishingDetectorResult {\n const punycodeOrigin = toASCII(origin);\n const hostname = getHostnameFromUrl(punycodeOrigin);\n if (this.state.whitelist.includes(hostname || punycodeOrigin)) {\n return { result: false, type: PhishingDetectorResultType.All }; // Same as whitelisted match returned by detector.check(...).\n }\n return this.#detector.isMaliciousC2Domain(punycodeOrigin);\n }\n\n /**\n * Temporarily marks a given origin as approved.\n *\n * @param origin - The origin to mark as approved.\n */\n bypass(origin: string) {\n const punycodeOrigin = toASCII(origin);\n const hostname = getHostnameFromUrl(punycodeOrigin);\n const { whitelist } = this.state;\n if (whitelist.includes(hostname || punycodeOrigin)) {\n return;\n }\n this.update((draftState) => {\n draftState.whitelist.push(hostname || punycodeOrigin);\n });\n }\n\n /**\n * Update the C2 domain blocklist.\n *\n * If an update is in progress, no additional update will be made. Instead this will wait until\n * the in-progress update has finished.\n */\n async updateC2DomainBlocklist() {\n if (this.#isProgressC2DomainBlocklistUpdate) {\n await this.#isProgressC2DomainBlocklistUpdate;\n return;\n }\n\n try {\n this.#isProgressC2DomainBlocklistUpdate = this.#updateC2DomainBlocklist();\n await this.#isProgressC2DomainBlocklistUpdate;\n } finally {\n this.#isProgressC2DomainBlocklistUpdate = undefined;\n }\n }\n\n /**\n * Update the hotlist.\n *\n * If an update is in progress, no additional update will be made. Instead this will wait until\n * the in-progress update has finished.\n */\n async updateHotlist() {\n if (this.#inProgressHotlistUpdate) {\n await this.#inProgressHotlistUpdate;\n return;\n }\n\n try {\n this.#inProgressHotlistUpdate = this.#updateHotlist();\n await this.#inProgressHotlistUpdate;\n } finally {\n this.#inProgressHotlistUpdate = undefined;\n }\n }\n\n /**\n * Update the stalelist.\n *\n * If an update is in progress, no additional update will be made. Instead this will wait until\n * the in-progress update has finished.\n */\n async updateStalelist() {\n if (this.#inProgressStalelistUpdate) {\n await this.#inProgressStalelistUpdate;\n return;\n }\n\n try {\n this.#inProgressStalelistUpdate = this.#updateStalelist();\n await this.#inProgressStalelistUpdate;\n } finally {\n this.#inProgressStalelistUpdate = undefined;\n }\n }\n\n /**\n * Scan a URL for phishing. It will only scan the hostname of the URL. It also only supports\n * web URLs.\n *\n * @param url - The URL to scan.\n * @returns The phishing detection scan result.\n */\n scanUrl = async (url: string): Promise<PhishingDetectionScanResult> => {\n const [hostname, ok] = getHostnameFromWebUrl(url);\n if (!ok) {\n return {\n domainName: '',\n recommendedAction: RecommendedAction.None,\n fetchError: 'url is not a valid web URL',\n };\n }\n\n const apiResponse = await safelyExecuteWithTimeout(\n async () => {\n const res = await fetch(\n `${PHISHING_DETECTION_BASE_URL}/${PHISHING_DETECTION_SCAN_ENDPOINT}?url=${encodeURIComponent(hostname)}`,\n {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n },\n );\n if (!res.ok) {\n return {\n error: `${res.status} ${res.statusText}`,\n };\n }\n const data = await res.json();\n return data;\n },\n true,\n 8000,\n );\n\n // Need to do it this way because safelyExecuteWithTimeout returns undefined for both timeouts and errors.\n if (!apiResponse) {\n return {\n domainName: '',\n recommendedAction: RecommendedAction.None,\n fetchError: 'timeout of 8000ms exceeded',\n };\n } else if ('error' in apiResponse) {\n return {\n domainName: '',\n recommendedAction: RecommendedAction.None,\n fetchError: apiResponse.error,\n };\n }\n\n return {\n domainName: hostname,\n recommendedAction: apiResponse.recommendedAction,\n } as PhishingDetectionScanResult;\n };\n\n /**\n * Update the stalelist configuration.\n *\n * This should only be called from the `updateStalelist` function, which is a wrapper around\n * this function that prevents redundant configuration updates.\n */\n async #updateStalelist() {\n let stalelistResponse: DataResultWrapper<PhishingStalelist> | null = null;\n let hotlistDiffsResponse: DataResultWrapper<Hotlist> | null = null;\n let c2DomainBlocklistResponse: C2DomainBlocklistResponse | null = null;\n try {\n const stalelistPromise = this.#queryConfig<\n DataResultWrapper<PhishingStalelist>\n >(METAMASK_STALELIST_URL);\n\n const c2DomainBlocklistPromise =\n this.#queryConfig<C2DomainBlocklistResponse>(C2_DOMAIN_BLOCKLIST_URL);\n\n [stalelistResponse, c2DomainBlocklistResponse] = await Promise.all([\n stalelistPromise,\n c2DomainBlocklistPromise,\n ]);\n // Fetching hotlist diffs relies on having a lastUpdated timestamp to do `GET /v1/diffsSince/:timestamp`,\n // so it doesn't make sense to call if there is not a timestamp to begin with.\n if (stalelistResponse?.data && stalelistResponse.data.lastUpdated > 0) {\n hotlistDiffsResponse = await this.#queryConfig<\n DataResultWrapper<Hotlist>\n >(`${METAMASK_HOTLIST_DIFF_URL}/${stalelistResponse.data.lastUpdated}`);\n }\n } finally {\n // Set `stalelistLastFetched` and `hotlistLastFetched` even for failed requests to prevent server\n // from being overwhelmed with traffic after a network disruption.\n const timeNow = fetchTimeNow();\n this.update((draftState) => {\n draftState.stalelistLastFetched = timeNow;\n draftState.hotlistLastFetched = timeNow;\n draftState.c2DomainBlocklistLastFetched = timeNow;\n });\n }\n\n if (!stalelistResponse || !hotlistDiffsResponse) {\n return;\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const { eth_phishing_detect_config, ...partialState } =\n stalelistResponse.data;\n\n const metamaskListState: PhishingListState = {\n ...eth_phishing_detect_config,\n ...partialState,\n c2DomainBlocklist: c2DomainBlocklistResponse\n ? c2DomainBlocklistResponse.recentlyAdded\n : [],\n name: phishingListKeyNameMap.eth_phishing_detect_config,\n };\n\n const newMetaMaskListState: PhishingListState = applyDiffs(\n metamaskListState,\n hotlistDiffsResponse.data,\n ListKeys.EthPhishingDetectConfig,\n );\n\n this.update((draftState) => {\n draftState.phishingLists = [newMetaMaskListState];\n });\n this.updatePhishingDetector();\n }\n\n /**\n * Update the stalelist configuration.\n *\n * This should only be called from the `updateStalelist` function, which is a wrapper around\n * this function that prevents redundant configuration updates.\n */\n async #updateHotlist() {\n let hotlistResponse: DataResultWrapper<Hotlist> | null;\n\n try {\n if (this.state.phishingLists.length === 0) {\n return;\n }\n\n const lastDiffTimestamp = Math.max(\n ...this.state.phishingLists.map(({ lastUpdated }) => lastUpdated),\n );\n\n hotlistResponse = await this.#queryConfig<DataResultWrapper<Hotlist>>(\n `${METAMASK_HOTLIST_DIFF_URL}/${lastDiffTimestamp}`,\n );\n } finally {\n // Set `hotlistLastFetched` even for failed requests to prevent server from being overwhelmed with\n // traffic after a network disruption.\n this.update((draftState) => {\n draftState.hotlistLastFetched = fetchTimeNow();\n });\n }\n\n if (!hotlistResponse?.data) {\n return;\n }\n const hotlist = hotlistResponse.data;\n const newPhishingLists = this.state.phishingLists.map((phishingList) => {\n const updatedList = applyDiffs(\n phishingList,\n hotlist,\n phishingListNameKeyMap[phishingList.name],\n [],\n [],\n );\n\n return updatedList;\n });\n\n this.update((draftState) => {\n draftState.phishingLists = newPhishingLists;\n });\n this.updatePhishingDetector();\n }\n\n /**\n * Update the C2 domain blocklist.\n *\n * This should only be called from the `updateC2DomainBlocklist` function, which is a wrapper around\n * this function that prevents redundant configuration updates.\n */\n async #updateC2DomainBlocklist() {\n let c2DomainBlocklistResponse: C2DomainBlocklistResponse | null = null;\n\n try {\n c2DomainBlocklistResponse =\n await this.#queryConfig<C2DomainBlocklistResponse>(\n `${C2_DOMAIN_BLOCKLIST_URL}?timestamp=${roundToNearestMinute(\n this.state.c2DomainBlocklistLastFetched,\n )}`,\n );\n } finally {\n // Set `c2DomainBlocklistLastFetched` even for failed requests to prevent server from being overwhelmed with\n // traffic after a network disruption.\n this.update((draftState) => {\n draftState.c2DomainBlocklistLastFetched = fetchTimeNow();\n });\n }\n\n if (!c2DomainBlocklistResponse) {\n return;\n }\n\n const recentlyAddedC2Domains = c2DomainBlocklistResponse.recentlyAdded;\n const recentlyRemovedC2Domains = c2DomainBlocklistResponse.recentlyRemoved;\n\n const newPhishingLists = this.state.phishingLists.map((phishingList) => {\n const updatedList = applyDiffs(\n phishingList,\n [],\n phishingListNameKeyMap[phishingList.name],\n recentlyAddedC2Domains,\n recentlyRemovedC2Domains,\n );\n\n return updatedList;\n });\n\n this.update((draftState) => {\n draftState.phishingLists = newPhishingLists;\n });\n this.updatePhishingDetector();\n }\n\n async #queryConfig<ResponseType>(\n input: RequestInfo,\n ): Promise<ResponseType | null> {\n const response = await safelyExecute(\n () => fetch(input, { cache: 'no-cache' }),\n true,\n );\n\n switch (response?.status) {\n case 200: {\n return await response.json();\n }\n\n default: {\n return null;\n }\n }\n }\n}\n\nexport default PhishingController;\n\nexport type { PhishingDetectorResult };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhishingController.d.cts","sourceRoot":"","sources":["../src/PhishingController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,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;AAEF;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,cAAc,CACpD,OAAO,cAAc,EACrB,uBAAuB,EACvB,2BAA2B,CAC5B;;IAiBC;;;;;;;;;OASG;gBACS,EACV,wBAAqD,EACrD,sBAAiD,EACjD,gCAAuE,EACvE,SAAS,EACT,KAAU,GACX,EAAE,yBAAyB;IAmC5B;;OAEG;IACH,sBAAsB;IAItB;;;;;;OAMG;IACH,2BAA2B,CAAC,QAAQ,EAAE,MAAM;IAI5C;;;;;;OAMG;IACH,yBAAyB,CAAC,QAAQ,EAAE,MAAM;IAI1C;;;;;;OAMG;IACH,mCAAmC,CAAC,QAAQ,EAAE,MAAM;IAIpD;;;;OAIG;IACH,oBAAoB;IAOpB;;;;OAIG;IACH,kBAAkB;IAOlB;;;;OAIG;IACH,4BAA4B;IAO5B;;;;;;;OAOG;IACG,gBAAgB;IAgBtB;;;;;;;;;OASG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB;IAS5C;;;;;;;;;OASG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB;IASxD;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM;IAYrB;;;;;OAKG;IACG,uBAAuB;IAc7B;;;;;OAKG;IACG,aAAa;IAcnB;;;;;OAKG;IACG,eAAe;IAcrB;;;;;;OAMG;IACH,OAAO,QAAe,MAAM,KAAG,QAAQ,2BAA2B,CAAC,CAoDjE;CA8LH;AAED,eAAe,kBAAkB,CAAC;AAElC,YAAY,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -431,9 +431,12 @@ async function _PhishingController_updateStalelist() {
|
|
|
431
431
|
* this function that prevents redundant configuration updates.
|
|
432
432
|
*/
|
|
433
433
|
async function _PhishingController_updateHotlist() {
|
|
434
|
-
const lastDiffTimestamp = Math.max(...this.state.phishingLists.map(({ lastUpdated }) => lastUpdated));
|
|
435
434
|
let hotlistResponse;
|
|
436
435
|
try {
|
|
436
|
+
if (this.state.phishingLists.length === 0) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
const lastDiffTimestamp = Math.max(...this.state.phishingLists.map(({ lastUpdated }) => lastUpdated));
|
|
437
440
|
hotlistResponse = await __classPrivateFieldGet(this, _PhishingController_instances, "m", _PhishingController_queryConfig).call(this, `${METAMASK_HOTLIST_DIFF_URL}/${lastDiffTimestamp}`);
|
|
438
441
|
}
|
|
439
442
|
finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhishingController.mjs","sourceRoot":"","sources":["../src/PhishingController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EACL,aAAa,EACb,wBAAwB,EACzB,mCAAmC;;;AAGpC,OAAO,EAAE,gBAAgB,EAAE,+BAA2B;AACtD,OAAO,EACL,0BAA0B,EAG1B,iBAAiB,EAClB,oBAAgB;AACjB,OAAO,EACL,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACtB,oBAAgB;AAEjB,MAAM,CAAC,MAAM,wBAAwB,GACnC,+CAA+C,CAAC;AAClD,MAAM,CAAC,MAAM,uBAAuB,GAAG,eAAe,CAAC;AACvD,MAAM,CAAC,MAAM,0BAA0B,GAAG,gBAAgB,CAAC;AAE3D,MAAM,CAAC,MAAM,6BAA6B,GACxC,kDAAkD,CAAC;AACrD,MAAM,CAAC,MAAM,4BAA4B,GAAG,uBAAuB,CAAC;AAEpE,MAAM,CAAC,MAAM,2BAA2B,GACtC,0CAA0C,CAAC;AAC7C,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC;AAEvD,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,oBAAoB;AAChF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,oBAAoB;AACpE,MAAM,CAAC,MAAM,0BAA0B,G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AC,EACzC,sBAAsB,EACtB,wBAAwB,CACzB,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;QACzB,UAAU,CAAC,aAAa,GAAG,gBAAgB,CAAC;IAC9C,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,sBAAsB,EAAE,CAAC;AAChC,CAAC,oCAED,KAAK,0CACH,KAAkB;IAElB,MAAM,QAAQ,GAAG,MAAM,aAAa,CAClC,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EACzC,IAAI,CACL,CAAC;IAEF,QAAQ,QAAQ,EAAE,MAAM,EAAE;QACxB,KAAK,GAAG,CAAC,CAAC;YACR,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;SAC9B;QAED,OAAO,CAAC,CAAC;YACP,OAAO,IAAI,CAAC;SACb;KACF;AACH,CAAC;AAGH,eAAe,kBAAkB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport {\n safelyExecute,\n safelyExecuteWithTimeout,\n} from '@metamask/controller-utils';\nimport { toASCII } from 'punycode/punycode.js';\n\nimport { PhishingDetector } from './PhishingDetector';\nimport {\n PhishingDetectorResultType,\n type PhishingDetectorResult,\n type PhishingDetectionScanResult,\n RecommendedAction,\n} from './types';\nimport {\n applyDiffs,\n fetchTimeNow,\n getHostnameFromUrl,\n roundToNearestMinute,\n getHostnameFromWebUrl,\n} from './utils';\n\nexport const PHISHING_CONFIG_BASE_URL =\n 'https://phishing-detection.api.cx.metamask.io';\nexport const METAMASK_STALELIST_FILE = '/v1/stalelist';\nexport const METAMASK_HOTLIST_DIFF_FILE = '/v1/diffsSince';\n\nexport const CLIENT_SIDE_DETECION_BASE_URL =\n 'https://client-side-detection.api.cx.metamask.io';\nexport const C2_DOMAIN_BLOCKLIST_ENDPOINT = '/v1/request-blocklist';\n\nexport const PHISHING_DETECTION_BASE_URL =\n 'https://dapp-scanning.api.cx.metamask.io';\nexport const PHISHING_DETECTION_SCAN_ENDPOINT = 'scan';\n\nexport const C2_DOMAIN_BLOCKLIST_REFRESH_INTERVAL = 5 * 60; // 5 mins in seconds\nexport const HOTLIST_REFRESH_INTERVAL = 5 * 60; // 5 mins in seconds\nexport const STALELIST_REFRESH_INTERVAL = 30 * 24 * 60 * 60; // 30 days in seconds\n\nexport const METAMASK_STALELIST_URL = `${PHISHING_CONFIG_BASE_URL}${METAMASK_STALELIST_FILE}`;\nexport const METAMASK_HOTLIST_DIFF_URL = `${PHISHING_CONFIG_BASE_URL}${METAMASK_HOTLIST_DIFF_FILE}`;\nexport const C2_DOMAIN_BLOCKLIST_URL = `${CLIENT_SIDE_DETECION_BASE_URL}${C2_DOMAIN_BLOCKLIST_ENDPOINT}`;\n\n/**\n * @type ListTypes\n *\n * Type outlining the types of lists provided by aggregating different source lists\n */\nexport type ListTypes =\n | 'fuzzylist'\n | 'blocklist'\n | 'allowlist'\n | 'c2DomainBlocklist';\n\n/**\n * @type EthPhishingResponse\n *\n * Configuration response from the eth-phishing-detect package\n * consisting of approved and unapproved website origins\n * @property blacklist - List of unapproved origins\n * @property fuzzylist - List of fuzzy-matched unapproved origins\n * @property tolerance - Fuzzy match tolerance level\n * @property version - Version number of this configuration\n * @property whitelist - List of approved origins\n */\nexport type EthPhishingResponse = {\n blacklist: string[];\n fuzzylist: string[];\n tolerance: number;\n version: number;\n whitelist: string[];\n};\n\n/**\n * @type C2DomainBlocklistResponse\n *\n * Response for blocklist update requests\n * @property recentlyAdded - List of c2 domains recently added to the blocklist\n * @property recentlyRemoved - List of c2 domains recently removed from the blocklist\n * @property lastFetchedAt - Timestamp of the last fetch request\n */\nexport type C2DomainBlocklistResponse = {\n recentlyAdded: string[];\n recentlyRemoved: string[];\n lastFetchedAt: string;\n};\n\n/**\n * @type PhishingStalelist\n *\n * type defining expected type of the stalelist.json file.\n * @property eth_phishing_detect_config - Stale list sourced from eth-phishing-detect's config.json.\n * @property tolerance - Fuzzy match tolerance level\n * @property lastUpdated - Timestamp of last update.\n * @property version - Stalelist data structure iteration.\n */\nexport type PhishingStalelist = {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n eth_phishing_detect_config: Record<ListTypes, string[]>;\n tolerance: number;\n version: number;\n lastUpdated: number;\n};\n\n/**\n * @type PhishingListState\n *\n * type defining the persisted list state. This is the persisted state that is updated frequently with `this.maybeUpdateState()`.\n * @property allowlist - List of approved origins (legacy naming \"whitelist\")\n * @property blocklist - List of unapproved origins (legacy naming \"blacklist\")\n * @property c2DomainBlocklist - List of hashed hostnames that C2 requests are blocked against.\n * @property fuzzylist - List of fuzzy-matched unapproved origins\n * @property tolerance - Fuzzy match tolerance level\n * @property lastUpdated - Timestamp of last update.\n * @property version - Version of the phishing list state.\n * @property name - Name of the list. Used for attribution.\n */\nexport type PhishingListState = {\n allowlist: string[];\n blocklist: string[];\n c2DomainBlocklist: string[];\n fuzzylist: string[];\n tolerance: number;\n version: number;\n lastUpdated: number;\n name: ListNames;\n};\n\n/**\n * @type HotlistDiff\n *\n * type defining the expected type of the diffs in hotlist.json file.\n * @property url - Url of the diff entry.\n * @property timestamp - Timestamp at which the diff was identified.\n * @property targetList - The list name where the diff was identified.\n * @property isRemoval - Was the diff identified a removal type.\n */\nexport type HotlistDiff = {\n url: string;\n timestamp: number;\n targetList: `${ListKeys}.${ListTypes}`;\n isRemoval?: boolean;\n};\n\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type DataResultWrapper<T> = {\n data: T;\n};\n\n/**\n * @type Hotlist\n *\n * Type defining expected hotlist.json file.\n * @property url - Url of the diff entry.\n * @property timestamp - Timestamp at which the diff was identified.\n * @property targetList - The list name where the diff was identified.\n * @property isRemoval - Was the diff identified a removal type.\n */\nexport type Hotlist = HotlistDiff[];\n\n/**\n * Enum containing upstream data provider source list keys.\n * These are the keys denoting lists consumed by the upstream data provider.\n */\nexport enum ListKeys {\n EthPhishingDetectConfig = 'eth_phishing_detect_config',\n}\n\n/**\n * Enum containing downstream client attribution names.\n */\nexport enum ListNames {\n MetaMask = 'MetaMask',\n}\n\n/**\n * Maps from downstream client attribution name\n * to list key sourced from upstream data provider.\n */\nconst phishingListNameKeyMap = {\n [ListNames.MetaMask]: ListKeys.EthPhishingDetectConfig,\n};\n\n/**\n * Maps from list key sourced from upstream data\n * provider to downstream client attribution name.\n */\nexport const phishingListKeyNameMap = {\n [ListKeys.EthPhishingDetectConfig]: ListNames.MetaMask,\n};\n\nconst controllerName = 'PhishingController';\n\nconst metadata = {\n phishingLists: { persist: true, anonymous: false },\n whitelist: { persist: true, anonymous: false },\n hotlistLastFetched: { persist: true, anonymous: false },\n stalelistLastFetched: { persist: true, anonymous: false },\n c2DomainBlocklistLastFetched: { persist: true, anonymous: false },\n};\n\n/**\n * Get a default empty state for the controller.\n * @returns The default empty state.\n */\nconst getDefaultState = (): PhishingControllerState => {\n return {\n phishingLists: [],\n whitelist: [],\n hotlistLastFetched: 0,\n stalelistLastFetched: 0,\n c2DomainBlocklistLastFetched: 0,\n };\n};\n\n/**\n * @type PhishingControllerState\n *\n * Phishing controller state\n * @property phishing - eth-phishing-detect configuration\n * @property whitelist - array of temporarily-approved origins\n */\nexport type PhishingControllerState = {\n phishingLists: PhishingListState[];\n whitelist: string[];\n hotlistLastFetched: number;\n stalelistLastFetched: number;\n c2DomainBlocklistLastFetched: number;\n};\n\n/**\n * @type PhishingControllerOptions\n *\n * Phishing controller options\n * @property stalelistRefreshInterval - Polling interval used to fetch stale list.\n * @property hotlistRefreshInterval - Polling interval used to fetch hotlist diff list.\n * @property c2DomainBlocklistRefreshInterval - Polling interval used to fetch c2 domain blocklist.\n */\nexport type PhishingControllerOptions = {\n stalelistRefreshInterval?: number;\n hotlistRefreshInterval?: number;\n c2DomainBlocklistRefreshInterval?: number;\n messenger: PhishingControllerMessenger;\n state?: Partial<PhishingControllerState>;\n};\n\nexport type MaybeUpdateState = {\n type: `${typeof controllerName}:maybeUpdateState`;\n handler: PhishingController['maybeUpdateState'];\n};\n\nexport type TestOrigin = {\n type: `${typeof controllerName}:testOrigin`;\n handler: PhishingController['test'];\n};\n\nexport type PhishingControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n PhishingControllerState\n>;\n\nexport type PhishingControllerActions =\n | PhishingControllerGetStateAction\n | MaybeUpdateState\n | TestOrigin;\n\nexport type PhishingControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n PhishingControllerState\n>;\n\nexport type PhishingControllerEvents = PhishingControllerStateChangeEvent;\n\nexport type PhishingControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n PhishingControllerActions,\n PhishingControllerEvents,\n never,\n never\n>;\n\n/**\n * Controller that manages community-maintained lists of approved and unapproved website origins.\n */\nexport class PhishingController extends BaseController<\n typeof controllerName,\n PhishingControllerState,\n PhishingControllerMessenger\n> {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #detector: any;\n\n #stalelistRefreshInterval: number;\n\n #hotlistRefreshInterval: number;\n\n #c2DomainBlocklistRefreshInterval: number;\n\n #inProgressHotlistUpdate?: Promise<void>;\n\n #inProgressStalelistUpdate?: Promise<void>;\n\n #isProgressC2DomainBlocklistUpdate?: Promise<void>;\n\n /**\n * Construct a Phishing Controller.\n *\n * @param config - Initial options used to configure this controller.\n * @param config.stalelistRefreshInterval - Polling interval used to fetch stale list.\n * @param config.hotlistRefreshInterval - Polling interval used to fetch hotlist diff list.\n * @param config.c2DomainBlocklistRefreshInterval - Polling interval used to fetch c2 domain blocklist.\n * @param config.messenger - The controller restricted messenger.\n * @param config.state - Initial state to set on this controller.\n */\n constructor({\n stalelistRefreshInterval = STALELIST_REFRESH_INTERVAL,\n hotlistRefreshInterval = HOTLIST_REFRESH_INTERVAL,\n c2DomainBlocklistRefreshInterval = C2_DOMAIN_BLOCKLIST_REFRESH_INTERVAL,\n messenger,\n state = {},\n }: PhishingControllerOptions) {\n super({\n name: controllerName,\n metadata,\n messenger,\n state: {\n ...getDefaultState(),\n ...state,\n },\n });\n\n this.#stalelistRefreshInterval = stalelistRefreshInterval;\n this.#hotlistRefreshInterval = hotlistRefreshInterval;\n this.#c2DomainBlocklistRefreshInterval = c2DomainBlocklistRefreshInterval;\n this.#registerMessageHandlers();\n\n this.updatePhishingDetector();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:maybeUpdateState` as const,\n this.maybeUpdateState.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:testOrigin` as const,\n this.test.bind(this),\n );\n }\n\n /**\n * Updates this.detector with an instance of PhishingDetector using the current state.\n */\n updatePhishingDetector() {\n this.#detector = new PhishingDetector(this.state.phishingLists);\n }\n\n /**\n * Set the interval at which the stale phishing list will be refetched.\n * Fetching will only occur on the next call to test/bypass.\n * For immediate update to the phishing list, call {@link updateStalelist} directly.\n *\n * @param interval - the new interval, in ms.\n */\n setStalelistRefreshInterval(interval: number) {\n this.#stalelistRefreshInterval = interval;\n }\n\n /**\n * Set the interval at which the hot list will be refetched.\n * Fetching will only occur on the next call to test/bypass.\n * For immediate update to the phishing list, call {@link updateHotlist} directly.\n *\n * @param interval - the new interval, in ms.\n */\n setHotlistRefreshInterval(interval: number) {\n this.#hotlistRefreshInterval = interval;\n }\n\n /**\n * Set the interval at which the C2 domain blocklist will be refetched.\n * Fetching will only occur on the next call to test/bypass.\n * For immediate update to the phishing list, call {@link updateHotlist} directly.\n *\n * @param interval - the new interval, in ms.\n */\n setC2DomainBlocklistRefreshInterval(interval: number) {\n this.#c2DomainBlocklistRefreshInterval = interval;\n }\n\n /**\n * Determine if an update to the stalelist configuration is needed.\n *\n * @returns Whether an update is needed\n */\n isStalelistOutOfDate() {\n return (\n fetchTimeNow() - this.state.stalelistLastFetched >=\n this.#stalelistRefreshInterval\n );\n }\n\n /**\n * Determine if an update to the hotlist configuration is needed.\n *\n * @returns Whether an update is needed\n */\n isHotlistOutOfDate() {\n return (\n fetchTimeNow() - this.state.hotlistLastFetched >=\n this.#hotlistRefreshInterval\n );\n }\n\n /**\n * Determine if an update to the C2 domain blocklist is needed.\n *\n * @returns Whether an update is needed\n */\n isC2DomainBlocklistOutOfDate() {\n return (\n fetchTimeNow() - this.state.c2DomainBlocklistLastFetched >=\n this.#c2DomainBlocklistRefreshInterval\n );\n }\n\n /**\n * Conditionally update the phishing configuration.\n *\n * If the stalelist configuration is out of date, this function will call `updateStalelist`\n * to update the configuration. This will automatically grab the hotlist,\n * so it isn't necessary to continue on to download the hotlist and the c2 domain blocklist.\n *\n */\n async maybeUpdateState() {\n const staleListOutOfDate = this.isStalelistOutOfDate();\n if (staleListOutOfDate) {\n await this.updateStalelist();\n return;\n }\n const hotlistOutOfDate = this.isHotlistOutOfDate();\n if (hotlistOutOfDate) {\n await this.updateHotlist();\n }\n const c2DomainBlocklistOutOfDate = this.isC2DomainBlocklistOutOfDate();\n if (c2DomainBlocklistOutOfDate) {\n await this.updateC2DomainBlocklist();\n }\n }\n\n /**\n * Determines if a given origin is unapproved.\n *\n * It is strongly recommended that you call {@link maybeUpdateState} before calling this,\n * to check whether the phishing configuration is up-to-date. It will be updated if necessary\n * by calling {@link updateStalelist} or {@link updateHotlist}.\n *\n * @param origin - Domain origin of a website.\n * @returns Whether the origin is an unapproved origin.\n */\n test(origin: string): PhishingDetectorResult {\n const punycodeOrigin = toASCII(origin);\n const hostname = getHostnameFromUrl(punycodeOrigin);\n if (this.state.whitelist.includes(hostname || punycodeOrigin)) {\n return { result: false, type: PhishingDetectorResultType.All }; // Same as whitelisted match returned by detector.check(...).\n }\n return this.#detector.check(punycodeOrigin);\n }\n\n /**\n * Checks if a request URL's domain is blocked against the request blocklist.\n *\n * This method is used to determine if a specific request URL is associated with a malicious\n * command and control (C2) domain. The URL's hostname is hashed and checked against a configured\n * blocklist of known malicious domains.\n *\n * @param origin - The full request URL to be checked.\n * @returns An object indicating whether the URL's domain is blocked and relevant metadata.\n */\n isBlockedRequest(origin: string): PhishingDetectorResult {\n const punycodeOrigin = toASCII(origin);\n const hostname = getHostnameFromUrl(punycodeOrigin);\n if (this.state.whitelist.includes(hostname || punycodeOrigin)) {\n return { result: false, type: PhishingDetectorResultType.All }; // Same as whitelisted match returned by detector.check(...).\n }\n return this.#detector.isMaliciousC2Domain(punycodeOrigin);\n }\n\n /**\n * Temporarily marks a given origin as approved.\n *\n * @param origin - The origin to mark as approved.\n */\n bypass(origin: string) {\n const punycodeOrigin = toASCII(origin);\n const hostname = getHostnameFromUrl(punycodeOrigin);\n const { whitelist } = this.state;\n if (whitelist.includes(hostname || punycodeOrigin)) {\n return;\n }\n this.update((draftState) => {\n draftState.whitelist.push(hostname || punycodeOrigin);\n });\n }\n\n /**\n * Update the C2 domain blocklist.\n *\n * If an update is in progress, no additional update will be made. Instead this will wait until\n * the in-progress update has finished.\n */\n async updateC2DomainBlocklist() {\n if (this.#isProgressC2DomainBlocklistUpdate) {\n await this.#isProgressC2DomainBlocklistUpdate;\n return;\n }\n\n try {\n this.#isProgressC2DomainBlocklistUpdate = this.#updateC2DomainBlocklist();\n await this.#isProgressC2DomainBlocklistUpdate;\n } finally {\n this.#isProgressC2DomainBlocklistUpdate = undefined;\n }\n }\n\n /**\n * Update the hotlist.\n *\n * If an update is in progress, no additional update will be made. Instead this will wait until\n * the in-progress update has finished.\n */\n async updateHotlist() {\n if (this.#inProgressHotlistUpdate) {\n await this.#inProgressHotlistUpdate;\n return;\n }\n\n try {\n this.#inProgressHotlistUpdate = this.#updateHotlist();\n await this.#inProgressHotlistUpdate;\n } finally {\n this.#inProgressHotlistUpdate = undefined;\n }\n }\n\n /**\n * Update the stalelist.\n *\n * If an update is in progress, no additional update will be made. Instead this will wait until\n * the in-progress update has finished.\n */\n async updateStalelist() {\n if (this.#inProgressStalelistUpdate) {\n await this.#inProgressStalelistUpdate;\n return;\n }\n\n try {\n this.#inProgressStalelistUpdate = this.#updateStalelist();\n await this.#inProgressStalelistUpdate;\n } finally {\n this.#inProgressStalelistUpdate = undefined;\n }\n }\n\n /**\n * Scan a URL for phishing. It will only scan the hostname of the URL. It also only supports\n * web URLs.\n *\n * @param url - The URL to scan.\n * @returns The phishing detection scan result.\n */\n scanUrl = async (url: string): Promise<PhishingDetectionScanResult> => {\n const [hostname, ok] = getHostnameFromWebUrl(url);\n if (!ok) {\n return {\n domainName: '',\n recommendedAction: RecommendedAction.None,\n fetchError: 'url is not a valid web URL',\n };\n }\n\n const apiResponse = await safelyExecuteWithTimeout(\n async () => {\n const res = await fetch(\n `${PHISHING_DETECTION_BASE_URL}/${PHISHING_DETECTION_SCAN_ENDPOINT}?url=${encodeURIComponent(hostname)}`,\n {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n },\n );\n if (!res.ok) {\n return {\n error: `${res.status} ${res.statusText}`,\n };\n }\n const data = await res.json();\n return data;\n },\n true,\n 8000,\n );\n\n // Need to do it this way because safelyExecuteWithTimeout returns undefined for both timeouts and errors.\n if (!apiResponse) {\n return {\n domainName: '',\n recommendedAction: RecommendedAction.None,\n fetchError: 'timeout of 8000ms exceeded',\n };\n } else if ('error' in apiResponse) {\n return {\n domainName: '',\n recommendedAction: RecommendedAction.None,\n fetchError: apiResponse.error,\n };\n }\n\n return {\n domainName: hostname,\n recommendedAction: apiResponse.recommendedAction,\n } as PhishingDetectionScanResult;\n };\n\n /**\n * Update the stalelist configuration.\n *\n * This should only be called from the `updateStalelist` function, which is a wrapper around\n * this function that prevents redundant configuration updates.\n */\n async #updateStalelist() {\n let stalelistResponse: DataResultWrapper<PhishingStalelist> | null = null;\n let hotlistDiffsResponse: DataResultWrapper<Hotlist> | null = null;\n let c2DomainBlocklistResponse: C2DomainBlocklistResponse | null = null;\n try {\n const stalelistPromise = this.#queryConfig<\n DataResultWrapper<PhishingStalelist>\n >(METAMASK_STALELIST_URL);\n\n const c2DomainBlocklistPromise =\n this.#queryConfig<C2DomainBlocklistResponse>(C2_DOMAIN_BLOCKLIST_URL);\n\n [stalelistResponse, c2DomainBlocklistResponse] = await Promise.all([\n stalelistPromise,\n c2DomainBlocklistPromise,\n ]);\n // Fetching hotlist diffs relies on having a lastUpdated timestamp to do `GET /v1/diffsSince/:timestamp`,\n // so it doesn't make sense to call if there is not a timestamp to begin with.\n if (stalelistResponse?.data && stalelistResponse.data.lastUpdated > 0) {\n hotlistDiffsResponse = await this.#queryConfig<\n DataResultWrapper<Hotlist>\n >(`${METAMASK_HOTLIST_DIFF_URL}/${stalelistResponse.data.lastUpdated}`);\n }\n } finally {\n // Set `stalelistLastFetched` and `hotlistLastFetched` even for failed requests to prevent server\n // from being overwhelmed with traffic after a network disruption.\n const timeNow = fetchTimeNow();\n this.update((draftState) => {\n draftState.stalelistLastFetched = timeNow;\n draftState.hotlistLastFetched = timeNow;\n draftState.c2DomainBlocklistLastFetched = timeNow;\n });\n }\n\n if (!stalelistResponse || !hotlistDiffsResponse) {\n return;\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const { eth_phishing_detect_config, ...partialState } =\n stalelistResponse.data;\n\n const metamaskListState: PhishingListState = {\n ...eth_phishing_detect_config,\n ...partialState,\n c2DomainBlocklist: c2DomainBlocklistResponse\n ? c2DomainBlocklistResponse.recentlyAdded\n : [],\n name: phishingListKeyNameMap.eth_phishing_detect_config,\n };\n\n const newMetaMaskListState: PhishingListState = applyDiffs(\n metamaskListState,\n hotlistDiffsResponse.data,\n ListKeys.EthPhishingDetectConfig,\n );\n\n this.update((draftState) => {\n draftState.phishingLists = [newMetaMaskListState];\n });\n this.updatePhishingDetector();\n }\n\n /**\n * Update the stalelist configuration.\n *\n * This should only be called from the `updateStalelist` function, which is a wrapper around\n * this function that prevents redundant configuration updates.\n */\n async #updateHotlist() {\n const lastDiffTimestamp = Math.max(\n ...this.state.phishingLists.map(({ lastUpdated }) => lastUpdated),\n );\n let hotlistResponse: DataResultWrapper<Hotlist> | null;\n\n try {\n hotlistResponse = await this.#queryConfig<DataResultWrapper<Hotlist>>(\n `${METAMASK_HOTLIST_DIFF_URL}/${lastDiffTimestamp}`,\n );\n } finally {\n // Set `hotlistLastFetched` even for failed requests to prevent server from being overwhelmed with\n // traffic after a network disruption.\n this.update((draftState) => {\n draftState.hotlistLastFetched = fetchTimeNow();\n });\n }\n\n if (!hotlistResponse?.data) {\n return;\n }\n const hotlist = hotlistResponse.data;\n const newPhishingLists = this.state.phishingLists.map((phishingList) => {\n const updatedList = applyDiffs(\n phishingList,\n hotlist,\n phishingListNameKeyMap[phishingList.name],\n [],\n [],\n );\n\n return updatedList;\n });\n\n this.update((draftState) => {\n draftState.phishingLists = newPhishingLists;\n });\n this.updatePhishingDetector();\n }\n\n /**\n * Update the C2 domain blocklist.\n *\n * This should only be called from the `updateC2DomainBlocklist` function, which is a wrapper around\n * this function that prevents redundant configuration updates.\n */\n async #updateC2DomainBlocklist() {\n let c2DomainBlocklistResponse: C2DomainBlocklistResponse | null = null;\n\n try {\n c2DomainBlocklistResponse =\n await this.#queryConfig<C2DomainBlocklistResponse>(\n `${C2_DOMAIN_BLOCKLIST_URL}?timestamp=${roundToNearestMinute(\n this.state.c2DomainBlocklistLastFetched,\n )}`,\n );\n } finally {\n // Set `c2DomainBlocklistLastFetched` even for failed requests to prevent server from being overwhelmed with\n // traffic after a network disruption.\n this.update((draftState) => {\n draftState.c2DomainBlocklistLastFetched = fetchTimeNow();\n });\n }\n\n if (!c2DomainBlocklistResponse) {\n return;\n }\n\n const recentlyAddedC2Domains = c2DomainBlocklistResponse.recentlyAdded;\n const recentlyRemovedC2Domains = c2DomainBlocklistResponse.recentlyRemoved;\n\n const newPhishingLists = this.state.phishingLists.map((phishingList) => {\n const updatedList = applyDiffs(\n phishingList,\n [],\n phishingListNameKeyMap[phishingList.name],\n recentlyAddedC2Domains,\n recentlyRemovedC2Domains,\n );\n\n return updatedList;\n });\n\n this.update((draftState) => {\n draftState.phishingLists = newPhishingLists;\n });\n this.updatePhishingDetector();\n }\n\n async #queryConfig<ResponseType>(\n input: RequestInfo,\n ): Promise<ResponseType | null> {\n const response = await safelyExecute(\n () => fetch(input, { cache: 'no-cache' }),\n true,\n );\n\n switch (response?.status) {\n case 200: {\n return await response.json();\n }\n\n default: {\n return null;\n }\n }\n }\n}\n\nexport default PhishingController;\n\nexport type { PhishingDetectorResult };\n"]}
|
|
1
|
+
{"version":3,"file":"PhishingController.mjs","sourceRoot":"","sources":["../src/PhishingController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EACL,aAAa,EACb,wBAAwB,EACzB,mCAAmC;;;AAGpC,OAAO,EAAE,gBAAgB,EAAE,+BAA2B;AACtD,OAAO,EACL,0BAA0B,EAG1B,iBAAiB,EAClB,oBAAgB;AACjB,OAAO,EACL,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACtB,oBAAgB;AAEjB,MAAM,CAAC,MAAM,wBAAwB,GACnC,+CAA+C,CAAC;AAClD,MAAM,CAAC,MAAM,uBAAuB,GAAG,eAAe,CAAC;AACvD,MAAM,CAAC,MAAM,0BAA0B,GAAG,gBAAgB,CAAC;AAE3D,MAAM,CAAC,MAAM,6BAA6B,GACxC,kDAAkD,CAAC;AACrD,MAAM,CAAC,MAAM,4BAA4B,GAAG,uBAAuB,CAAC;AAEpE,MAAM,CAAC,MAAM,2BAA2B,GACtC,0CAA0C,CAAC;AAC7C,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC;AAEvD,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,oBAAoB;AACh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;IAE3E,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE;QACrE,MAAM,WAAW,GAAG,UAAU,CAC5B,YAAY,EACZ,EAAE,EACF,sBAAsB,CAAC,YAAY,CAAC,IAAI,CAAC,EACzC,sBAAsB,EACtB,wBAAwB,CACzB,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;QACzB,UAAU,CAAC,aAAa,GAAG,gBAAgB,CAAC;IAC9C,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,sBAAsB,EAAE,CAAC;AAChC,CAAC,oCAED,KAAK,0CACH,KAAkB;IAElB,MAAM,QAAQ,GAAG,MAAM,aAAa,CAClC,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EACzC,IAAI,CACL,CAAC;IAEF,QAAQ,QAAQ,EAAE,MAAM,EAAE;QACxB,KAAK,GAAG,CAAC,CAAC;YACR,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;SAC9B;QAED,OAAO,CAAC,CAAC;YACP,OAAO,IAAI,CAAC;SACb;KACF;AACH,CAAC;AAGH,eAAe,kBAAkB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport {\n safelyExecute,\n safelyExecuteWithTimeout,\n} from '@metamask/controller-utils';\nimport { toASCII } from 'punycode/punycode.js';\n\nimport { PhishingDetector } from './PhishingDetector';\nimport {\n PhishingDetectorResultType,\n type PhishingDetectorResult,\n type PhishingDetectionScanResult,\n RecommendedAction,\n} from './types';\nimport {\n applyDiffs,\n fetchTimeNow,\n getHostnameFromUrl,\n roundToNearestMinute,\n getHostnameFromWebUrl,\n} from './utils';\n\nexport const PHISHING_CONFIG_BASE_URL =\n 'https://phishing-detection.api.cx.metamask.io';\nexport const METAMASK_STALELIST_FILE = '/v1/stalelist';\nexport const METAMASK_HOTLIST_DIFF_FILE = '/v1/diffsSince';\n\nexport const CLIENT_SIDE_DETECION_BASE_URL =\n 'https://client-side-detection.api.cx.metamask.io';\nexport const C2_DOMAIN_BLOCKLIST_ENDPOINT = '/v1/request-blocklist';\n\nexport const PHISHING_DETECTION_BASE_URL =\n 'https://dapp-scanning.api.cx.metamask.io';\nexport const PHISHING_DETECTION_SCAN_ENDPOINT = 'scan';\n\nexport const C2_DOMAIN_BLOCKLIST_REFRESH_INTERVAL = 5 * 60; // 5 mins in seconds\nexport const HOTLIST_REFRESH_INTERVAL = 5 * 60; // 5 mins in seconds\nexport const STALELIST_REFRESH_INTERVAL = 30 * 24 * 60 * 60; // 30 days in seconds\n\nexport const METAMASK_STALELIST_URL = `${PHISHING_CONFIG_BASE_URL}${METAMASK_STALELIST_FILE}`;\nexport const METAMASK_HOTLIST_DIFF_URL = `${PHISHING_CONFIG_BASE_URL}${METAMASK_HOTLIST_DIFF_FILE}`;\nexport const C2_DOMAIN_BLOCKLIST_URL = `${CLIENT_SIDE_DETECION_BASE_URL}${C2_DOMAIN_BLOCKLIST_ENDPOINT}`;\n\n/**\n * @type ListTypes\n *\n * Type outlining the types of lists provided by aggregating different source lists\n */\nexport type ListTypes =\n | 'fuzzylist'\n | 'blocklist'\n | 'allowlist'\n | 'c2DomainBlocklist';\n\n/**\n * @type EthPhishingResponse\n *\n * Configuration response from the eth-phishing-detect package\n * consisting of approved and unapproved website origins\n * @property blacklist - List of unapproved origins\n * @property fuzzylist - List of fuzzy-matched unapproved origins\n * @property tolerance - Fuzzy match tolerance level\n * @property version - Version number of this configuration\n * @property whitelist - List of approved origins\n */\nexport type EthPhishingResponse = {\n blacklist: string[];\n fuzzylist: string[];\n tolerance: number;\n version: number;\n whitelist: string[];\n};\n\n/**\n * @type C2DomainBlocklistResponse\n *\n * Response for blocklist update requests\n * @property recentlyAdded - List of c2 domains recently added to the blocklist\n * @property recentlyRemoved - List of c2 domains recently removed from the blocklist\n * @property lastFetchedAt - Timestamp of the last fetch request\n */\nexport type C2DomainBlocklistResponse = {\n recentlyAdded: string[];\n recentlyRemoved: string[];\n lastFetchedAt: string;\n};\n\n/**\n * @type PhishingStalelist\n *\n * type defining expected type of the stalelist.json file.\n * @property eth_phishing_detect_config - Stale list sourced from eth-phishing-detect's config.json.\n * @property tolerance - Fuzzy match tolerance level\n * @property lastUpdated - Timestamp of last update.\n * @property version - Stalelist data structure iteration.\n */\nexport type PhishingStalelist = {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n eth_phishing_detect_config: Record<ListTypes, string[]>;\n tolerance: number;\n version: number;\n lastUpdated: number;\n};\n\n/**\n * @type PhishingListState\n *\n * type defining the persisted list state. This is the persisted state that is updated frequently with `this.maybeUpdateState()`.\n * @property allowlist - List of approved origins (legacy naming \"whitelist\")\n * @property blocklist - List of unapproved origins (legacy naming \"blacklist\")\n * @property c2DomainBlocklist - List of hashed hostnames that C2 requests are blocked against.\n * @property fuzzylist - List of fuzzy-matched unapproved origins\n * @property tolerance - Fuzzy match tolerance level\n * @property lastUpdated - Timestamp of last update.\n * @property version - Version of the phishing list state.\n * @property name - Name of the list. Used for attribution.\n */\nexport type PhishingListState = {\n allowlist: string[];\n blocklist: string[];\n c2DomainBlocklist: string[];\n fuzzylist: string[];\n tolerance: number;\n version: number;\n lastUpdated: number;\n name: ListNames;\n};\n\n/**\n * @type HotlistDiff\n *\n * type defining the expected type of the diffs in hotlist.json file.\n * @property url - Url of the diff entry.\n * @property timestamp - Timestamp at which the diff was identified.\n * @property targetList - The list name where the diff was identified.\n * @property isRemoval - Was the diff identified a removal type.\n */\nexport type HotlistDiff = {\n url: string;\n timestamp: number;\n targetList: `${ListKeys}.${ListTypes}`;\n isRemoval?: boolean;\n};\n\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type DataResultWrapper<T> = {\n data: T;\n};\n\n/**\n * @type Hotlist\n *\n * Type defining expected hotlist.json file.\n * @property url - Url of the diff entry.\n * @property timestamp - Timestamp at which the diff was identified.\n * @property targetList - The list name where the diff was identified.\n * @property isRemoval - Was the diff identified a removal type.\n */\nexport type Hotlist = HotlistDiff[];\n\n/**\n * Enum containing upstream data provider source list keys.\n * These are the keys denoting lists consumed by the upstream data provider.\n */\nexport enum ListKeys {\n EthPhishingDetectConfig = 'eth_phishing_detect_config',\n}\n\n/**\n * Enum containing downstream client attribution names.\n */\nexport enum ListNames {\n MetaMask = 'MetaMask',\n}\n\n/**\n * Maps from downstream client attribution name\n * to list key sourced from upstream data provider.\n */\nconst phishingListNameKeyMap = {\n [ListNames.MetaMask]: ListKeys.EthPhishingDetectConfig,\n};\n\n/**\n * Maps from list key sourced from upstream data\n * provider to downstream client attribution name.\n */\nexport const phishingListKeyNameMap = {\n [ListKeys.EthPhishingDetectConfig]: ListNames.MetaMask,\n};\n\nconst controllerName = 'PhishingController';\n\nconst metadata = {\n phishingLists: { persist: true, anonymous: false },\n whitelist: { persist: true, anonymous: false },\n hotlistLastFetched: { persist: true, anonymous: false },\n stalelistLastFetched: { persist: true, anonymous: false },\n c2DomainBlocklistLastFetched: { persist: true, anonymous: false },\n};\n\n/**\n * Get a default empty state for the controller.\n * @returns The default empty state.\n */\nconst getDefaultState = (): PhishingControllerState => {\n return {\n phishingLists: [],\n whitelist: [],\n hotlistLastFetched: 0,\n stalelistLastFetched: 0,\n c2DomainBlocklistLastFetched: 0,\n };\n};\n\n/**\n * @type PhishingControllerState\n *\n * Phishing controller state\n * @property phishing - eth-phishing-detect configuration\n * @property whitelist - array of temporarily-approved origins\n */\nexport type PhishingControllerState = {\n phishingLists: PhishingListState[];\n whitelist: string[];\n hotlistLastFetched: number;\n stalelistLastFetched: number;\n c2DomainBlocklistLastFetched: number;\n};\n\n/**\n * @type PhishingControllerOptions\n *\n * Phishing controller options\n * @property stalelistRefreshInterval - Polling interval used to fetch stale list.\n * @property hotlistRefreshInterval - Polling interval used to fetch hotlist diff list.\n * @property c2DomainBlocklistRefreshInterval - Polling interval used to fetch c2 domain blocklist.\n */\nexport type PhishingControllerOptions = {\n stalelistRefreshInterval?: number;\n hotlistRefreshInterval?: number;\n c2DomainBlocklistRefreshInterval?: number;\n messenger: PhishingControllerMessenger;\n state?: Partial<PhishingControllerState>;\n};\n\nexport type MaybeUpdateState = {\n type: `${typeof controllerName}:maybeUpdateState`;\n handler: PhishingController['maybeUpdateState'];\n};\n\nexport type TestOrigin = {\n type: `${typeof controllerName}:testOrigin`;\n handler: PhishingController['test'];\n};\n\nexport type PhishingControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n PhishingControllerState\n>;\n\nexport type PhishingControllerActions =\n | PhishingControllerGetStateAction\n | MaybeUpdateState\n | TestOrigin;\n\nexport type PhishingControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n PhishingControllerState\n>;\n\nexport type PhishingControllerEvents = PhishingControllerStateChangeEvent;\n\nexport type PhishingControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n PhishingControllerActions,\n PhishingControllerEvents,\n never,\n never\n>;\n\n/**\n * Controller that manages community-maintained lists of approved and unapproved website origins.\n */\nexport class PhishingController extends BaseController<\n typeof controllerName,\n PhishingControllerState,\n PhishingControllerMessenger\n> {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #detector: any;\n\n #stalelistRefreshInterval: number;\n\n #hotlistRefreshInterval: number;\n\n #c2DomainBlocklistRefreshInterval: number;\n\n #inProgressHotlistUpdate?: Promise<void>;\n\n #inProgressStalelistUpdate?: Promise<void>;\n\n #isProgressC2DomainBlocklistUpdate?: Promise<void>;\n\n /**\n * Construct a Phishing Controller.\n *\n * @param config - Initial options used to configure this controller.\n * @param config.stalelistRefreshInterval - Polling interval used to fetch stale list.\n * @param config.hotlistRefreshInterval - Polling interval used to fetch hotlist diff list.\n * @param config.c2DomainBlocklistRefreshInterval - Polling interval used to fetch c2 domain blocklist.\n * @param config.messenger - The controller restricted messenger.\n * @param config.state - Initial state to set on this controller.\n */\n constructor({\n stalelistRefreshInterval = STALELIST_REFRESH_INTERVAL,\n hotlistRefreshInterval = HOTLIST_REFRESH_INTERVAL,\n c2DomainBlocklistRefreshInterval = C2_DOMAIN_BLOCKLIST_REFRESH_INTERVAL,\n messenger,\n state = {},\n }: PhishingControllerOptions) {\n super({\n name: controllerName,\n metadata,\n messenger,\n state: {\n ...getDefaultState(),\n ...state,\n },\n });\n\n this.#stalelistRefreshInterval = stalelistRefreshInterval;\n this.#hotlistRefreshInterval = hotlistRefreshInterval;\n this.#c2DomainBlocklistRefreshInterval = c2DomainBlocklistRefreshInterval;\n this.#registerMessageHandlers();\n\n this.updatePhishingDetector();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:maybeUpdateState` as const,\n this.maybeUpdateState.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:testOrigin` as const,\n this.test.bind(this),\n );\n }\n\n /**\n * Updates this.detector with an instance of PhishingDetector using the current state.\n */\n updatePhishingDetector() {\n this.#detector = new PhishingDetector(this.state.phishingLists);\n }\n\n /**\n * Set the interval at which the stale phishing list will be refetched.\n * Fetching will only occur on the next call to test/bypass.\n * For immediate update to the phishing list, call {@link updateStalelist} directly.\n *\n * @param interval - the new interval, in ms.\n */\n setStalelistRefreshInterval(interval: number) {\n this.#stalelistRefreshInterval = interval;\n }\n\n /**\n * Set the interval at which the hot list will be refetched.\n * Fetching will only occur on the next call to test/bypass.\n * For immediate update to the phishing list, call {@link updateHotlist} directly.\n *\n * @param interval - the new interval, in ms.\n */\n setHotlistRefreshInterval(interval: number) {\n this.#hotlistRefreshInterval = interval;\n }\n\n /**\n * Set the interval at which the C2 domain blocklist will be refetched.\n * Fetching will only occur on the next call to test/bypass.\n * For immediate update to the phishing list, call {@link updateHotlist} directly.\n *\n * @param interval - the new interval, in ms.\n */\n setC2DomainBlocklistRefreshInterval(interval: number) {\n this.#c2DomainBlocklistRefreshInterval = interval;\n }\n\n /**\n * Determine if an update to the stalelist configuration is needed.\n *\n * @returns Whether an update is needed\n */\n isStalelistOutOfDate() {\n return (\n fetchTimeNow() - this.state.stalelistLastFetched >=\n this.#stalelistRefreshInterval\n );\n }\n\n /**\n * Determine if an update to the hotlist configuration is needed.\n *\n * @returns Whether an update is needed\n */\n isHotlistOutOfDate() {\n return (\n fetchTimeNow() - this.state.hotlistLastFetched >=\n this.#hotlistRefreshInterval\n );\n }\n\n /**\n * Determine if an update to the C2 domain blocklist is needed.\n *\n * @returns Whether an update is needed\n */\n isC2DomainBlocklistOutOfDate() {\n return (\n fetchTimeNow() - this.state.c2DomainBlocklistLastFetched >=\n this.#c2DomainBlocklistRefreshInterval\n );\n }\n\n /**\n * Conditionally update the phishing configuration.\n *\n * If the stalelist configuration is out of date, this function will call `updateStalelist`\n * to update the configuration. This will automatically grab the hotlist,\n * so it isn't necessary to continue on to download the hotlist and the c2 domain blocklist.\n *\n */\n async maybeUpdateState() {\n const staleListOutOfDate = this.isStalelistOutOfDate();\n if (staleListOutOfDate) {\n await this.updateStalelist();\n return;\n }\n const hotlistOutOfDate = this.isHotlistOutOfDate();\n if (hotlistOutOfDate) {\n await this.updateHotlist();\n }\n const c2DomainBlocklistOutOfDate = this.isC2DomainBlocklistOutOfDate();\n if (c2DomainBlocklistOutOfDate) {\n await this.updateC2DomainBlocklist();\n }\n }\n\n /**\n * Determines if a given origin is unapproved.\n *\n * It is strongly recommended that you call {@link maybeUpdateState} before calling this,\n * to check whether the phishing configuration is up-to-date. It will be updated if necessary\n * by calling {@link updateStalelist} or {@link updateHotlist}.\n *\n * @param origin - Domain origin of a website.\n * @returns Whether the origin is an unapproved origin.\n */\n test(origin: string): PhishingDetectorResult {\n const punycodeOrigin = toASCII(origin);\n const hostname = getHostnameFromUrl(punycodeOrigin);\n if (this.state.whitelist.includes(hostname || punycodeOrigin)) {\n return { result: false, type: PhishingDetectorResultType.All }; // Same as whitelisted match returned by detector.check(...).\n }\n return this.#detector.check(punycodeOrigin);\n }\n\n /**\n * Checks if a request URL's domain is blocked against the request blocklist.\n *\n * This method is used to determine if a specific request URL is associated with a malicious\n * command and control (C2) domain. The URL's hostname is hashed and checked against a configured\n * blocklist of known malicious domains.\n *\n * @param origin - The full request URL to be checked.\n * @returns An object indicating whether the URL's domain is blocked and relevant metadata.\n */\n isBlockedRequest(origin: string): PhishingDetectorResult {\n const punycodeOrigin = toASCII(origin);\n const hostname = getHostnameFromUrl(punycodeOrigin);\n if (this.state.whitelist.includes(hostname || punycodeOrigin)) {\n return { result: false, type: PhishingDetectorResultType.All }; // Same as whitelisted match returned by detector.check(...).\n }\n return this.#detector.isMaliciousC2Domain(punycodeOrigin);\n }\n\n /**\n * Temporarily marks a given origin as approved.\n *\n * @param origin - The origin to mark as approved.\n */\n bypass(origin: string) {\n const punycodeOrigin = toASCII(origin);\n const hostname = getHostnameFromUrl(punycodeOrigin);\n const { whitelist } = this.state;\n if (whitelist.includes(hostname || punycodeOrigin)) {\n return;\n }\n this.update((draftState) => {\n draftState.whitelist.push(hostname || punycodeOrigin);\n });\n }\n\n /**\n * Update the C2 domain blocklist.\n *\n * If an update is in progress, no additional update will be made. Instead this will wait until\n * the in-progress update has finished.\n */\n async updateC2DomainBlocklist() {\n if (this.#isProgressC2DomainBlocklistUpdate) {\n await this.#isProgressC2DomainBlocklistUpdate;\n return;\n }\n\n try {\n this.#isProgressC2DomainBlocklistUpdate = this.#updateC2DomainBlocklist();\n await this.#isProgressC2DomainBlocklistUpdate;\n } finally {\n this.#isProgressC2DomainBlocklistUpdate = undefined;\n }\n }\n\n /**\n * Update the hotlist.\n *\n * If an update is in progress, no additional update will be made. Instead this will wait until\n * the in-progress update has finished.\n */\n async updateHotlist() {\n if (this.#inProgressHotlistUpdate) {\n await this.#inProgressHotlistUpdate;\n return;\n }\n\n try {\n this.#inProgressHotlistUpdate = this.#updateHotlist();\n await this.#inProgressHotlistUpdate;\n } finally {\n this.#inProgressHotlistUpdate = undefined;\n }\n }\n\n /**\n * Update the stalelist.\n *\n * If an update is in progress, no additional update will be made. Instead this will wait until\n * the in-progress update has finished.\n */\n async updateStalelist() {\n if (this.#inProgressStalelistUpdate) {\n await this.#inProgressStalelistUpdate;\n return;\n }\n\n try {\n this.#inProgressStalelistUpdate = this.#updateStalelist();\n await this.#inProgressStalelistUpdate;\n } finally {\n this.#inProgressStalelistUpdate = undefined;\n }\n }\n\n /**\n * Scan a URL for phishing. It will only scan the hostname of the URL. It also only supports\n * web URLs.\n *\n * @param url - The URL to scan.\n * @returns The phishing detection scan result.\n */\n scanUrl = async (url: string): Promise<PhishingDetectionScanResult> => {\n const [hostname, ok] = getHostnameFromWebUrl(url);\n if (!ok) {\n return {\n domainName: '',\n recommendedAction: RecommendedAction.None,\n fetchError: 'url is not a valid web URL',\n };\n }\n\n const apiResponse = await safelyExecuteWithTimeout(\n async () => {\n const res = await fetch(\n `${PHISHING_DETECTION_BASE_URL}/${PHISHING_DETECTION_SCAN_ENDPOINT}?url=${encodeURIComponent(hostname)}`,\n {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n },\n );\n if (!res.ok) {\n return {\n error: `${res.status} ${res.statusText}`,\n };\n }\n const data = await res.json();\n return data;\n },\n true,\n 8000,\n );\n\n // Need to do it this way because safelyExecuteWithTimeout returns undefined for both timeouts and errors.\n if (!apiResponse) {\n return {\n domainName: '',\n recommendedAction: RecommendedAction.None,\n fetchError: 'timeout of 8000ms exceeded',\n };\n } else if ('error' in apiResponse) {\n return {\n domainName: '',\n recommendedAction: RecommendedAction.None,\n fetchError: apiResponse.error,\n };\n }\n\n return {\n domainName: hostname,\n recommendedAction: apiResponse.recommendedAction,\n } as PhishingDetectionScanResult;\n };\n\n /**\n * Update the stalelist configuration.\n *\n * This should only be called from the `updateStalelist` function, which is a wrapper around\n * this function that prevents redundant configuration updates.\n */\n async #updateStalelist() {\n let stalelistResponse: DataResultWrapper<PhishingStalelist> | null = null;\n let hotlistDiffsResponse: DataResultWrapper<Hotlist> | null = null;\n let c2DomainBlocklistResponse: C2DomainBlocklistResponse | null = null;\n try {\n const stalelistPromise = this.#queryConfig<\n DataResultWrapper<PhishingStalelist>\n >(METAMASK_STALELIST_URL);\n\n const c2DomainBlocklistPromise =\n this.#queryConfig<C2DomainBlocklistResponse>(C2_DOMAIN_BLOCKLIST_URL);\n\n [stalelistResponse, c2DomainBlocklistResponse] = await Promise.all([\n stalelistPromise,\n c2DomainBlocklistPromise,\n ]);\n // Fetching hotlist diffs relies on having a lastUpdated timestamp to do `GET /v1/diffsSince/:timestamp`,\n // so it doesn't make sense to call if there is not a timestamp to begin with.\n if (stalelistResponse?.data && stalelistResponse.data.lastUpdated > 0) {\n hotlistDiffsResponse = await this.#queryConfig<\n DataResultWrapper<Hotlist>\n >(`${METAMASK_HOTLIST_DIFF_URL}/${stalelistResponse.data.lastUpdated}`);\n }\n } finally {\n // Set `stalelistLastFetched` and `hotlistLastFetched` even for failed requests to prevent server\n // from being overwhelmed with traffic after a network disruption.\n const timeNow = fetchTimeNow();\n this.update((draftState) => {\n draftState.stalelistLastFetched = timeNow;\n draftState.hotlistLastFetched = timeNow;\n draftState.c2DomainBlocklistLastFetched = timeNow;\n });\n }\n\n if (!stalelistResponse || !hotlistDiffsResponse) {\n return;\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const { eth_phishing_detect_config, ...partialState } =\n stalelistResponse.data;\n\n const metamaskListState: PhishingListState = {\n ...eth_phishing_detect_config,\n ...partialState,\n c2DomainBlocklist: c2DomainBlocklistResponse\n ? c2DomainBlocklistResponse.recentlyAdded\n : [],\n name: phishingListKeyNameMap.eth_phishing_detect_config,\n };\n\n const newMetaMaskListState: PhishingListState = applyDiffs(\n metamaskListState,\n hotlistDiffsResponse.data,\n ListKeys.EthPhishingDetectConfig,\n );\n\n this.update((draftState) => {\n draftState.phishingLists = [newMetaMaskListState];\n });\n this.updatePhishingDetector();\n }\n\n /**\n * Update the stalelist configuration.\n *\n * This should only be called from the `updateStalelist` function, which is a wrapper around\n * this function that prevents redundant configuration updates.\n */\n async #updateHotlist() {\n let hotlistResponse: DataResultWrapper<Hotlist> | null;\n\n try {\n if (this.state.phishingLists.length === 0) {\n return;\n }\n\n const lastDiffTimestamp = Math.max(\n ...this.state.phishingLists.map(({ lastUpdated }) => lastUpdated),\n );\n\n hotlistResponse = await this.#queryConfig<DataResultWrapper<Hotlist>>(\n `${METAMASK_HOTLIST_DIFF_URL}/${lastDiffTimestamp}`,\n );\n } finally {\n // Set `hotlistLastFetched` even for failed requests to prevent server from being overwhelmed with\n // traffic after a network disruption.\n this.update((draftState) => {\n draftState.hotlistLastFetched = fetchTimeNow();\n });\n }\n\n if (!hotlistResponse?.data) {\n return;\n }\n const hotlist = hotlistResponse.data;\n const newPhishingLists = this.state.phishingLists.map((phishingList) => {\n const updatedList = applyDiffs(\n phishingList,\n hotlist,\n phishingListNameKeyMap[phishingList.name],\n [],\n [],\n );\n\n return updatedList;\n });\n\n this.update((draftState) => {\n draftState.phishingLists = newPhishingLists;\n });\n this.updatePhishingDetector();\n }\n\n /**\n * Update the C2 domain blocklist.\n *\n * This should only be called from the `updateC2DomainBlocklist` function, which is a wrapper around\n * this function that prevents redundant configuration updates.\n */\n async #updateC2DomainBlocklist() {\n let c2DomainBlocklistResponse: C2DomainBlocklistResponse | null = null;\n\n try {\n c2DomainBlocklistResponse =\n await this.#queryConfig<C2DomainBlocklistResponse>(\n `${C2_DOMAIN_BLOCKLIST_URL}?timestamp=${roundToNearestMinute(\n this.state.c2DomainBlocklistLastFetched,\n )}`,\n );\n } finally {\n // Set `c2DomainBlocklistLastFetched` even for failed requests to prevent server from being overwhelmed with\n // traffic after a network disruption.\n this.update((draftState) => {\n draftState.c2DomainBlocklistLastFetched = fetchTimeNow();\n });\n }\n\n if (!c2DomainBlocklistResponse) {\n return;\n }\n\n const recentlyAddedC2Domains = c2DomainBlocklistResponse.recentlyAdded;\n const recentlyRemovedC2Domains = c2DomainBlocklistResponse.recentlyRemoved;\n\n const newPhishingLists = this.state.phishingLists.map((phishingList) => {\n const updatedList = applyDiffs(\n phishingList,\n [],\n phishingListNameKeyMap[phishingList.name],\n recentlyAddedC2Domains,\n recentlyRemovedC2Domains,\n );\n\n return updatedList;\n });\n\n this.update((draftState) => {\n draftState.phishingLists = newPhishingLists;\n });\n this.updatePhishingDetector();\n }\n\n async #queryConfig<ResponseType>(\n input: RequestInfo,\n ): Promise<ResponseType | null> {\n const response = await safelyExecute(\n () => fetch(input, { cache: 'no-cache' }),\n true,\n );\n\n switch (response?.status) {\n case 200: {\n return await response.json();\n }\n\n default: {\n return null;\n }\n }\n }\n}\n\nexport default PhishingController;\n\nexport type { PhishingDetectorResult };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/phishing-controller",
|
|
3
|
-
"version": "12.4.0-preview-
|
|
3
|
+
"version": "12.4.0-preview-b08aa8e7",
|
|
4
4
|
"description": "Maintains a periodically updated list of approved and unapproved website origins",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@metamask/base-controller": "^8.0.0",
|
|
51
|
-
"@metamask/controller-utils": "^11.
|
|
51
|
+
"@metamask/controller-utils": "^11.6.0",
|
|
52
52
|
"@noble/hashes": "^1.4.0",
|
|
53
53
|
"@types/punycode": "^2.1.0",
|
|
54
54
|
"ethereum-cryptography": "^2.1.2",
|