Skip to content
Merged
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
26 changes: 26 additions & 0 deletions packages/client/src/collectors/environment-fonts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { EnvironmentalCollector } from './environment';

it('includes Menlo and Calibri in the existing font summary', () => {
const installed = new Set(['Arial', 'Menlo', 'Calibri']);
const canvas = {
font: '',
measureText(): { width: number } {
const family = /"([^"]+)"/.exec(this.font)?.[1];
return { width: family && installed.has(family) ? 105 : 100 };
},
};
const context = jest.spyOn(HTMLCanvasElement.prototype, 'getContext')
.mockReturnValue(canvas as unknown as CanvasRenderingContext2D);
try {
expect(new EnvironmentalCollector()._getFontsInfo()).toMatchObject({
supported: true,
count: 3,
hasMenlo: true,
hasCalibri: true,
hasSFPro: false,
hasSegoeUI: false,
});
} finally {
context.mockRestore();
}
});
2 changes: 2 additions & 0 deletions packages/client/src/collectors/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,9 @@ export class EnvironmentalCollector {
hasArial: detectedFonts.includes('Arial'),
hasTimesNewRoman: detectedFonts.includes('Times New Roman'),
hasSegoeUI: detectedFonts.includes('Segoe UI'),
hasCalibri: detectedFonts.includes('Calibri'),
hasSFPro: detectedFonts.includes('SF Pro'),
hasMenlo: detectedFonts.includes('Menlo'),
hasDejaVuSans: detectedFonts.includes('DejaVu Sans'),
supported: true
};
Expand Down
65 changes: 23 additions & 42 deletions packages/webdecoy/src/detection/detectors/advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,56 +130,37 @@ export function analyzeCSSMediaQueries(cssMedia: CSSMediaQueriesInfo | undefined
return detections;
}

