Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebAuthN fails on localhost because it expects an HTTPS origin #6882

Open
1 task done
allezxandre opened this issue Nov 14, 2023 · 14 comments · May be fixed by #9236
Open
1 task done

WebAuthN fails on localhost because it expects an HTTPS origin #6882

allezxandre opened this issue Nov 14, 2023 · 14 comments · May be fixed by #9236
Labels
browser Browser Extension bug

Comments

@allezxandre
Copy link

Steps To Reproduce

  1. Go to a localhost website with WebAuthN (using unencrypted http protocol)
  2. Use WebAuthN authentication

Expected Result

WebAuthN UI opens, mimicking browser behavior on localhost

Actual Result

WebAuthN fails silently on the UI but an error is logged to the console:

Error: 'origin' is not a valid https origin

The error is correct, http://localhost is indeed not https, but I expected localhost to still be a valid origin.

Screenshots or Videos

No response

Additional Context

No response

Operating System

macOS

Operating System Version

No response

Web Browser

Chrome, Safari

Browser Version

Safari 17.0 and Arc 1.15.2

Build Version

Chromium Engine Version 119.0.6045.123 (arm64)

Issue Tracking Info

  • I understand that work is tracked outside of Github. A PR will be linked to this issue should one be opened to address it, but Bitwarden doesn't use fields like "assigned", "milestone", or "project" to track progress.
@allezxandre allezxandre added browser Browser Extension bug labels Nov 14, 2023
@gregorvand
Copy link

+1

since BitWarden jumps in ahead of native browser (why?) it stops all localhost development using WebAuthn being workable, unless in a browser where the BitWarden chrome extension has been disabled

@SDAChess
Copy link

This also made me go insane debugging today to find out this was Bitwarden related and not my own WebAuthn code. Please at least update the error message so that it's easy to know that it is related to Bitwarden ;)

@Jhoscy
Copy link

Jhoscy commented Nov 17, 2023

+1

since BitWarden jumps in ahead of native browser (why?) it stops all localhost development using WebAuthn being workable, unless in a browser where the BitWarden chrome extension has been disabled

I agree, after disabling BitWarden webauthn works as expected

@barryp
Copy link

barryp commented Nov 17, 2023

I just ran into this too. Seems like it's coming from

if (parsedOrigin.hostname == undefined || !params.origin.startsWith("https://")) {
this.logService?.warning(`[Fido2Client] Invalid https origin: ${params.origin}`);
throw new DOMException("'origin' is not a valid https origin", "SecurityError");
}

There's a simple window.isSecureContext it could check, but maybe it doesn't have access to the window

At the very least, maybe something like

if (parsedOrigin.hostname == undefined 
    || !(
        params.origin.startsWith("https://") 
        || (params.origin === 'localhost') 
        || params.origin.endsWith('.localhost')
    )
) ...

@taylorjdawson
Copy link

If @barryp's solution is acceptable could we put this into a PR or is further consideration necessary? I have to enable & disable bitwarden when developing locally

@SDAChess
Copy link

I might need some tweaking such as adding 127.0.0.1 and .local domains maybe? Either way there some to be little to no interest from the Bitwarden team on this issue.

@abergs
Copy link
Member

abergs commented Jan 29, 2024

Hey, while I mostly work on Bitwarden passwordless.dev I'm just updating that we're looking to fix this in a way that aligns with the WebAuthn specification.

@acewings27
Copy link

This started being an issue for me today.

@carlos-menezes
Copy link

Hey, while I mostly work on Bitwarden passwordless.dev I'm just updating that we're looking to fix this in a way that aligns with the WebAuthn specification.

Awesome. Any news on this?

@Aeases
Copy link

Aeases commented Feb 10, 2024

+1 this sucks ass

@coroiu
Copy link
Contributor

coroiu commented Feb 14, 2024

@abergs
Copy link
Member

abergs commented Feb 22, 2024

@carlos-menezes and others: Since w3c/webauthn#2018 was merged in the spec we will move forward and allow http://localhost:* for passkeys in bitwarden. I don't have a date, but my guess is that it won't be long.

Thanks for reporting this.

@carlos-menezes
Copy link

Awesome, great to hear!

coroiu added a commit that referenced this issue May 17, 2024
coroiu added a commit that referenced this issue May 17, 2024
@coroiu coroiu linked a pull request May 17, 2024 that will close this issue
@shahradelahi
Copy link

Hey there!

Thanks to @coroiu, this issue will be resolved pretty soon, but I have a workaround and I hope this becomes useful for some.

I'm working on a project with Next.js and WebAuthn, and to bypass this limitation, I've created an HTTPS proxy for the development environment.

If you want to try this workaround, first install dependencies by following command:

npm i -D concurrently http-proxy

And then create https-server.js file in root of the project:

import fs from 'node:fs';
import path from 'node:path';
import proxy from 'http-proxy';

proxy
  .createServer({
    // openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -keyout localhost.key -out localhost.crt
    ssl: {
      key: fs.readFileSync(path.resolve('localhost.key')),
      cert: fs.readFileSync(path.resolve('localhost.crt')),
    },
    target: {
      host: 'localhost',
      port: 3000,
    },
    ws: true,
  })
  .listen(3001);

Now run the dev server by following command:

concurrently --raw --kill-others "next dev" "node https-server.js"

Also, make sure that localhost is not excluded in extension settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser Browser Extension bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.