mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Passkeys: Permissions Policy support
This commit is contained in:
parent
6414dd24b7
commit
4c5d82c94c
1 changed files with 14 additions and 3 deletions
|
|
@ -63,7 +63,18 @@ 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) {
|
||||
return policy.allowsFeature(`publickey-credentials-${action}`);
|
||||
}
|
||||
|
||||
// fallback to sameOriginWithAncestors
|
||||
try {
|
||||
return window.origin === window.top.origin;
|
||||
} catch (_err) {
|
||||
|
|
@ -80,14 +91,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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue