Skip to content

Commit

Permalink
Bug 1162205 - Don't import encrypted cookies from Chrome. r=mak a=lma…
Browse files Browse the repository at this point in the history
  • Loading branch information
mnoorenberghe committed May 8, 2015
1 parent 4c4c083 commit 1594821
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 6 deletions.
7 changes: 5 additions & 2 deletions browser/components/migration/ChromeProfileMigrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,11 @@ function GetCookiesResource(aProfileFolder) {

migrate: function(aCallback) {
let dbConn = Services.storage.openUnsharedDatabase(cookiesFile);
let stmt = dbConn.createAsyncStatement(
"SELECT host_key, path, name, value, secure, httponly, expires_utc FROM cookies");
// We don't support decrypting cookies yet so only import plaintext ones.
let stmt = dbConn.createAsyncStatement(`
SELECT host_key, name, value, path, expires_utc, secure, httponly, encrypted_value
FROM cookies
WHERE length(encrypted_value) = 0`);

stmt.executeAsync({
handleResult : function(aResults) {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"profile" : {
"info_cache" : {
"Default" : {
"active_time" : 1430950755.65137,
"is_using_default_name" : true,
"is_ephemeral" : false,
"is_omitted_from_profile_list" : false,
"user_name" : "",
"background_apps" : false,
"is_using_default_avatar" : true,
"avatar_icon" : "chrome://theme/IDR_PROFILE_AVATAR_0",
"name" : "Person 1"
}
},
"profiles_created" : 1,
"last_used" : "Default",
"last_active_profiles" : [
"Default"
]
}
}
31 changes: 27 additions & 4 deletions browser/components/migration/tests/unit/head_migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,40 @@ updateAppInfo();
/**
* Migrates the requested resource and waits for the migration to be complete.
*/
function promiseMigration(migrator, resourceType) {
function promiseMigration(migrator, resourceType, aProfile = null) {
// Ensure resource migration is available.
let availableSources = migrator.getMigrateData(null, false);
Assert.ok((availableSources & resourceType) > 0);
let availableSources = migrator.getMigrateData(aProfile, false);
Assert.ok((availableSources & resourceType) > 0, "Resource supported by migrator");

return new Promise (resolve => {
Services.obs.addObserver(function onMigrationEnded() {
Services.obs.removeObserver(onMigrationEnded, "Migration:Ended");
resolve();
}, "Migration:Ended", false);

migrator.migrate(resourceType, null, null);
migrator.migrate(resourceType, null, aProfile);
});
}

/**
* Replaces a directory service entry with a given nsIFile.
*/
function registerFakePath(key, file) {
// Register our own provider for the Library directory.
let provider = {
getFile(prop, persistent) {
persistent.value = true;
if (prop == key) {
return file;
}
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: XPCOMUtils.generateQI([ Ci.nsIDirectoryServiceProvider ])
};
Services.dirsvc.QueryInterface(Ci.nsIDirectoryService)
.registerProvider(provider);
do_register_cleanup(() => {
Services.dirsvc.QueryInterface(Ci.nsIDirectoryService)
.unregisterProvider(provider);
});
}
49 changes: 49 additions & 0 deletions browser/components/migration/tests/unit/test_Chrome_cookies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Cu.import("resource://gre/modules/ForgetAboutSite.jsm");

add_task(function* () {
registerFakePath("ULibDir", do_get_file("Library/"));
let migrator = MigrationUtils.getMigrator("chrome");

Assert.ok(migrator.sourceExists, "Sanity check the source exists");

const COOKIE = {
expiry: 2145934800,
host: "unencryptedcookie.invalid",
isHttpOnly: false,
isSession: false,
name: "testcookie",
path: "/",
value: "testvalue",
};

// Sanity check.
Assert.equal(Services.cookies.countCookiesFromHost(COOKIE.host), 0,
"There are no cookies initially");

const PROFILE = {
id: "Default",
name: "Person 1",
};

// Migrate unencrypted cookies.
yield promiseMigration(migrator, MigrationUtils.resourceTypes.COOKIES, PROFILE);

do_register_cleanup(() => {
ForgetAboutSite.removeDataFromDomain(COOKIE.host);
Assert.equal(Services.cookies.countCookiesFromHost(COOKIE.host), 0,
"There are no cookies after cleanup");
});
Assert.equal(Services.cookies.countCookiesFromHost(COOKIE.host), 1,
"Migrated the expected number of unencrypted cookies");
Assert.equal(Services.cookies.countCookiesFromHost("encryptedcookie.invalid"), 0,
"Migrated the expected number of encrypted cookies");

// Now check the cookie details.
let enumerator = Services.cookies.getCookiesFromHost(COOKIE.host);
Assert.ok(enumerator.hasMoreElements(), "Cookies available");
let foundCookie = enumerator.getNext().QueryInterface(Ci.nsICookie2);

for (let prop of Object.keys(COOKIE)) {
Assert.equal(foundCookie[prop], COOKIE[prop], "Check cookie " + prop);
}
});
4 changes: 4 additions & 0 deletions browser/components/migration/tests/unit/xpcshell.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ head = head_migration.js
tail =
firefox-appdir = browser
skip-if = toolkit == 'android' || toolkit == 'gonk'
support-files =
Library/**

[test_Chrome_cookies.js]
skip-if = os != "mac" # Relies on ULibDir
[test_fx_fhr.js]
[test_IE_bookmarks.js]
skip-if = os != "win"
Expand Down

0 comments on commit 1594821

Please sign in to comment.