From 5461f538d4c6ef09a3c3bd3cd47e7e99bb599012 Mon Sep 17 00:00:00 2001 From: Renzo Canepa Date: Mon, 9 Sep 2024 16:45:26 -0300 Subject: [PATCH] Revert "[Fraud] Get Fingerprinted Visitor ID (#93952)" (#94346) This reverts commit 1e83dc8c4be2e1968c23672dcfe0e59c94f22651. --- client/lib/wp/browser.js | 3 -- client/lib/wp/handlers/fingerprint.js | 34 ---------------------- client/package.json | 1 - client/webpack.config.js | 3 -- packages/fingerprintjs/package.json | 1 - packages/fingerprintjs/src/agent.test.ts | 3 +- packages/fingerprintjs/src/agent.ts | 5 ++-- packages/fingerprintjs/src/global.d.ts | 1 - packages/fingerprintjs/src/index.ts | 36 +++++++++++++++--------- packages/fingerprintjs/tsconfig.json | 5 +--- yarn.lock | 3 +- 11 files changed, 30 insertions(+), 65 deletions(-) delete mode 100644 client/lib/wp/handlers/fingerprint.js diff --git a/client/lib/wp/browser.js b/client/lib/wp/browser.js index 21838dae8823a..e734e3b366ddb 100644 --- a/client/lib/wp/browser.js +++ b/client/lib/wp/browser.js @@ -5,7 +5,6 @@ import wpcomProxyRequest from 'wpcom-proxy-request'; import * as oauthToken from 'calypso/lib/oauth-token'; import wpcomSupport from 'calypso/lib/wp/support'; import wpcomXhrWrapper, { jetpack_site_xhr_wrapper } from 'calypso/lib/wpcom-xhr-wrapper'; -import { injectFingerprint } from './handlers/fingerprint'; import { injectGuestSandboxTicketHandler } from './handlers/guest-sandbox-ticket'; import { injectLocalization } from './localization'; @@ -48,8 +47,6 @@ injectLocalization( wpcom ); injectGuestSandboxTicketHandler( wpcom ); -injectFingerprint( wpcom ); - /** * Expose `wpcom` */ diff --git a/client/lib/wp/handlers/fingerprint.js b/client/lib/wp/handlers/fingerprint.js deleted file mode 100644 index 3306240488984..0000000000000 --- a/client/lib/wp/handlers/fingerprint.js +++ /dev/null @@ -1,34 +0,0 @@ -import { load } from '@automattic/fingerprintjs'; - -let fingerprint; -async function loadFingerprint() { - const agent = await load( { monitoring: false } ); - const result = await agent.get(); - fingerprint = result.visitorId; -} -if ( document.readyState !== 'loading' ) { - loadFingerprint(); -} else { - document.addEventListener( 'DOMContentLoaded', loadFingerprint ); -} - -/** - * Updates `wpcom` to pass a fingerprint if one is present. - * @param {Object} wpcom Original WPCOM instance - */ -export function injectFingerprint( wpcom ) { - const request = wpcom.request.bind( wpcom ); - - wpcom.request = function ( params, callback ) { - if ( fingerprint ) { - params = { - ...params, - headers: { - ...( params.headers || {} ), - 'X-Fingerprint': fingerprint, - }, - }; - } - return request( params, callback ); - }; -} diff --git a/client/package.json b/client/package.json index 5438f03459516..500045e15cb3f 100644 --- a/client/package.json +++ b/client/package.json @@ -39,7 +39,6 @@ "@automattic/domains-table": "workspace:^", "@automattic/explat-client": "workspace:^", "@automattic/explat-client-react-helpers": "workspace:^", - "@automattic/fingerprintjs": "workspace:^", "@automattic/format-currency": "workspace:^", "@automattic/generate-password": "workspace:^", "@automattic/global-styles": "workspace:^", diff --git a/client/webpack.config.js b/client/webpack.config.js index 49b39abd33a2a..b3f22dd3fd93a 100644 --- a/client/webpack.config.js +++ b/client/webpack.config.js @@ -306,9 +306,6 @@ const webpackConfig = { !! process.env.FORCE_REDUCED_MOTION || false ), __i18n_text_domain__: JSON.stringify( 'default' ), - fingerprintJsVersion: JSON.stringify( - require( '../packages/fingerprintjs/package.json' ).version - ), global: 'window', } ), // Node polyfills diff --git a/packages/fingerprintjs/package.json b/packages/fingerprintjs/package.json index b4699dacb7127..8ecc90e8a9981 100644 --- a/packages/fingerprintjs/package.json +++ b/packages/fingerprintjs/package.json @@ -25,7 +25,6 @@ "url": "https://github.com/fingerprintjs/fingerprintjs/issues" }, "homepage": "https://github.com/fingerprintjs/fingerprintjs", - "calypso:src": "src/index.ts", "main": "dist/fp.cjs.js", "module": "dist/fp.esm.js", "types": "dist/fp.d.ts", diff --git a/packages/fingerprintjs/src/agent.test.ts b/packages/fingerprintjs/src/agent.test.ts index 719ec0d7f334f..e0639103950f7 100644 --- a/packages/fingerprintjs/src/agent.test.ts +++ b/packages/fingerprintjs/src/agent.test.ts @@ -1,3 +1,4 @@ +import { version } from '../package.json'; import { withMockProperties } from '../tests/utils'; import { load as loadAgent } from './agent'; import { sources } from './sources'; @@ -12,7 +13,7 @@ describe( 'Agent', () => { expect( result.visitorId ).not.toEqual( '' ); expect( typeof result.confidence.score ).toBe( 'number' ); expect( typeof result.confidence.comment ).toBe( 'string' ); - expect( result.version ).toBe( window.fingerprintJsVersion ); + expect( result.version ).toBe( version ); const expectedComponents = Object.keys( sources ).sort() as Array< keyof typeof sources >; expect( expectedComponents.length ).toBeGreaterThan( 10 ); // To check the test itself diff --git a/packages/fingerprintjs/src/agent.ts b/packages/fingerprintjs/src/agent.ts index 90430d321ebc5..52174c6cdf9e0 100644 --- a/packages/fingerprintjs/src/agent.ts +++ b/packages/fingerprintjs/src/agent.ts @@ -1,3 +1,4 @@ +import { version } from '../package.json'; import { requestIdleCallbackIfAvailable } from './utils/async'; import { UnknownComponents } from './utils/entropy_source'; import { x64hash128 } from './utils/hashing'; @@ -127,7 +128,7 @@ function makeLazyGetResult( components: BuiltinComponents ): GetResult { }, confidence, components, - version: window.fingerprintJsVersion, + version, }; } @@ -189,7 +190,7 @@ function monitor() { const request = new XMLHttpRequest(); request.open( 'get', - `https://m1.openfpcdn.io/fingerprintjs/v${ window.fingerprintJsVersion }/npm-monitoring`, + `https://m1.openfpcdn.io/fingerprintjs/v${ version }/npm-monitoring`, true ); request.send(); diff --git a/packages/fingerprintjs/src/global.d.ts b/packages/fingerprintjs/src/global.d.ts index ae1c94855d187..2aefe581614f4 100644 --- a/packages/fingerprintjs/src/global.d.ts +++ b/packages/fingerprintjs/src/global.d.ts @@ -4,7 +4,6 @@ interface Window { webkitOfflineAudioContext?: OfflineAudioContext; openDatabase?( ...args: unknown[] ): void; __fpjs_d_m?: unknown; - fingerprintJsVersion: string; } interface Navigator { diff --git a/packages/fingerprintjs/src/index.ts b/packages/fingerprintjs/src/index.ts index f3bba747d68f2..978ca1a8e352a 100644 --- a/packages/fingerprintjs/src/index.ts +++ b/packages/fingerprintjs/src/index.ts @@ -1,23 +1,31 @@ -import { load, hashComponents, componentsToDebugString } from './agent'; +import { + load, + Agent, + LoadOptions, + GetOptions, + GetResult, + hashComponents, + componentsToDebugString, +} from './agent'; +import { BuiltinComponents } from './sources'; +import { Confidence } from './confidence'; +import { Component, UnknownComponents } from './utils/entropy_source'; import { x64hash128 } from './utils/hashing'; -import type { Agent, GetOptions, GetResult, LoadOptions } from './agent'; -import type { BuiltinComponents } from './sources'; -import type { Component, UnknownComponents } from './utils/entropy_source'; -import type { Confidence } from './confidence'; // Exports that are under Semantic versioning -export { load, hashComponents, componentsToDebugString }; -export type { +export { + load, Agent, - BuiltinComponents, - Component, - Confidence, + LoadOptions, GetOptions, GetResult, - LoadOptions, + hashComponents, + componentsToDebugString, + Component, UnknownComponents, + BuiltinComponents, + Confidence, }; - // The default export is a syntax sugar (`import * as FP from '...' → import FP from '...'`). // It should contain all the public exported values. export default { load, hashComponents, componentsToDebugString }; @@ -40,7 +48,9 @@ export { } from './utils/browser'; export { loadSources, + Source, + SourcesToComponents, transformSource, // Not used here but adds only 222 uncompressed (60 compressed) bytes of code + UnknownSources, } from './utils/entropy_source'; -export type { Source, SourcesToComponents, UnknownSources } from './utils/entropy_source'; export { withIframe } from './utils/dom'; diff --git a/packages/fingerprintjs/tsconfig.json b/packages/fingerprintjs/tsconfig.json index 27f4b535377fd..2a7a258c56b52 100644 --- a/packages/fingerprintjs/tsconfig.json +++ b/packages/fingerprintjs/tsconfig.json @@ -9,14 +9,11 @@ "importHelpers": true, "noErrorTruncation": true, "strict": true, - "composite": false, "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, "isolatedModules": false, - "types": [ "node", "jasmine" ], - "typeRoots": [ "../../node_modules/@types", "node_modules/@types/jasmine" ], - "sourceMap": false, + "types": [ "jasmine" ], "declarationDir": "dist/types", "outDir": "dist/esm", "rootDir": "." diff --git a/yarn.lock b/yarn.lock index 3711b34300251..9ad3e810f8007 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1020,7 +1020,7 @@ __metadata: languageName: unknown linkType: soft -"@automattic/fingerprintjs@workspace:^, @automattic/fingerprintjs@workspace:packages/fingerprintjs": +"@automattic/fingerprintjs@workspace:packages/fingerprintjs": version: 0.0.0-use.local resolution: "@automattic/fingerprintjs@workspace:packages/fingerprintjs" dependencies: @@ -12685,7 +12685,6 @@ __metadata: "@automattic/domains-table": "workspace:^" "@automattic/explat-client": "workspace:^" "@automattic/explat-client-react-helpers": "workspace:^" - "@automattic/fingerprintjs": "workspace:^" "@automattic/format-currency": "workspace:^" "@automattic/generate-password": "workspace:^" "@automattic/global-styles": "workspace:^"