Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions keepassxc-browser/content/passkeys-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const PASSKEYS_WAIT_FOR_LIFETIMER = 30;
// Apply a script to the page for intercepting Passkeys (WebAuthn) requests
const enablePasskeys = async function() {
const passkeysLogDebug = function(message, extra) {
if (kpxcPasskeysUtils.debugLogging) {
// `global.js` runs at `document_idle`
if (kpxcPasskeysUtils.debugLogging && typeof debugLogMessage === 'function') {
debugLogMessage(message, extra);
}
};
Expand Down Expand Up @@ -63,8 +64,21 @@ const enablePasskeys = async function() {
}
};

const isSameOriginWithAncestors = function () {
/**
* @param {'create' | 'get'} action
* @returns {boolean}
*/
const isAllowedByPolicy = function (action) {
// https://www.w3.org/TR/webauthn-2/#sctn-permissions-policy
const policy = document.featurePolicy || document.permissionsPolicy;
if (policy) {
passkeysLogDebug('Checking Permissions Policy');
return policy.allowsFeature(`publickey-credentials-${action}`);
}

// fallback to sameOriginWithAncestors
try {
passkeysLogDebug('Checking sameOriginWithAncestors');
return window.origin === window.top.origin;
} catch (_err) {
return false;
Expand All @@ -80,14 +94,14 @@ const enablePasskeys = async function() {
if (ev.detail.action === 'passkeys_create') {
const publicKey = kpxcPasskeysUtils.buildCredentialCreationOptions(
ev.detail.publicKey,
isSameOriginWithAncestors(),
isAllowedByPolicy('create'),
);
passkeysLogDebug('Passkey request', publicKey);
await sendResponse('passkeys_register', publicKey);
} else if (ev.detail.action === 'passkeys_get') {
const publicKey = kpxcPasskeysUtils.buildCredentialRequestOptions(
ev.detail.publicKey,
isSameOriginWithAncestors(),
isAllowedByPolicy('get'),
);
passkeysLogDebug('Passkey request', publicKey);
await sendResponse('passkeys_get', publicKey);
Expand Down