Skip to content

Commit

Permalink
Merge pull request #1010 from keepassxreboot/feature/predefined_sites
Browse files Browse the repository at this point in the history
Add predefined sites option
  • Loading branch information
Sami Vänttinen authored Nov 1, 2020
2 parents 32be7da + 6a70f44 commit 82e32d4
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 84 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"slashNeededForUrl": true,
"statusResponse": true,
"tr": true,
"trimURL", true
"trimURL": true,
"PREDEFINED_SITELIST": true
}
}
16 changes: 14 additions & 2 deletions keepassxc-browser/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,18 @@
"message": "Passwords are generated by KeePassXC using your password generation profile.",
"description": "Password Generator option help text, second part."
},
"optionsPredefinedSiteList": {
"message": "Predefined sites",
"description": "Predefined site list details button text."
},
"optionsUsePredefinedSites": {
"message": "Use predefined sites for compatibility.",
"description": "Use predefined sites checkbox text."
},
"optionsUsePredefinedSitesHelpText": {
"message": "Adds common sites that have username-only login forms to the site preferences.",
"description": "Use predefined sites option help text."
},
"optionsShowLoginFormIconHelpText": {
"message": "Adds an icon to username fields for filling credentials with a single mouse click.",
"description": "Username field icon option help text."
Expand Down Expand Up @@ -916,8 +928,8 @@
"description": "Part of confirmation text when removing saved custom login fields."
},
"optionsSitePreferencesNotFound": {
"message": "No ignored sites found.",
"description": "Shown when no ignored sites are saved."
"message": "No site preferences found.",
"description": "Shown when no site preferences are saved."
},
"optionsSitePreferencesRemove": {
"message": "Remove site?",
Expand Down
1 change: 1 addition & 0 deletions keepassxc-browser/background/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
try {
await keepass.migrateKeyRing();
await page.initSettings();
await page.initSitePreferences();
await page.initOpenedTabs();
await httpAuth.init();
await keepass.reconnect(null, 5000); // 5 second timeout for the first connect
Expand Down
17 changes: 17 additions & 0 deletions keepassxc-browser/background/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const defaultSettings = {
showNotifications: true,
showOTPIcon: true,
useObserver: true,
usePredefinedSites: true,
usePasswordGeneratorIcons: false
};

Expand Down Expand Up @@ -124,6 +125,10 @@ page.initSettings = async function() {
page.settings.usePasswordGeneratorIcons = defaultSettings.usePasswordGeneratorIcons;
}

if (!('usePredefinedSites' in page.settings)) {
page.settings.usePredefinedSites = defaultSettings.usePredefinedSites;
}

await browser.storage.local.set({ 'settings': page.settings });
return page.settings;
} catch (err) {
Expand Down Expand Up @@ -153,6 +158,18 @@ page.initOpenedTabs = async function() {
}
};

page.initSitePreferences = async function() {
if (!page.settings) {
return;
}

if (!page.settings['sitePreferences']) {
page.settings['sitePreferences'] = [];
}

await browser.storage.local.set({ 'settings': page.settings });
};

page.switchTab = function(tab) {
browserAction.showDefault(tab);
browser.tabs.sendMessage(tab.id, { action: 'activated_tab' }).catch((e) => {
Expand Down
File renamed without changes.
File renamed without changes.
63 changes: 63 additions & 0 deletions keepassxc-browser/common/sites.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';

const PREDEFINED_SITELIST = [
'https://accounts.google.com/*',
'https://www.paypal.com/*',
'https://*.live.com/*',
'https://www.amazon.com/*',
'https://www.amazon.de/*',
'https://www.amazon.co.uk/*',
'https://signin.aws.amazon.com/*',
'https://www.upwork.com/ab/*',
'https://home.personalcapital.com/*',
'https://auth.services.adobe.com/*',
'https://idmsa.apple.com/*',
'https://*.soundcloud.com/*',
'https://icloud.com/*',
'https://signin.ebay.de/*',
'https://signin.ebay.com/*',
'https://signin.ebay.com.au/*',
'https://signin.ebay.com.cn/*',
'https://signin.ebay.com.hk/*',
'https://signin.ebay.com.my/*',
'https://signin.ebay.com.sg/*',
'https://signin.ebay.it/*',
'https://signin.ebay.co.uk/*',
'https://signin.ebay.ca/*',
'https://signin.ebay.at/*',
'https://signin.ebay.be/*',
'https://signin.ebay.fr/*',
'https://signin.ebay.ie/*',
'https://signin.ebay.nl/*',
'https://signin.ebay.es/*',
'https://signin.ebay.ch/*',
'https://signin.ebay.in/*',
'https://signin.ebay.ph/*',
'https://login.yahoo.com/*',
'https://*.atlassian.com/*'
];

const kpxcSites = {};
kpxcSites.googlePasswordFormUrl = 'https://accounts.google.com/signin/v2/challenge/password';
kpxcSites.googleUrl = 'https://accounts.google.com';
kpxcSites.savedForm = undefined;

// Handles a few exceptions for certain sites where password form is inside a div
// or another element that is not detected directly. Triggered by MutationObserver.
// Returns true if an Element has a matching classList.
kpxcSites.exceptionFound = function(classList) {
if (!classList || classList.length === 0) {
return;
}

// Apple ID
if (document.location.origin === 'https://idmsa.apple.com'
&& [ 'password', 'form-row', 'show-password' ].every(c => classList.contains(c))) {
return true;
} else if (document.location.origin.startsWith('https://signin.ebay.com')
&& classList.contains('null')) {
return true;
}

return false;
};
File renamed without changes.
48 changes: 24 additions & 24 deletions keepassxc-browser/content/keepassxc-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,14 @@ kpxcForm.getFormSubmitButton = function(form) {
const action = kpxc.submitUrl || form.action;

// Special handling for accounts.google.com. The submit button is outside the form.
if (form.action.startsWith('https://accounts.google.com')) {
const findDiv = $('#identifierNext');
if (form.action.startsWith(kpxcSites.googleUrl)) {
const findDiv = $('#identifierNext, #passwordNext');
if (!findDiv) {
return undefined;
}

const buttons = findDiv.getElementsByTagName('button');
kpxcSites.savedForm = form;
return buttons.length > 0 ? buttons[0] : undefined;
}

Expand Down Expand Up @@ -220,7 +221,8 @@ kpxcForm.getNewPassword = function(passwordInputs = []) {

// Initializes form and attaches the submit button to our own callback
kpxcForm.init = function(form, credentialFields) {
if (!kpxcForm.formIdentified(form) && (credentialFields.password || credentialFields.username)) {
if (!kpxcForm.formIdentified(form) && (credentialFields.password || credentialFields.username)
|| form.action.startsWith(kpxcSites.googlePasswordFormUrl)) {
kpxcForm.saveForm(form, credentialFields);
form.addEventListener('submit', kpxcForm.onSubmit);

Expand All @@ -244,7 +246,13 @@ kpxcForm.onSubmit = async function(e) {
};

// Traverse parents if the form is not found.
const form = this.nodeName === 'FORM' ? this : kpxcFields.traverseParents(this, searchForm, searchForm, () => null);
let form = this.nodeName === 'FORM' ? this : kpxcFields.traverseParents(this, searchForm, searchForm, () => null);

// Check for extra forms from sites.js
if (!form) {
form = kpxcSites.savedForm;
}

if (!form) {
return;
}
Expand Down Expand Up @@ -612,11 +620,9 @@ kpxc.submitUrl = null;
kpxc.url = null;

// Add page to Site Preferences with Username-only detection enabled. Set from the popup
kpxc.addToSitePreferences = async function(sites) {
kpxc.initSitePreferences();

kpxc.addToSitePreferences = async function() {
// Returns a predefined URL for certain sites
let site = kpxcSites.definedURL(trimURL(window.top.location.href));
let site = trimURL(window.top.location.href);

// Check if the site already exists -> update the current settings
let siteExists = false;
Expand Down Expand Up @@ -955,8 +961,6 @@ kpxc.getSite = function(sites) {
}

let site = trimURL(sites[0]);
kpxc.initSitePreferences();

if (slashNeededForUrl(site)) {
site += '/';
}
Expand Down Expand Up @@ -1151,17 +1155,6 @@ kpxc.initLoginPopup = function() {
sendMessage('popup_login', usernames);
};

// Delete previously created Object if it exists. It will be replaced by an Array
kpxc.initSitePreferences = function() {
if (kpxc.settings['sitePreferences'] !== undefined && kpxc.settings['sitePreferences'].constructor === Object) {
delete kpxc.settings['sitePreferences'];
}

if (!kpxc.settings['sitePreferences']) {
kpxc.settings['sitePreferences'] = [];
}
};

kpxc.passwordFilled = async function() {
return await sendMessage('password_get_filled');
};
Expand Down Expand Up @@ -1356,8 +1349,6 @@ kpxc.setValueWithChange = function(field, value) {

// Returns true if site is ignored
kpxc.siteIgnored = async function(condition) {
kpxc.initSitePreferences();

if (kpxc.settings.sitePreferences) {
let currentLocation;
try {
Expand All @@ -1378,6 +1369,15 @@ kpxc.siteIgnored = async function(condition) {
kpxc.singleInputEnabledForPage = site.usernameOnly;
}
}

// Check for predefined sites
if (kpxc.settings.usePredefinedSites) {
for (const url of PREDEFINED_SITELIST) {
if (siteMatch(url, currentLocation) || url === currentLocation) {
kpxc.singleInputEnabledForPage = true;
}
}
}
}

return false;
Expand Down Expand Up @@ -1644,7 +1644,7 @@ kpxcObserverHelper.initObserver = async function() {
} else if (mut.type === 'attributes' && mut.attributeName === 'class') {
// Only accept targets with forms
const forms = mut.target.nodeName === 'FORM' ? mut.target : mut.target.getElementsByTagName('form');
if (forms.length === 0) {
if (forms.length === 0 && !kpxcSites.exceptionFound(mut.target.classList)) {
continue;
}

Expand Down
35 changes: 0 additions & 35 deletions keepassxc-browser/content/sites.js

This file was deleted.

15 changes: 8 additions & 7 deletions keepassxc-browser/manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"manifest_version": 2,
"name": "KeePassXC-Browser",
"version": "1.7.1",
"version_name": "1.7.1",
"version": "1.7.2",
"version_name": "1.7.2",
"description": "__MSG_extensionDescription__",
"author": "KeePassXC Team",
"icons": {
Expand Down Expand Up @@ -31,8 +31,9 @@
},
"background": {
"scripts": [
"browser-polyfill.min.js",
"global.js",
"common/browser-polyfill.min.js",
"common/global.js",
"common/sites.js",
"background/nacl.min.js",
"background/nacl-util.min.js",
"background/keepass.js",
Expand All @@ -49,15 +50,15 @@
"<all_urls>"
],
"js": [
"browser-polyfill.min.js",
"global.js",
"common/browser-polyfill.min.js",
"common/global.js",
"common/sites.js",
"content/ui.js",
"content/banner.js",
"content/autocomplete.js",
"content/define.js",
"content/keepassxc-browser.js",
"content/pwgen.js",
"content/sites.js",
"content/totp-field.js",
"content/username-field.js"
],
Expand Down
18 changes: 15 additions & 3 deletions keepassxc-browser/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
<link rel="icon" type="image/png" href="../icons/keepassxc_32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="../icons/keepassxc_64x64.png" sizes="64x64">
<link rel="icon" type="image/png" href="../icons/keepassxc_96x96.png" sizes="96x96">
<script src="../browser-polyfill.min.js"></script>
<script src="../global.js"></script>
<script src="../common/browser-polyfill.min.js"></script>
<script src="../common/global.js"></script>
<script src="../common/sites.js"></script>
<script src="../bootstrap/jquery-3.4.1.min.js"></script>
<script src="../bootstrap/bootstrap.min.js"></script>
<script src="options.js"></script>
<script src="../translate.js" defer></script>
<script src="../common/translate.js" defer></script>
</head>
<body class="pt-3 pb-5">
<div class="container-fluid">
Expand Down Expand Up @@ -307,6 +308,17 @@ <h2 class="pb-3 mt-0" data-i18n="optionsGeneralSettingsTab"></h2>
<span class="form-text text-muted" data-i18n="optionsSaveDomainOnlyCustomLoginHelpText"></span>
</div>
</div>

<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="usePredefinedSites" id="usePredefinedSites" value="true" />
<label class="form-check-label" for="usePredefinedSites" data-i18n="optionsUsePredefinedSites"></label>
<span class="form-text text-muted" data-i18n="optionsUsePredefinedSitesHelpText"></span>
<details id="predefinedSiteList">
<summary><span data-i18n="optionsPredefinedSiteList"></span></summary>
</details>
</div>
</div>
</div>
</div>

Expand Down
12 changes: 12 additions & 0 deletions keepassxc-browser/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,18 @@ options.initGeneralSettings = function() {
const copyText = document.getElementById('versionInfo').innerText;
navigator.clipboard.writeText(copyText);
});

// Add predefined sites to the <details> list
const siteListing = $('#predefinedSiteList');
if (siteListing) {
// From sites.js
for (const site of PREDEFINED_SITELIST) {
const elem = document.createElement('span');
elem.textContent = site;
siteListing.append(document.createElement('br'));
siteListing.append(elem);
}
}
};

options.showKeePassXCVersions = function(response) {
Expand Down
Loading

0 comments on commit 82e32d4

Please sign in to comment.