Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/systemInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* For a full copy of the LGPL and ethical contribution guidelines, please refer to the `COPYRIGHT.md` and `NOTICE.md` files.
*/
import { SystemInfo} from './types.js';
import Bowser from './bowser/bowser.js';
import { detectIncognito } from './incognito.js';
import { getMockSystemInfo } from './mock.js';
import { detectAdBlockers } from './adblocker.js';
Expand Down Expand Up @@ -99,6 +100,30 @@ export function detectBot(): { isBot: boolean; signals: string[]; confidence: nu
signals.push('weak:unusual-concurrency');
}

// CSS pointer/hover and screen resolution checks for desktop OS
let isDesktop = false;
try {
const parsed = Bowser.parse(navigator.userAgent);
isDesktop = parsed.platform?.type === 'desktop';
} catch {
isDesktop = /Linux|Windows|Macintosh|X11/.test(navigator.userAgent) && !/Android|iPhone|iPad|iPod/.test(navigator.userAgent);
}

if (isDesktop) {
if (window.matchMedia) {
const hoverNone = window.matchMedia('(hover: none)').matches;
const pointerNone = !window.matchMedia('(pointer: fine)').matches && !window.matchMedia('(pointer: coarse)').matches;
if (hoverNone || pointerNone) {
signals.push('strong:desktop-no-pointer-hover-mismatch');
}
}
if (window.screen) {
if (window.screen.width === 800 && window.screen.height === 600) {
signals.push('medium:desktop-default-headless-resolution');
}
}
}

// Calculate confidence score
let confidence = 0.5;
confidence += signals.filter(s => s.startsWith('strong:')).length * confidenceWeights.strong;
Expand Down
46 changes: 46 additions & 0 deletions test/e2e/cypress/e2e/unit/core.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,50 @@ describe('core system modules', () => {
expect(vpn.vpn).to.have.property('probability');
});
});

it('detects bot characteristics', () => {
cy.loadFingerprintOSS().then((fp) => {
const result = fp.detectBot();
expect(result).to.be.ok;
expect(result.isBot).to.be.a('boolean');
expect(result.signals).to.be.an('array');
expect(result.confidence).to.be.a('number');
});
});

it('detects desktop pointer/hover mismatch bot signal', () => {
cy.visit('/');
cy.window().then((win) => {
Object.defineProperty(win.navigator, 'userAgent', {
value: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36',
configurable: true
});
cy.stub(win, 'matchMedia').callsFake((query) => {
if (query === '(hover: none)') return { matches: true };
if (query === '(pointer: fine)') return { matches: false };
if (query === '(pointer: coarse)') return { matches: false };
return { matches: false };
});

const result = win.fingerprintOSS.detectBot();
expect(result.signals).to.include('strong:desktop-no-pointer-hover-mismatch');
});
});

it('detects desktop headless resolution bot signal', () => {
cy.visit('/');
cy.window().then((win) => {
Object.defineProperty(win.navigator, 'userAgent', {
value: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36',
configurable: true
});
Object.defineProperty(win, 'screen', {
value: { width: 800, height: 600 },
configurable: true
});

const result = win.fingerprintOSS.detectBot();
expect(result.signals).to.include('medium:desktop-default-headless-resolution');
});
});
});
15 changes: 10 additions & 5 deletions test/e2e/cypress/e2e/unit/hash-serialization.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ describe('hashing and serialization', () => {
it('serializes output to JSON', () => {
cy.loadFingerprintOSS().then((fp) => {
return fp.getSystemInfo().then((info) => {
return fp.fetchGeolocationInfo().then((geo) => {
return fp.generateJSON(geo, info, 0.5).then((result) => {
expect(result).to.be.ok;
expect(result).to.have.property('hash');
});
const geoMock = {
ipAddress: '127.0.0.1',
country: { isoCode: 'US', name: 'United States' },
city: { name: 'New York', geonameId: 5128581 },
location: { accuracyRadius: 10, latitude: 40.7128, longitude: -74.0060, timeZone: 'America/New_York' },
traits: { isAnonymous: false, isAnonymousProxy: false, isAnonymousVpn: false, network: '127.0.0.1/32' }
};
return fp.generateJSON(geoMock, info, 0.5).then((result) => {
expect(result).to.be.ok;
expect(result).to.have.property('hash');
});
});
});
Expand Down
Loading