From 57dfe26630b6c8cfb8be7f5cd900c85fea337c1f Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Wed, 28 Apr 2021 21:17:55 -0700 Subject: [PATCH 1/9] Allow file:// in site preferences. --- keepassxc-browser/_locales/en/messages.json | 2 +- keepassxc-browser/options/options.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/keepassxc-browser/_locales/en/messages.json b/keepassxc-browser/_locales/en/messages.json index 15f1ffc..c0aaca0 100644 --- a/keepassxc-browser/_locales/en/messages.json +++ b/keepassxc-browser/_locales/en/messages.json @@ -992,7 +992,7 @@ "description": "Label for adding site manually on Site preferences tab." }, "optionsSitePreferencesManualAddHelp": { - "message": "The URL must start with either https://, http://, or ftp:// and must be at least 10 characters long.", + "message": "The URL must start with either https://, http://, file://, or ftp:// and must be at least 10 characters long.", "description": "Help text for adding site manually on Site preferences tab." }, "optionsSitePreferencesConfirmation": { diff --git a/keepassxc-browser/options/options.html b/keepassxc-browser/options/options.html index fa49abf..f267c59 100644 --- a/keepassxc-browser/options/options.html +++ b/keepassxc-browser/options/options.html @@ -541,7 +541,7 @@
- +
From cc8ce983f6a21d20f02d0ebd0601f6b53b20f03b Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Wed, 28 Apr 2021 21:20:43 -0700 Subject: [PATCH 2/9] The manualUrl.validity.valid check already checks for minlength. Add a maxlength attribute and remove javascript check. --- keepassxc-browser/options/options.html | 2 +- keepassxc-browser/options/options.js | 59 +++++++++++++------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/keepassxc-browser/options/options.html b/keepassxc-browser/options/options.html index f267c59..2679351 100644 --- a/keepassxc-browser/options/options.html +++ b/keepassxc-browser/options/options.html @@ -541,7 +541,7 @@
- +
diff --git a/keepassxc-browser/options/options.js b/keepassxc-browser/options/options.js index 291e69b..9fcc30d 100644 --- a/keepassxc-browser/options/options.js +++ b/keepassxc-browser/options/options.js @@ -502,38 +502,37 @@ options.initSitePreferences = function() { const errorMessage = tr('optionsErrorValueExists'); let value = manualUrl.value; - if (value.length > 10 && value.length <= 2000) { - // Fills the last / char if needed. This ensures the compatibility with Match Patterns - if (slashNeededForUrl(value)) { - value += '/'; - } - // Check if the URL is already in the list - if (options.settings['sitePreferences'].some(s => s.url === value)) { - options.createWarning(manualUrl, errorMessage); - return; - } - - if (options.settings['sitePreferences'] === undefined) { - options.settings['sitePreferences'] = []; - } - - const newValue = options.settings['sitePreferences'].length + 1; - const trClone = $('#tab-site-preferences table tr.clone:first').clone(true); - trClone.removeClass('clone d-none'); - - const tr = trClone.clone(true); - tr.data('url', value.toLowerCase()); - tr.attr('id', 'tr-scf' + newValue); - tr.children('td:first').text(value); - tr.children('td:nth-child(2)').children('select').val(IGNORE_NOTHING); - $('#tab-site-preferences table tbody:first').append(tr); - $('#tab-site-preferences table tbody:first tr.empty:first').hide(); - - options.settings['sitePreferences'].push({ url: value.toLowerCase(), ignore: IGNORE_NOTHING, usernameOnly: false }); - options.saveSettings(); - manualUrl.value = ''; + // Fills the last / char if needed. This ensures the compatibility with Match Patterns + if (slashNeededForUrl(value)) { + value += '/'; } + + // Check if the URL is already in the list + if (options.settings['sitePreferences'].some(s => s.url === value)) { + options.createWarning(manualUrl, errorMessage); + return; + } + + if (options.settings['sitePreferences'] === undefined) { + options.settings['sitePreferences'] = []; + } + + const newValue = options.settings['sitePreferences'].length + 1; + const trClone = $('#tab-site-preferences table tr.clone:first').clone(true); + trClone.removeClass('clone d-none'); + + const tr = trClone.clone(true); + tr.data('url', value.toLowerCase()); + tr.attr('id', 'tr-scf' + newValue); + tr.children('td:first').text(value); + tr.children('td:nth-child(2)').children('select').val(IGNORE_NOTHING); + $('#tab-site-preferences table tbody:first').append(tr); + $('#tab-site-preferences table tbody:first tr.empty:first').hide(); + + options.settings['sitePreferences'].push({ url: value.toLowerCase(), ignore: IGNORE_NOTHING, usernameOnly: false }); + options.saveSettings(); + manualUrl.value = ''; }); $('#dialogDeleteSite .modal-footer:first button.yes:first').click(function(e) { From ca72d95e6ac921ee2e82e2c5d7d5924967f735e6 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Wed, 28 Apr 2021 21:21:08 -0700 Subject: [PATCH 3/9] Remove unnecessary variable. --- keepassxc-browser/options/options.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/keepassxc-browser/options/options.js b/keepassxc-browser/options/options.js index 9fcc30d..5a31fe4 100644 --- a/keepassxc-browser/options/options.js +++ b/keepassxc-browser/options/options.js @@ -500,7 +500,6 @@ options.initSitePreferences = function() { return; } - const errorMessage = tr('optionsErrorValueExists'); let value = manualUrl.value; // Fills the last / char if needed. This ensures the compatibility with Match Patterns @@ -510,7 +509,7 @@ options.initSitePreferences = function() { // Check if the URL is already in the list if (options.settings['sitePreferences'].some(s => s.url === value)) { - options.createWarning(manualUrl, errorMessage); + options.createWarning(manualUrl, tr('optionsErrorValueExists')); return; } From 4a17805d8132e7717730fca4d8d8c937f7618d7c Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Wed, 28 Apr 2021 21:22:21 -0700 Subject: [PATCH 4/9] Change minlength to 5 characters to allow "file://*". --- keepassxc-browser/_locales/en/messages.json | 2 +- keepassxc-browser/options/options.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/keepassxc-browser/_locales/en/messages.json b/keepassxc-browser/_locales/en/messages.json index c0aaca0..8b839b0 100644 --- a/keepassxc-browser/_locales/en/messages.json +++ b/keepassxc-browser/_locales/en/messages.json @@ -992,7 +992,7 @@ "description": "Label for adding site manually on Site preferences tab." }, "optionsSitePreferencesManualAddHelp": { - "message": "The URL must start with either https://, http://, file://, or ftp:// and must be at least 10 characters long.", + "message": "The URL must start with either https://, http://, file://, or ftp:// and must be at least 5 characters long.", "description": "Help text for adding site manually on Site preferences tab." }, "optionsSitePreferencesConfirmation": { diff --git a/keepassxc-browser/options/options.html b/keepassxc-browser/options/options.html index 2679351..10c5329 100644 --- a/keepassxc-browser/options/options.html +++ b/keepassxc-browser/options/options.html @@ -541,7 +541,7 @@
- +
From aba6823eec34930236c98533bf21ad8978cbff7a Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Thu, 29 Apr 2021 07:58:01 -0700 Subject: [PATCH 5/9] Add special handling of file:// since there is no host. --- keepassxc-browser/common/global.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/keepassxc-browser/common/global.js b/keepassxc-browser/common/global.js index e8bdf29..7e82e02 100755 --- a/keepassxc-browser/common/global.js +++ b/keepassxc-browser/common/global.js @@ -61,6 +61,18 @@ const matchPatternToRegExp = function(pattern) { return (/^(?:http|https|file|ftp|app):\/\//); } + // special handling of file:// since there is no host + if (pattern.startsWith('file://')) { + let regex = '^'; + if (pattern.endsWith('*')) { + regex += pattern.slice(0, -1); + } + else { + regex += `${pattern}$`; + } + return new RegExp(regex); + } + const matchPatternRegExp = new RegExp( `^${schemeSegment}://${hostSegment}/${pathSegment}$` ); From c98d7d8cf2ee5a82deca15f026e98bb5ff9f5f42 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Thu, 29 Apr 2021 07:59:29 -0700 Subject: [PATCH 6/9] Remove "file" from schemeSegment. This lets you add "file://*" as a site preference (before this would be corrected to "file://*/" and you had to use "file:///*" to get what you wanted). --- keepassxc-browser/common/global.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keepassxc-browser/common/global.js b/keepassxc-browser/common/global.js index 7e82e02..7dbc2fe 100755 --- a/keepassxc-browser/common/global.js +++ b/keepassxc-browser/common/global.js @@ -12,7 +12,7 @@ const SORT_BY_USERNAME = 'sortByUsername'; const SORT_BY_GROUP_AND_TITLE = 'sortByGroupAndTitle'; const SORT_BY_GROUP_AND_USERNAME = 'sortByGroupAndUsername'; -const schemeSegment = '(\\*|http|https|ws|wss|file|ftp)'; +const schemeSegment = '(\\*|http|https|ws|wss|ftp)'; const hostSegment = '(\\*|(?:\\*\\.)?(?:[^/*]+))?'; const pathSegment = '(.*)'; From e6f7c6c21f9c47e8768fe05d020a691ccc2be146 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Thu, 29 Apr 2021 08:13:34 -0700 Subject: [PATCH 7/9] Do toLowerCase() earlier so the value that is added to the table is consistent after page refresh. This also prevents duplicates with different casing from being added. --- keepassxc-browser/options/options.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keepassxc-browser/options/options.js b/keepassxc-browser/options/options.js index 5a31fe4..3fc3690 100644 --- a/keepassxc-browser/options/options.js +++ b/keepassxc-browser/options/options.js @@ -500,7 +500,7 @@ options.initSitePreferences = function() { return; } - let value = manualUrl.value; + let value = manualUrl.value.toLowerCase(); // Fills the last / char if needed. This ensures the compatibility with Match Patterns if (slashNeededForUrl(value)) { @@ -522,14 +522,14 @@ options.initSitePreferences = function() { trClone.removeClass('clone d-none'); const tr = trClone.clone(true); - tr.data('url', value.toLowerCase()); + tr.data('url', value); tr.attr('id', 'tr-scf' + newValue); tr.children('td:first').text(value); tr.children('td:nth-child(2)').children('select').val(IGNORE_NOTHING); $('#tab-site-preferences table tbody:first').append(tr); $('#tab-site-preferences table tbody:first tr.empty:first').hide(); - options.settings['sitePreferences'].push({ url: value.toLowerCase(), ignore: IGNORE_NOTHING, usernameOnly: false }); + options.settings['sitePreferences'].push({ url: value, ignore: IGNORE_NOTHING, usernameOnly: false }); options.saveSettings(); manualUrl.value = ''; }); From 254f255afe5c225131f0bf3100b9de05ce01fad7 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Thu, 29 Apr 2021 08:17:53 -0700 Subject: [PATCH 8/9] Rename tr variables to avoid conflict with the tr function. This avoids this confusing error: can't access lexical declaration 'tr' before initialization. --- keepassxc-browser/options/options.js | 70 ++++++++++++++-------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/keepassxc-browser/options/options.js b/keepassxc-browser/options/options.js index 3fc3690..7040d7f 100644 --- a/keepassxc-browser/options/options.js +++ b/keepassxc-browser/options/options.js @@ -338,24 +338,24 @@ options.initConnectedDatabases = function() { $('#tab-connected-databases tr.clone:first .dropdown-menu:first').width('230px'); - const trClone = $('#tab-connected-databases table tr.clone:first').clone(true); - trClone.removeClass('clone d-none'); + const rowClone = $('#tab-connected-databases table tr.clone:first').clone(true); + rowClone.removeClass('clone d-none'); const addHashToTable = function(hash) { $('#tab-connected-databases table tbody:first tr.empty:first').hide(); - const tr = trClone.clone(true); - tr.data('hash', hash); - tr.attr('id', 'tr-cd-' + hash); + const row = rowClone.clone(true); + row.data('hash', hash); + row.attr('id', 'tr-cd-' + hash); - $('a.dropdown-toggle:first img:first', tr).attr('src', '/icons/toolbar/icon_normal.png'); + $('a.dropdown-toggle:first img:first', row).attr('src', '/icons/toolbar/icon_normal.png'); - tr.children('td:first').text(options.keyRing[hash].id); - tr.children('td:eq(1)').text(options.getPartiallyHiddenKey(options.keyRing[hash].key)); + row.children('td:first').text(options.keyRing[hash].id); + row.children('td:eq(1)').text(options.getPartiallyHiddenKey(options.keyRing[hash].key)); const lastUsed = (options.keyRing[hash].lastUsed) ? new Date(options.keyRing[hash].lastUsed).toLocaleString() : 'unknown'; - tr.children('td:eq(2)').text(lastUsed); + row.children('td:eq(2)').text(lastUsed); const date = (options.keyRing[hash].created) ? new Date(options.keyRing[hash].created).toLocaleDateString() : 'unknown'; - tr.children('td:eq(3)').text(date); - $('#tab-connected-databases table tbody:first').append(tr); + row.children('td:eq(3)').text(date); + $('#tab-connected-databases table tbody:first').append(row); }; let hashList = options.keyRing; @@ -421,17 +421,17 @@ options.initCustomCredentialFields = function() { } }); - const trClone = $('#tab-custom-fields table tr.clone:first').clone(true); - trClone.removeClass('clone d-none'); + const rowClone = $('#tab-custom-fields table tr.clone:first').clone(true); + rowClone.removeClass('clone d-none'); let counter = 1; for (const url in options.settings['defined-custom-fields']) { - const tr = trClone.clone(true); - tr.data('url', url); - tr.attr('id', 'tr-scf' + counter); + const row = rowClone.clone(true); + row.data('url', url); + row.attr('id', 'tr-scf' + counter); ++counter; - tr.children('td:first').text(url); - $('#tab-custom-fields table tbody:first').append(tr); + row.children('td:first').text(url); + $('#tab-custom-fields table tbody:first').append(row); } if ($('#tab-custom-fields table tbody:first tr').length > 2) { @@ -518,15 +518,15 @@ options.initSitePreferences = function() { } const newValue = options.settings['sitePreferences'].length + 1; - const trClone = $('#tab-site-preferences table tr.clone:first').clone(true); - trClone.removeClass('clone d-none'); + const rowClone = $('#tab-site-preferences table tr.clone:first').clone(true); + rowClone.removeClass('clone d-none'); - const tr = trClone.clone(true); - tr.data('url', value); - tr.attr('id', 'tr-scf' + newValue); - tr.children('td:first').text(value); - tr.children('td:nth-child(2)').children('select').val(IGNORE_NOTHING); - $('#tab-site-preferences table tbody:first').append(tr); + const row = rowClone.clone(true); + row.data('url', value); + row.attr('id', 'tr-scf' + newValue); + row.children('td:first').text(value); + row.children('td:nth-child(2)').children('select').val(IGNORE_NOTHING); + $('#tab-site-preferences table tbody:first').append(row); $('#tab-site-preferences table tbody:first tr.empty:first').hide(); options.settings['sitePreferences'].push({ url: value, ignore: IGNORE_NOTHING, usernameOnly: false }); @@ -555,20 +555,20 @@ options.initSitePreferences = function() { } }); - const trClone = $('#tab-site-preferences table tr.clone:first').clone(true); - trClone.removeClass('clone d-none'); + const rowClone = $('#tab-site-preferences table tr.clone:first').clone(true); + rowClone.removeClass('clone d-none'); let counter = 1; if (options.settings['sitePreferences']) { for (const site of options.settings['sitePreferences']) { - const tr = trClone.clone(true); - tr.data('url', site.url); - tr.attr('id', 'tr-scf' + counter); + const row = rowClone.clone(true); + row.data('url', site.url); + row.attr('id', 'tr-scf' + counter); ++counter; - tr.children('td:first').text(site.url); - tr.children('td:nth-child(2)').children('select').val(site.ignore); - tr.children('td:nth-child(3)').children('input[type=checkbox]').attr('checked', site.usernameOnly); - $('#tab-site-preferences table tbody:first').append(tr); + row.children('td:first').text(site.url); + row.children('td:nth-child(2)').children('select').val(site.ignore); + row.children('td:nth-child(3)').children('input[type=checkbox]').attr('checked', site.usernameOnly); + $('#tab-site-preferences table tbody:first').append(row); } } From 56ff521812708274bd30636b430e7324cfc919df Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Thu, 29 Apr 2021 08:25:14 -0700 Subject: [PATCH 9/9] Escape "." also for file://. --- keepassxc-browser/common/global.js | 1 + 1 file changed, 1 insertion(+) diff --git a/keepassxc-browser/common/global.js b/keepassxc-browser/common/global.js index 7dbc2fe..9d92e89 100755 --- a/keepassxc-browser/common/global.js +++ b/keepassxc-browser/common/global.js @@ -64,6 +64,7 @@ const matchPatternToRegExp = function(pattern) { // special handling of file:// since there is no host if (pattern.startsWith('file://')) { let regex = '^'; + pattern = pattern.replace(/\./g, '\\.'); if (pattern.endsWith('*')) { regex += pattern.slice(0, -1); }