Skip to content

Commit

Permalink
feat: Import reusable instrumentation from the OpenWPM repository
Browse files Browse the repository at this point in the history
(at the time of the merge of openwpm/OpenWPM#221)
  • Loading branch information
motin committed Oct 2, 2018
1 parent 743d765 commit 11cf01e
Show file tree
Hide file tree
Showing 9 changed files with 1,724 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"name": "openwpm-webext-instrumentation",
"version": "0.1.0",
"description": "Allows WebExtensions to track and monitor privacy-related browsing behavior",
"author": "OpenWPM Contributors",
"license": "GPL v3",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
"module": "build/module/index.js",
"repository": "https://github.com/motin/openwpm-webext-instrumentation",
"license": "MIT",
"keywords": [],
"scripts": {
"info": "npm-scripts-info",
Expand Down
80 changes: 80 additions & 0 deletions src/background/cookie-instrument.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// import { Cc, Ci } from 'chrome';
// import events from 'sdk/system/events';
// import { data } from 'sdk/self';

let loggingDB;
export const setLoggingDB = function($loggingDB) {
loggingDB = $loggingDB;
};

export const run = function(crawlID) {
// Instrument cookie changes
browser.cookies.onChanged.addListener(function(changeInfo) {
// Ignore requests made by extensions
/*
if (details.originUrl.indexOf("moz-extension://") > -1) {
return;
}
*/
console.log(
"Cookie changed: " +
"\n * Cookie: " +
JSON.stringify(changeInfo.cookie) +
"\n * Cause: " +
changeInfo.cause +
"\n * Removed: " +
changeInfo.removed,
changeInfo
);
});
/*
events.on("cookie-changed", function(event) {
var data = event.data;
// TODO: Support other cookie operations
if(data == "deleted" || data == "added" || data == "changed") {
var update = {};
update["change"] = loggingDB.escapeString(data);
update["crawl_id"] = crawlID;
var cookie = event.subject.QueryInterface(Ci.nsICookie2);
// Creation time (in microseconds)
var creationTime = new Date(cookie.creationTime / 1000); // requires milliseconds
update["creationTime"] = creationTime.toLocaleFormat('%Y-%m-%d %H:%M:%S');
// Expiry time (in seconds)
// May return ~Max(int64). I believe this is a session
// cookie which doesn't expire. Sessions cookies with
// non-max expiry time expire after session or at expiry.
var expiryTime = cookie.expiry; // returns seconds
if (expiryTime == 9223372036854776000) {
var expiryTimeString = '9999-12-31 23:59:59';
} else {
var expiryTimeDate = new Date(expiryTime * 1000) // requires milliseconds
var expiryTimeString = expiryTimeDate.toLocaleFormat('%Y-%m-%d %H:%M:%S');
}
update["expiry"] = expiryTimeString;
update["is_http_only"] = loggingDB.boolToInt(cookie.isHttpOnly);
update["is_session"] = loggingDB.boolToInt(cookie.isSession);
// Accessed time (in microseconds)
var lastAccessedTime = new Date(cookie.lastAccessed / 1000); // requires milliseconds
update["last_accessed"] = lastAccessedTime.toLocaleFormat('%Y-%m-%d %H:%M:%S');
update["raw_host"] = loggingDB.escapeString(cookie.rawHost);
cookie = cookie.QueryInterface(Ci.nsICookie);
update["expires"] = cookie.expires;
update["host"] = loggingDB.escapeString(cookie.host);
update["is_domain"] = loggingDB.boolToInt(cookie.isDomain);
update["is_secure"] = loggingDB.boolToInt(cookie.isSecure);
update["name"] = loggingDB.escapeString(cookie.name);
update["path"] = loggingDB.escapeString(cookie.path);
update["policy"] = cookie.policy;
update["status"] = cookie.status;
update["value"] = loggingDB.escapeString(cookie.value);
loggingDB.saveRecord("javascript_cookies", update);
}
}, true);
*/
};
Loading

0 comments on commit 11cf01e

Please sign in to comment.