From e7d44b099d863d82ffd8af3f7852381c9549427a Mon Sep 17 00:00:00 2001 From: z0ccc Date: Wed, 8 Sep 2021 19:16:17 -0400 Subject: [PATCH] Detecting tor browser --- frontend/src/components/DataBlock.js | 46 +++++++++++++++++++++++++++ frontend/src/components/ScanBlocks.js | 2 ++ frontend/src/components/TableRow.js | 4 ++- frontend/src/components/main.js | 31 +++++++----------- 4 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 frontend/src/components/DataBlock.js diff --git a/frontend/src/components/DataBlock.js b/frontend/src/components/DataBlock.js new file mode 100644 index 0000000..4919869 --- /dev/null +++ b/frontend/src/components/DataBlock.js @@ -0,0 +1,46 @@ +/* eslint-disable no-unused-vars */ +import { useState, useEffect } from 'react'; +import Bowser from 'bowser'; +import ScanBlock from './ScanBlock'; +import Table from './Table'; +import { + checkNavigatorProperties, + checkWebWorker, + checkScreenProperties, + getBrowser, +} from './main'; + +const NavigatorBlock = () => { + const [firstRender, setfirstRender] = useState(true); + const [workerData, setWorkerData] = useState(''); + const [userAgent, setUserAgent] = useState(); + + useEffect(() => { + checkWebWorker('userAgent', setWorkerData); + }, []); + + useEffect(() => { + if (!workerData) { + setUserAgent(Bowser.parse(navigator.userAgent)); + } else { + setUserAgent(Bowser.parse(workerData)); + } + }, [workerData]); + + return ( + +

Data

+ {userAgent && ( +
+ {getBrowser(userAgent.browser.name)} {userAgent.browser.version} +
+ )} +

+ Explanation: JavaScript can be used to find information about + your hardware. This information can be used to create a fingerprint. +

+
+ ); +}; + +export default NavigatorBlock; diff --git a/frontend/src/components/ScanBlocks.js b/frontend/src/components/ScanBlocks.js index 12341a9..282d608 100644 --- a/frontend/src/components/ScanBlocks.js +++ b/frontend/src/components/ScanBlocks.js @@ -1,4 +1,5 @@ /* eslint-disable no-unused-vars */ +import DataBlock from './DataBlock'; import NavigatorBlock from './NavigatorBlock'; import ScreenBlock from './ScreenBlock'; import FingerprintBlock from './FingerprintBlock'; @@ -11,6 +12,7 @@ import FiltersBlock from './FiltersBlock'; const ScanBlocks = () => ( <> + {/* diff --git a/frontend/src/components/TableRow.js b/frontend/src/components/TableRow.js index 8724afe..4010de2 100644 --- a/frontend/src/components/TableRow.js +++ b/frontend/src/components/TableRow.js @@ -34,7 +34,9 @@ const TableRow = ({ item }) => { {ele} ))} -
{workerData}
+
+ {workerData && <>{`Did not match web worker (${workerData})`}} +
); diff --git a/frontend/src/components/main.js b/frontend/src/components/main.js index 787c81c..330520f 100644 --- a/frontend/src/components/main.js +++ b/frontend/src/components/main.js @@ -1,11 +1,14 @@ /* eslint-disable no-unused-vars */ /* eslint-disable dot-notation */ +// import Bowser from 'bowser'; + export { getNavigator, checkNavigatorProperties, checkWebWorker, getScreen, checkScreenProperties, + getBrowser, }; const getDeviceMemory = () => ({ @@ -344,25 +347,6 @@ const checkScreenPrototype = (key) => { return null; }; -// const checkWindowProperties = (key) => { -// const list = []; -// if ( -// Object.getOwnPropertyDescriptor(Window.prototype, key).value !== undefined -// ) { -// list.push('Failed descriptor.value undefined'); -// } -// // try { -// // // eslint-disable-next-line no-unused-vars -// // const check = Window.prototype[key]; -// // list.push('Failed Navigator.prototype'); -// // } catch (err) { -// // // eslint-disable-next-line no-unused-vars -// // const check = ''; -// // } - -// return list.toString().split(',').join('
'); -// }; - const checkWidth = () => { if (window.screen.availWidth > window.screen.width) { return 'Avail width is wider then width'; @@ -388,7 +372,14 @@ const checkWebWorker = (key, setWorkerData) => { event.data !== undefined && event.data.toString() !== navigator[key].toString() ) { - setWorkerData(`Did not match web worker (${event.data.toString()})`); + setWorkerData(event.data.toString()); } }; }; + +const getBrowser = (userAgent) => { + if (navigator.brave) { + return 'Brave'; + } + return userAgent; +};