Skip to content

Commit

Permalink
Skip FirefoxAccounts during Firefox CSV Import (bitwarden#323)
Browse files Browse the repository at this point in the history
* Skip FirefoxAccounts during Firefox CSV Import

Firefox exports 'chrome://FirefoxAccounts' if Firefox Accouts are used
in browser. It's quite hacky - password field in CSV is actually a JSON
encoded data, not a password.
Because it's not a useful record, it should be skipped during import.

* Fix indentation

* Move test Firefox test data to files, fix linter errors
  • Loading branch information
tzdybal committed Apr 12, 2021
1 parent 62cc43f commit 8276748
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
73 changes: 73 additions & 0 deletions spec/common/importers/firefoxCsvImporter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { FirefoxCsvImporter as Importer } from '../../../src/importers/firefoxCsvImporter';

import { CipherView } from '../../../src/models/view/cipherView';
import { LoginUriView } from '../../../src/models/view/loginUriView';
import { LoginView } from '../../../src/models/view/loginView';

import { data as firefoxAccountsData } from './testData/firefoxCsv/firefoxAccountsData.csv';
import { data as simplePasswordData } from './testData/firefoxCsv/simplePasswordData.csv';

const CipherData = [
{
title: 'should parse password',
csv: simplePasswordData,
expected: Object.assign(new CipherView(), {
id: null,
organizationId: null,
folderId: null,
name: 'example.com',
login: Object.assign(new LoginView(), {
username: 'foo',
password: 'bar',
uris: [
Object.assign(new LoginUriView(), {
uri: 'https://example.com',
}),
],
}),
notes: null,
type: 1,
}),
},
{
title: 'should skip "chrome://FirefoxAccounts"',
csv: firefoxAccountsData,
expected: Object.assign(new CipherView(), {
id: null,
organizationId: null,
folderId: null,
name: 'example.com',
login: Object.assign(new LoginView(), {
username: 'foo',
password: 'bar',
uris: [
Object.assign(new LoginUriView(), {
uri: 'https://example.com',
}),
],
}),
notes: null,
type: 1,
}),
},
];

describe('Firefox CSV Importer', () => {
CipherData.forEach(data => {
it(data.title, async () => {
const importer = new Importer();
const result = await importer.parse(data.csv);
expect(result != null).toBe(true);
expect(result.ciphers.length).toBeGreaterThan(0);

const cipher = result.ciphers.shift();
let property: keyof typeof data.expected;
for (property in data.expected) {
if (data.expected.hasOwnProperty(property)) {
expect(cipher.hasOwnProperty(property)).toBe(true);
expect(cipher[property]).toEqual(data.expected[property]);
}
}
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const data = `"url","username","password","httpRealm","formActionOrigin","guid","timeCreated","timeLastUsed","timePasswordChanged"
"chrome://FirefoxAccounts","bla-bla-foo-bar","{""version"":1,""accountData"":{""kSync"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kXCS"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kExtSync"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kExtKbHash"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""scopedKeys"":{""https://identity.mozilla.com/apps/oldsync"":{""kid"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",""k"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kty"":""xxx""},""sync:addon_storage"":{""kid"":""xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""k"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kty"":""xxx""}}}}","Firefox Accounts credentials",,"{d61e37fa-2bc4-469a-bd66-41fd3b0005e0}","1612345678900","1612345678900","1612345678900"
"https://example.com","foo","bar",,"","{d61e37fa-2bc4-469a-bd66-41fd3b0005e0}","1612345678900","1612345678900","1612345678900"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const data = `"url","username","password","httpRealm","formActionOrigin","guid","timeCreated","timeLastUsed","timePasswordChanged"
"https://example.com","foo","bar",,"","{d61e37fa-2bc4-469a-bd66-41fd3b0005e0}","1612345678900","1612345678900","1612345678900"`;
4 changes: 3 additions & 1 deletion src/importers/firefoxCsvImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export class FirefoxCsvImporter extends BaseImporter implements Importer {
return Promise.resolve(result);
}

results.forEach(value => {
results.filter(value => {
return value.url !== 'chrome://FirefoxAccounts';
}).forEach(value => {
const cipher = this.initLoginCipher();
const url = this.getValueOrDefault(value.url, this.getValueOrDefault(value.hostname));
cipher.name = this.getValueOrDefault(this.nameFromUrl(url), '--');
Expand Down

0 comments on commit 8276748

Please sign in to comment.