Skip to content

Commit b825129

Browse files
committed
Implement fingerprinting in the FirefoxDriver
The FirefoxDriver will flag its presence by setting window.navigator.webdriver === true on every page. See: https://w3c.github.io/webdriver/webdriver-spec.html#fingerprinting For now, the original fingerprinting method (setting an attribute on documentElement) remains.
1 parent 8666096 commit b825129

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

javascript/firefox-driver/extension/content/server.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,35 @@ try {
3535
// _browser window_ (not chrome window). Multiple tabs in the same window will
3636
// share a FirefoxDriver and DomMessenger instance.
3737
window.addEventListener('load', function(e) {
38+
// http://w3c.github.io/webdriver/webdriver-spec.html#security-and-privacy
39+
var appcontent = document.getElementById('appcontent');
40+
if (appcontent) {
41+
appcontent.addEventListener('DOMContentLoaded', function(e) {
42+
var doc = e.originalTarget || e.target;
43+
var isSvg = doc.documentElement.nodeName == 'svg';
44+
var script = isSvg ?
45+
doc.createElementNS('http://www.w3.org/2000/svg', 'script') :
46+
doc.createElement('script');
47+
script.setAttribute('type', 'text/javascript');
48+
script.textContent = '(' + function() {
49+
Object.defineProperty(window.navigator, 'webdriver', {
50+
value: true,
51+
configurable: false,
52+
enumerable: true,
53+
writable: false
54+
});
55+
} + ')()';
56+
doc.documentElement.appendChild(script);
57+
doc.documentElement.removeChild(script);
58+
});
59+
}
60+
61+
// old fingerprinting path
3862
var server = Components.classes['@googlecode.com/webdriver/fxdriver;1']
3963
.createInstance()
4064
.wrappedJSObject;
4165

4266
if (!domMessenger) {
43-
var appcontent = document.getElementById('appcontent');
4467
if (appcontent) {
4568
try {
4669
var commandProcessor = Components.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2015 Selenium committers
2+
// Copyright 2015 Software Freedom Conservancy
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
'use strict';
17+
18+
var assert = require('../testing/assert'),
19+
test = require('../lib/test'),
20+
Pages = test.Pages;
21+
22+
23+
test.suite(function(env) {
24+
var browsers = env.browsers;
25+
26+
var driver;
27+
test.before(function() {
28+
driver = env.builder().build();
29+
});
30+
31+
test.after(function() {
32+
driver.quit();
33+
});
34+
35+
describe('fingerprinting', function() {
36+
test.it('it should fingerprint the navigator object', function() {
37+
driver.get(Pages.simpleTestPage);
38+
assert(driver.executeScript('return navigator.webdriver')).equalTo(true);
39+
});
40+
41+
test.it('fingerprint must not be writable', function() {
42+
driver.get(Pages.simpleTestPage);
43+
assert(driver.executeScript(
44+
'navigator.webdriver = "ohai"; return navigator.webdriver'))
45+
.equalTo(true);
46+
});
47+
48+
test.it('leaves fingerprint on svg pages', function() {
49+
driver.get(Pages.svgPage);
50+
assert(driver.executeScript('return navigator.webdriver')).equalTo(true);
51+
});
52+
});
53+
54+
// Currently only implemented in firefox.
55+
}, {browsers: ['firefox']});

0 commit comments

Comments
 (0)