Nacre/tests/smoke/pages/fingerprint.html
astar76 68346f0edb S024: privacy mode that holds up (R1-16)
Firefox-consistent anti-fingerprinting script (canvas/WebGL/audio/font noise per run and site; common screen,
CPU, platform, touch and WebGL values; frames covered), paused per site, on in incognito. Privacy mode also
switches third-party cookie blocking and a Firefox-style Accept-Language in the vendored servo-net;
document.cookie is emptied in cross-site frames. Engine gaps fixed on the way: screen geometry (was 0x0),
document.fonts.check, a pass-through DynamicsCompressorNode. Settings sub-page and shield flyout explain it.
Tests: unit tests, privacy-mode/incognito/net smokes, Cover Your Tracks run recorded in
docs/engine/privacy-mode.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-12 17:13:08 -06:00

136 lines
8.3 KiB
HTML

<!DOCTYPE html>
<meta charset="utf-8">
<title>Fingerprint</title>
<!-- The fingerprint surfaces a page can read (S024), printed as JSON in #out and kept in window.fp.
The same values are read in a same-origin frame from markup (srcdoc; file:// frames are cross-origin) and in a frame made by script
(about:blank), so tests can check privacy mode covers frames too. Title becomes "FP done" when finished. -->
<style>
body { font: 13px monospace; margin: 12px; background: #fff; color: #111; }
pre { white-space: pre-wrap; margin: 0; }
iframe { width: 10px; height: 10px; border: 0; }
</style>
<pre id="out">reading…</pre>
<iframe id="static" srcdoc="<!DOCTYPE html><title>frame</title><p>frame"></iframe>
<script>
// FNV-1a over a string, as hex.
function hash(s) { let h = 2166136261; for (let i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 16777619); } return (h >>> 0).toString(16); }
// Everything that is read synchronously, from a window `W` (this one or a frame's).
function basics(W) {
const N = W.navigator, S = W.screen, out = {};
const get = (k, f) => { try { out[k] = f(); } catch (e) { out[k] = 'error: ' + e.message; } };
get('userAgent', () => N.userAgent);
get('appVersion', () => N.appVersion);
get('platform', () => N.platform);
get('vendor', () => N.vendor);
get('language', () => N.language);
get('languages', () => N.languages ? Array.from(N.languages) : null);
get('timezone', () => W.Intl.DateTimeFormat().resolvedOptions().timeZone);
get('timezoneOffset', () => new W.Date(2026, 0, 1).getTimezoneOffset());
get('locale', () => W.Intl.DateTimeFormat().resolvedOptions().locale);
get('hardwareConcurrency', () => N.hardwareConcurrency);
get('deviceMemory', () => N.deviceMemory === undefined ? null : N.deviceMemory);
get('maxTouchPoints', () => N.maxTouchPoints);
get('doNotTrack', () => N.doNotTrack === undefined ? null : N.doNotTrack);
get('globalPrivacyControl', () => N.globalPrivacyControl === undefined ? null : N.globalPrivacyControl);
get('cookieEnabled', () => N.cookieEnabled);
get('plugins', () => N.plugins ? N.plugins.length : null);
get('mimeTypes', () => N.mimeTypes ? N.mimeTypes.length : null);
get('pdfViewerEnabled', () => N.pdfViewerEnabled === undefined ? null : N.pdfViewerEnabled);
get('webdriver', () => N.webdriver === undefined ? null : N.webdriver);
get('screen', () => [S.width, S.height, S.availWidth, S.availHeight, S.colorDepth, S.pixelDepth].join(' '));
get('availOrigin', () => [S.availLeft, S.availTop].join(' '));
get('devicePixelRatio', () => W.devicePixelRatio);
get('window', () => [W.outerWidth, W.outerHeight, W.innerWidth, W.innerHeight].join(' '));
get('getBattery', () => typeof N.getBattery);
get('mediaDevices', () => typeof N.mediaDevices);
get('RTCPeerConnection', () => typeof W.RTCPeerConnection);
get('userAgentData', () => typeof N.userAgentData);
get('touchEvents', () => typeof W.TouchEvent + ' ' + (() => { try { W.document.createEvent('TouchEvent'); return 'createEvent'; } catch (e) { return e.name; } })());
get('gamepads', () => typeof N.getGamepads);
get('bluetooth', () => typeof N.bluetooth);
get('canvas', () => canvas(W));
get('canvasPixels', () => canvasPixels(W));
get('webgl', () => webgl(W));
get('fonts', () => fonts(W));
get('nativeLooking', () => [W.HTMLCanvasElement.prototype.toDataURL, W.CanvasRenderingContext2D.prototype.getImageData,
Object.getOwnPropertyDescriptor(W.Navigator.prototype, 'hardwareConcurrency').get]
.every(f => /\[native code\]/.test(W.Function.prototype.toString.call(f))));
return out;
}
function draw(W) {
const c = W.document.createElement('canvas'); c.width = 220; c.height = 40;
const x = c.getContext('2d');
x.textBaseline = 'top'; x.font = '16px Arial'; x.fillStyle = '#f60'; x.fillRect(100, 1, 62, 20);
x.fillStyle = '#069'; x.fillText('Nacre fingerprint 😃', 2, 15);
x.fillStyle = 'rgba(102, 204, 0, 0.7)'; x.fillText('Nacre fingerprint 😃', 4, 17);
return c;
}
// toDataURL twice: the two reads must match (noise stable inside a site).
function canvas(W) { const a = hash(draw(W).toDataURL()), b = hash(draw(W).toDataURL()); return a === b ? a : a + ' != ' + b; }
function canvasPixels(W) { const c = draw(W); return hash(Array.from(c.getContext('2d').getImageData(0, 0, c.width, c.height).data).join(',')); }
function webgl(W) {
const c = W.document.createElement('canvas'); c.width = 16; c.height = 16;
const gl = c.getContext('webgl') || c.getContext('experimental-webgl');
if (!gl) return null;
const ext = gl.getExtension('WEBGL_debug_renderer_info');
gl.clearColor(0.2, 0.4, 0.6, 1); gl.clear(gl.COLOR_BUFFER_BIT);
const px = new Uint8Array(16 * 16 * 4); gl.readPixels(0, 0, 16, 16, gl.RGBA, gl.UNSIGNED_BYTE, px);
return { vendor: gl.getParameter(gl.VENDOR), renderer: gl.getParameter(gl.RENDERER),
unmaskedVendor: ext ? gl.getParameter(ext.UNMASKED_VENDOR_WEBGL) : null,
unmaskedRenderer: ext ? gl.getParameter(ext.UNMASKED_RENDERER_WEBGL) : null,
version: gl.getParameter(gl.VERSION), extensions: (gl.getSupportedExtensions() || []).length,
maxTexture: gl.getParameter(gl.MAX_TEXTURE_SIZE), pixels: hash(Array.from(px).join(',')) };
}
// Installed fonts, the way fingerprinters measure them: text width against the generic fallbacks.
const FONTS = ['Arial', 'Helvetica', 'Times New Roman', 'Courier New', 'Verdana', 'Georgia', 'Comic Sans MS', 'Impact',
'DejaVu Sans', 'DejaVu Serif', 'Liberation Sans', 'Noto Sans', 'Noto Serif', 'Ubuntu', 'Cantarell', 'Roboto',
'Open Sans', 'Fira Sans', 'Inter', 'JetBrains Mono', 'Source Code Pro', 'Hack', 'Segoe UI', 'Calibri', 'Cambria',
'Tahoma', 'Lucida Grande', 'Menlo', 'Monaco', 'Consolas', 'Material Symbols Rounded', 'Noto Color Emoji'];
function fonts(W) {
const c = W.document.createElement('canvas').getContext('2d'), text = 'mmmmmmmmmmlli1WQ@#';
const width = f => { c.font = '48px ' + f; return c.measureText(text).width; };
const base = ['monospace', 'sans-serif', 'serif'].map(width);
const found = FONTS.filter(f => ['monospace', 'sans-serif', 'serif'].some((g, i) => width(`"${f}", ${g}`) !== base[i]));
return { count: found.length, hash: hash(found.join(',')), found };
}
// Audio: the classic OfflineAudioContext oscillator (+ compressor) sum.
function audio(W) {
return new Promise(done => {
try {
const Ctx = W.OfflineAudioContext || W.webkitOfflineAudioContext;
if (!Ctx) return done(null);
// Servo has no DynamicsCompressorNode: the oscillator alone where it's missing.
const ctx = new Ctx(1, 5000, 44100), osc = ctx.createOscillator();
osc.type = 'triangle'; osc.frequency.value = 10000;
if (ctx.createDynamicsCompressor) { const comp = ctx.createDynamicsCompressor(); osc.connect(comp); comp.connect(ctx.destination); }
else osc.connect(ctx.destination);
osc.start(0);
const t = setTimeout(() => done('timeout'), 4000);
ctx.startRendering().then(buf => { clearTimeout(t); const d = buf.getChannelData(0); let s = 0;
for (let i = 4500; i < 5000; i++) s += Math.abs(d[i]); done(s.toFixed(12)); }, e => done('error: ' + e.message));
} catch (e) { done('error: ' + e.message); }
});
}
async function run() {
const fp = basics(window);
fp.audio = await audio(window);
// A same-origin frame from markup, and an about:blank frame made by script (no injected scripts of its own).
await new Promise(r => { const f = document.getElementById('static'); if (f.contentDocument && f.contentDocument.readyState === 'complete') r(); else f.onload = r; });
const made = document.createElement('iframe'); document.body.appendChild(made);
const frames = { static: basics(document.getElementById('static').contentWindow), scripted: basics(made.contentWindow) };
// Which values differ from the top document's (should be none).
const keys = ['userAgent', 'platform', 'language', 'languages', 'timezone', 'hardwareConcurrency', 'deviceMemory', 'screen', 'webgl', 'canvas'];
fp.frameMismatch = {};
for (const [name, v] of Object.entries(frames)) fp.frameMismatch[name] = keys.filter(k => JSON.stringify(v[k]) !== JSON.stringify(fp[k]));
window.fp = fp;
document.getElementById('out').textContent = JSON.stringify(fp, null, 1);
document.title = 'FP done';
}
addEventListener('load', () => run().catch(e => { document.getElementById('out').textContent = 'error: ' + e.stack; document.title = 'FP error'; }));
</script>