Skip to content
Open
Show file tree
Hide file tree
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
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.


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) {
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.

pkOptions.challenge.byteLength would be enough 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.

I want to make sure challenge exists and is the correct type. That it's not a base64string or something like that. So that there's no more undefined < 16 check.

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.

Does your silence mean that I should refuse this additional check anyway?

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.

My silence means I haven't answered you yet. if (pkOptions.challenge.byteLength < 16) is enough here.

throw new TypeError('challenge is shorter than required minimum length.');
}
};
Expand Down