Skip to content

[PM-6125] fix: handle cases when kp.alg is string in createCredential for…#7832

Closed
AlessioC31 wants to merge 1 commit intobitwarden:mainfrom
AlessioC31:main
Closed

[PM-6125] fix: handle cases when kp.alg is string in createCredential for…#7832
AlessioC31 wants to merge 1 commit intobitwarden:mainfrom
AlessioC31:main

Conversation

@AlessioC31
Copy link
Contributor

@AlessioC31 AlessioC31 commented Feb 6, 2024

Fido2

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

I was trying to add passkeys from a website that uses a version of KeycloakJS that sends kp.alg as string.
I know this deviates from standard but it would help passkeys adoption in Bitwarden while providers fix their code (and organizations install the new version).

With this PR, createCredential handles passkeys creation when kp.alg is string by parsing it as a Number.
Let me know if you think this should be handled differently, thanks!

Code changes

Parse kp.alg as Number if it is a string.

Fixes #6804 .

@AlessioC31 AlessioC31 requested a review from a team as a code owner February 6, 2024 21:48
@bitwarden-bot
Copy link

Thank you for your contribution! We've added this to our internal Community PR board for review.
ID: PM-6125

@bitwarden-bot bitwarden-bot changed the title fix: handle cases when kp.alg is string in createCredential for… [PM-6125] fix: handle cases when kp.alg is string in createCredential for… Feb 6, 2024
@bitwarden-bot
Copy link

Logo
Checkmarx One – Scan Summary & Detailsd91209d2-e98a-4d17-b9ca-05a97d1fa99c

No New Or Fixed Issues Found

credTypesAndPubKeyAlgs = params.pubKeyCredParams.filter(
(kp) => kp.alg === -7 && kp.type === "public-key",
);
credTypesAndPubKeyAlgs = params.pubKeyCredParams.filter((kp) => {
Copy link
Contributor

@coroiu coroiu Jul 25, 2024

Choose a reason for hiding this comment

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

issue: could you add a test case to check that this works? (we want Fido2Client well-tested)

(kp) => kp.alg === -7 && kp.type === "public-key",
);
credTypesAndPubKeyAlgs = params.pubKeyCredParams.filter((kp) => {
if (typeof kp.alg == "string") {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: we usually use strict equality wherever possible

Suggested change
if (typeof kp.alg == "string") {
if (typeof kp.alg === "string") {

(kp) => kp.alg === -7 && kp.type === "public-key",
);
credTypesAndPubKeyAlgs = params.pubKeyCredParams.filter((kp) => {
if (typeof kp.alg == "string") {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Could you add a comment here (and above the test case) explaining that this is a fix for non-compliant websites?

Suggested change
if (typeof kp.alg == "string") {
// Fix for spec-deviation: Sites using KeycloakJS send `kp.alg` as a string
if (typeof kp.alg == "string") {

@AlessioC31
Copy link
Contributor Author

Hello @coroiu , thanks for the comments. I see that you created a new PR to address your comments, sorry but didn't have the time to reply these past days. Should I consider this as done then?

@coroiu
Copy link
Contributor

coroiu commented Jul 26, 2024

@AlessioC31 No worries :) Normally we would've just waited but I'm going on vacation at the end of the day and wanted to get this merged before! Thanks for your contribution!

Closing this in favor of #10285

@coroiu coroiu closed this Jul 26, 2024
@merissaacosta
Copy link
Contributor

merissaacosta commented Jul 30, 2024

hey @AlessioC31 - what website were you using that sent kp.alg as a string? we're testing out your fix. thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"No supported key algorithms were found

4 participants