mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Merge pull request #2653 from keepassxreboot/fix/html_and_body_opacity
Clear credentials if html/body/form opacity limit is met
This commit is contained in:
parent
9ff98e8875
commit
9f3a9ebc63
5 changed files with 39 additions and 9 deletions
|
|
@ -161,6 +161,7 @@
|
|||
"MIN_TOTP_INPUT_LENGTH": "readonly",
|
||||
"module": "readonly",
|
||||
"nacl": "readonly",
|
||||
"OBSERVER_OPTIONS": "readonly",
|
||||
"ORANGE_BUTTON": "readonly",
|
||||
"page": "readonly",
|
||||
"Pixels": "readonly",
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ kpxcEvent.onMessage = async function(request, sender) {
|
|||
}
|
||||
};
|
||||
|
||||
kpxcEvent.showStatus = async function(tab, configured, internalPoll) {
|
||||
kpxcEvent.showStatus = async function(tab, configured, internalPoll, forceShowDefault = false) {
|
||||
let keyId = null;
|
||||
if (configured && keepass.databaseHash !== ''
|
||||
&& Object.hasOwn(keepass.keyRing, keepass.databaseHash)) {
|
||||
keyId = keepass.keyRing[keepass.databaseHash].id;
|
||||
}
|
||||
|
||||
if (!internalPoll) {
|
||||
if (!internalPoll || forceShowDefault) {
|
||||
browserAction.showDefault(tab);
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ kpxcEvent.onSaveSettings = async function(tab, settings) {
|
|||
kpxcEvent.onGetStatus = async function(tab, args = []) {
|
||||
// When internalPoll is true the event is triggered from content script in intervals -> don't poll KeePassXC
|
||||
try {
|
||||
const [ internalPoll = false, triggerUnlock = false ] = args;
|
||||
const [ internalPoll = false, triggerUnlock = false, forceShowDefault ] = args;
|
||||
if (!internalPoll) {
|
||||
const response = await keepass.testAssociation(tab, [ true, triggerUnlock ]);
|
||||
if (!response) {
|
||||
|
|
@ -85,7 +85,7 @@ kpxcEvent.onGetStatus = async function(tab, args = []) {
|
|||
}
|
||||
|
||||
const configured = await keepass.isConfigured();
|
||||
return kpxcEvent.showStatus(tab, configured, internalPoll);
|
||||
return kpxcEvent.showStatus(tab, configured, internalPoll, forceShowDefault);
|
||||
} catch (err) {
|
||||
logError('No status shown: ' + err);
|
||||
return Promise.reject();
|
||||
|
|
|
|||
|
|
@ -166,6 +166,8 @@ kpxcForm.initForm = function(form, credentialFields) {
|
|||
if (submitButton) {
|
||||
submitButton.addEventListener('click', kpxcForm.onSubmit);
|
||||
}
|
||||
|
||||
kpxcUI.pageObserver.observe(form, OBSERVER_OPTIONS);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -81,8 +81,9 @@ kpxc.clearAllFromPage = function() {
|
|||
kpxcUserAutocomplete.closeList();
|
||||
}
|
||||
|
||||
// Switch back to default popup
|
||||
sendMessage('get_status', [ true ]); // This is an internal function call
|
||||
// Clear logins from background and switch back to default popup
|
||||
sendMessage('page_clear_logins');
|
||||
sendMessage('get_status', [ true, false, true ]); // This is an internal function call, forceShowDefault
|
||||
};
|
||||
|
||||
// Creates a new combination manually from active element
|
||||
|
|
@ -879,7 +880,7 @@ kpxc.usePredefinedSites = function(currentLocation) {
|
|||
* Content script initialization.
|
||||
*/
|
||||
const initContentScript = async function() {
|
||||
try {
|
||||
try {
|
||||
if (document?.documentElement?.ownerDocument?.contentType !== 'text/html'
|
||||
&& document?.documentElement?.ownerDocument?.contentType !== 'application/xhtml+xml'
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ const ORANGE_BUTTON = 'kpxc-button kpxc-orange-button';
|
|||
const RED_BUTTON = 'kpxc-button kpxc-red-button';
|
||||
const GRAY_BUTTON_CLASS = 'kpxc-gray-button';
|
||||
|
||||
const OBSERVER_OPTIONS = { attributes: true, attributeFilter: [ 'style' ] };
|
||||
|
||||
const DatabaseState = {
|
||||
DISCONNECTED: 0,
|
||||
LOCKED: 1,
|
||||
|
|
@ -408,7 +410,22 @@ kpxcUI.createWrapperObserver = function() {
|
|||
};
|
||||
|
||||
kpxcUI.observeWrapper = function(elem) {
|
||||
kpxcUI.wrapperObserver.observe(elem, { attributes: true, attributeFilter: [ 'style' ] });
|
||||
kpxcUI.wrapperObserver?.observe(elem, OBSERVER_OPTIONS);
|
||||
};
|
||||
|
||||
// Observer <html> and <body> style changes
|
||||
kpxcUI.createPageObserver = function() {
|
||||
kpxcUI.pageObserver = new MutationObserver(function(mutations, obs) {
|
||||
for (const mut of mutations) {
|
||||
const currentStyle = getComputedStyle(mut?.target);
|
||||
if (currentStyle.opacity && currentStyle.opacity < MIN_OPACITY) {
|
||||
kpxc.clearAllFromPage();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
kpxcUI.pageObserver.observe(document.documentElement, OBSERVER_OPTIONS);
|
||||
kpxcUI.pageObserver.observe(document.body, OBSERVER_OPTIONS);
|
||||
};
|
||||
|
||||
const DOMRectToArray = function(domRect) {
|
||||
|
|
@ -440,6 +457,11 @@ const logDebug = function(message, extra) {
|
|||
}
|
||||
};
|
||||
|
||||
const initObservers = function() {
|
||||
kpxcUI.createWrapperObserver();
|
||||
kpxcUI.createPageObserver();
|
||||
};
|
||||
|
||||
document.addEventListener('mousedown', function(e) {
|
||||
if (!e.isTrusted) {
|
||||
return;
|
||||
|
|
@ -456,7 +478,11 @@ document.addEventListener('mouseup', function(e) {
|
|||
kpxcUI.mouseDown = false;
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', kpxcUI.createWrapperObserver());
|
||||
if (document.readyState === 'complete' || (document.readyState !== 'loading' && !document.documentElement.doScroll)) {
|
||||
initObservers();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', initObservers);
|
||||
}
|
||||
|
||||
HTMLDivElement.prototype.appendMultiple = function(...args) {
|
||||
for (const a of args) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue