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

allow http://localhost origins #218

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions examples/server/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ Once the environment has been created, you can run the server by running:
$ poetry run server

When the server is running, use a browser supporting WebAuthn and open
https://localhost:5000 to access the website.
http://localhost:5000 to access the website.

NOTE: As this server uses a self-signed certificate, you will get warnings in
your browser about the connection not being secure. This is expected, and you
can safely proceed to the site.
NOTE: Webauthn requires a secure context (HTTPS), which involves
obtaining a valid TLS certificate. However, most browsers also treat
http://localhost as a secure context. This example runs without TLS
as a demo, but otherwise you should always use HTTPS with a valid
certificate when using Webauthn.

=== Using the website
The site allows you to register a WebAuthn credential, and to authenticate it.
Expand Down
7 changes: 5 additions & 2 deletions examples/server/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

See the file README.adoc in this directory for details.

Navigate to https://localhost:5000 in a supported web browser.
Navigate to http://localhost:5000 in a supported web browser.
"""
from fido2.webauthn import PublicKeyCredentialRpEntity, PublicKeyCredentialUserEntity
from fido2.server import Fido2Server
Expand Down Expand Up @@ -121,7 +121,10 @@ def authenticate_complete():

def main():
print(__doc__)
app.run(ssl_context="adhoc", debug=False)
# Note: using localhost without TLS, as some browsers do
# not allow Webauthn in case of TLS certificate errors.
# See https://lists.w3.org/Archives/Public/public-webauthn/2022Nov/0135.html
app.run(host="localhost", debug=False)


if __name__ == "__main__":
Expand Down
7 changes: 5 additions & 2 deletions fido2/rpid.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ def verify_rp_id(rp_id: str, origin: str) -> bool:
return False

url = urlparse(origin)
if url.scheme != "https":
return False
host = url.hostname
# Note that Webauthn requires a secure context, i.e. an origin with https scheme.
# However, most browsers also treat http://localhost as a secure context. See
# https://groups.google.com/a/chromium.org/g/blink-dev/c/RC9dSw-O3fE/m/E3_0XaT0BAAJ
if url.scheme != "https" and (url.scheme, host) != ("http", "localhost"):
return False
if host == rp_id:
return True
if host and host.endswith("." + rp_id) and rp_id not in suffixes:
Expand Down
7 changes: 5 additions & 2 deletions fido2/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,12 @@ def verify_app_id(app_id: str, origin: str) -> bool:
:return: True if the App ID is usable by the origin, False if not.
"""
url = urlparse(app_id)
if url.scheme != "https":
return False
hostname = url.hostname
# Note that FIDO U2F requires a secure context, i.e. an origin with https scheme.
# However, most browsers also treat http://localhost as a secure context. See
# https://groups.google.com/a/chromium.org/g/blink-dev/c/RC9dSw-O3fE/m/E3_0XaT0BAAJ
if url.scheme != "https" and (url.scheme, hostname) != ("http", "localhost"):
return False
if not hostname:
return False
return verify_rp_id(hostname, origin)
Expand Down