export function analyzeFonts(fontsInfo: FontsInfo | undefined, userAgent: string): Detection[] {
if (!fontsInfo || !fontsInfo.supported) return [];
const detections: Detection[] = [];
export function analyzeFonts(fontsInfo: FontsInfo, platform?: string): Detection[] {
const count = fontsInfo.count ?? 0;

if (count < 3) {
detections.push({
category: 'headless',
score: 0.5,
confidence: 0.5,
reason: `Very few fonts detected (${count})`,
});
if (fontsInfo.supported !== true || !Number.isInteger(count) || count < 3 || typeof platform !== 'string') {
return [];
}

const ua = (userAgent || '').toLowerCase();
// A missing flag on an older payload means the font was not reported.
const hasWindowsFonts = fontsInfo.hasSegoeUI === true || fontsInfo.hasCalibri === true;
const hasMacFonts = fontsInfo.hasSFPro === true || fontsInfo.hasMenlo === true;
const noWindowsFonts = fontsInfo.hasSegoeUI === false && fontsInfo.hasCalibri === false;
const noMacFonts = fontsInfo.hasSFPro === false && fontsInfo.hasMenlo === false;

if (ua.includes('windows') && fontsInfo.hasSegoeUI === false && count > 5) {
detections.push({
category: 'bot',
if (/^(mac|iphone|ipad|ipod)/i.test(platform) && hasWindowsFonts && noMacFonts) {
return [{
category: 'automation',
score: 0.5,
confidence: 0.6,
reason: 'Windows UA but Segoe UI font not detected',
});
}

if (
(ua.includes('mac os x') || ua.includes('macintosh')) &&
fontsInfo.hasSFPro === false &&
!ua.includes('10_15') &&
!ua.includes('10_14') &&
count > 5
) {
detections.push({
category: 'bot',
score: 0.3,
confidence: 0.4,
reason: 'Modern macOS UA but SF Pro font not detected',
});
confidence: 0.5,
reason: `Font set contradicts platform (Windows faces while claiming ${platform})`,
}];
}

if (ua.includes('linux') && !ua.includes('android') && fontsInfo.hasDejaVuSans === false && count > 5) {
detections.push({
category: 'bot',
score: 0.4,
if (/^win/i.test(platform) && hasMacFonts && noWindowsFonts) {
return [{
category: 'automation',
score: 0.5,
confidence: 0.5,
reason: 'Linux UA but DejaVu Sans font not detected',
});
reason: `Font set contradicts platform (macOS faces while claiming ${platform})`,
}];
}

return detections;
return [];
}

const PERMISSION_API_KEYS = [
Expand Down Expand Up @@ -239,15 +220,15 @@ export function analyzeDOMRect(domRectInfo?: DOMRectInfo): Detection[] {
}

/** Run every advanced-fingerprint detector present in the signals. */
export function analyzeAdvancedSignals(signals: Signals, userAgent: string): Detection[] {
export function analyzeAdvancedSignals(signals: Signals): Detection[] {
const detections: Detection[] = [];
const env = signals.environmental ?? {};

if (env.webrtcInfo) detections.push(...analyzeWebRTC(env.webrtcInfo));
if (env.speechInfo) detections.push(...analyzeSpeechAPI(env.speechInfo));
if (env.workerConsistency) detections.push(...analyzeWorkerConsistency(env.workerConsistency));
if (env.cssMediaQueries) detections.push(...analyzeCSSMediaQueries(env.cssMediaQueries, signals));
if (env.fontsInfo) detections.push(...analyzeFonts(env.fontsInfo, userAgent));
if (env.fontsInfo) detections.push(...analyzeFonts(env.fontsInfo, env.navigator?.platform));
if (env.permissionsInfo) detections.push(...analyzePermissions(env.permissionsInfo));
if (env.domRectFingerprint) detections.push(...analyzeDOMRect(env.domRectFingerprint));
if (env.audioInfo) detections.push(...analyzeAudioContext(env.audioInfo));
Expand Down
19 changes: 15 additions & 4 deletions packages/webdecoy/src/detection/engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import { DetectionEngine } from './engine';
import fontPlatformFixtures from './fixtures/font-platform.json';
import inputModalityFixtures from './fixtures/input-modality.json';
import type { DetectionContext, Signals, Verdict } from './types';

Expand Down Expand Up @@ -394,11 +395,21 @@ describe('advanced fingerprint detection', () => {
expect(hasReasonIncluding(v, 'Worker/main thread mismatch')).toBe(true);
});

it('detects Windows UA without Segoe UI', () => {
const v = score({
environmental: { fontsInfo: { supported: true, count: 10, hasSegoeUI: false, hasSFPro: false, hasDejaVuSans: false } },
it.each(fontPlatformFixtures.cases)('matches the reference for $name', ({ fonts, platform, reasons }) => {
const verdict = score({ environmental: { fontsInfo: fonts, navigator: { platform } } });
expect(verdict.detections.filter(({ reason }) => /font/i.test(reason))).toEqual(
reasons.map(reason => ({ category: 'automation', score: 0.5, confidence: 0.5, reason })),
);
});

it('keeps legacy font summaries neutral when a native font flag was not reported', () => {
const verdict = score({
environmental: {
fontsInfo: { supported: true, count: 12, hasSegoeUI: true, hasSFPro: false },
navigator: { platform: 'MacIntel' },
},
});
expect(hasReasonIncluding(v, 'Segoe UI')).toBe(true);
expect(verdict.detections.filter(({ reason }) => /font/i.test(reason))).toEqual([]);
});

it('detects CSS pointer/touch mismatch', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/webdecoy/src/detection/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class DetectionEngine {
if (signals.formAnalysis) {
detections.push(...analyzeFormInteraction(signals.formAnalysis));
}
detections.push(...analyzeAdvancedSignals(signals, userAgent));
detections.push(...analyzeAdvancedSignals(signals));

// --- Aggregate -------------------------------------------------------------
const categoryScores = calculateCategoryScores(detections, this.weights);
Expand Down
85 changes: 85 additions & 0 deletions packages/webdecoy/src/detection/fixtures/font-platform.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"reference": {
"version": "v1.51.1",
"commit": "b769817ffa4069a80217dc5b4cef9ce597077c07"
},
"cases": [
{
"name": "a Windows font on a reported Mac platform",
"platform": "MacIntel",
"fonts": {
"supported": true,
"count": 12,
"hasSegoeUI": false,
"hasCalibri": true,
"hasSFPro": false,
"hasMenlo": false
},
"reasons": [
"Font set contradicts platform (Windows faces while claiming MacIntel)"
]
},
{
"name": "a Mac font on a reported Windows platform",
"platform": "Win32",
"fonts": {
"supported": true,
"count": 12,
"hasSegoeUI": false,
"hasCalibri": false,
"hasSFPro": false,
"hasMenlo": true
},
"reasons": [
"Font set contradicts platform (macOS faces while claiming Win32)"
]
},
{
"name": "a Mac with both native and cross-platform fonts",
"platform": "MacIntel",
"fonts": {
"supported": true,
"count": 12,
"hasSegoeUI": true,
"hasCalibri": true,
"hasSFPro": false,
"hasMenlo": true
},
"reasons": []
},
{
"name": "a small visible font inventory",
"platform": "MacIntel",
"fonts": {
"supported": true,
"count": 2,
"hasSegoeUI": true,
"hasCalibri": false,
"hasSFPro": false,
"hasMenlo": false
},
"reasons": []
},
{
"name": "a browser with font probing unavailable",
"platform": "MacIntel",
"fonts": {
"supported": false
},
"reasons": []
},
{
"name": "a Windows device missing stock fonts",
"platform": "Win32",
"fonts": {
"supported": true,
"count": 8,
"hasSegoeUI": false,
"hasCalibri": false,
"hasSFPro": false,
"hasMenlo": false
},
"reasons": []
}
]
}
2 changes: 2 additions & 0 deletions packages/webdecoy/src/detection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ export interface FontsInfo {
supported?: boolean;
count?: number;
hasSegoeUI?: boolean;
hasCalibri?: boolean;
hasSFPro?: boolean;
hasMenlo?: boolean;
hasDejaVuSans?: boolean;
[key: string]: unknown;
}
Expand Down
Loading