Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
21 changes: 20 additions & 1 deletion keepassxc-browser/background/keepass.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ keepass.passkeysGet = async function(tab, args = []) {
const nonce = keepassClient.getNonce();
const [ publicKey, origin ] = args;
const passkeyPublicKey = JSON.parse(JSON.stringify(publicKey));
const relatedOrigins = await keepass.getPasskeysRelatedOrigins(passkeyPublicKey?.rp?.id);
const relatedOrigins = await keepass.getPasskeysRelatedOrigins(passkeyPublicKey?.rpId);
Comment thread
varjolintu marked this conversation as resolved.

const messageData = {
action: kpAction,
Expand Down Expand Up @@ -920,11 +920,30 @@ keepass.getPasskeysRelatedOrigins = async function(rpId) {
}

try {
let hostname;
try {
hostname = new URL(`https://${rpId}`).hostname;
} catch { }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should return already in here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there should be code duplication?

try {
  if (new URL(`https://${rpId}`).hostname !== rpId) {
    logError(`getRelatedOrigins error: "${rpId}" is wrong rpId`);
    return [];
  }
} catch {
  logError(`getRelatedOrigins error: "${rpId}" is wrong rpId`);
  return [];
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course we want to handle the exception.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error itself does not provide any useful information. The rpId may be incorrect both in case of an error and without one.

If an error occurs, the assignment operation will not be executed, and the hostname will be equal to undefined.


if (hostname !== rpId) {
logError(`getRelatedOrigins error: "${rpId}" is wrong rpId`);
return [];
}
Comment thread
droidmonkey marked this conversation as resolved.

const response = await fetch(`https://${rpId}/.well-known/webauthn`, {
signal: AbortSignal.timeout(DEFAULT_FETCH_TIMEOUT),
cache: 'no-store',
credentials: 'omit',
referrerPolicy: 'no-referrer',
});

// Basic reply validation, see: https://www.w3.org/TR/webauthn-3/#sctn-validating-relation-origin

if (response.status !== 200) {
logError(`getRelatedOrigins error: HTTP status code is ${response.status}`);
return [];
}

const isJson = response?.headers?.get('content-type')?.includes('application/json');
if (!isJson) {
logError('getRelatedOrigins error: Content-Type is not JSON');
Expand Down
2 changes: 1 addition & 1 deletion keepassxc-browser/content/passkeys-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const checkErrors = function(pkOptions, sameOriginWithAncestors) {
throw new DOMException('Cross-origin register or authentication is not allowed.', DOMException.NotAllowedError);
}

if (pkOptions.challenge.length < 16) {
if (!Number.isSafeInteger(pkOptions.challenge?.byteLength) || pkOptions.challenge.byteLength < 16) {
Comment thread
varjolintu marked this conversation as resolved.
Outdated
throw new TypeError('challenge is shorter than required minimum length.');
}
};
Expand Down