Prevent registration if WebAuthn is not supported

This hides the "Register" button and shows an error that's specific
to one of two ways a browser may not support WebAuthn:

- JavaScript is disabled (there's no possible fallback for this).
- WebAuthn API is not supported (e.g. on Internet Explorer).

We could add a similar check for the API in the JS code to handle
the button click, but hiding it seems like enough protection.

In order to avoid elements flashing when the page loads, this uses
a view macro to embed a script at the start of the body element,
which is the same approach used for the "js-enabled" class flag [1].

Tested with Chrome and IE 11.

[1]: https://github.com/alphagov/govuk-frontend/blob/main/src/govuk/template.njk#L31
This commit is contained in:
Ben Thorner
2021-05-13 14:52:32 +01:00
parent a7d7cb3421
commit 2039d3aa45
5 changed files with 50 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
{% extends "template.njk" %}
{% from "components/banner.html" import banner %}
{% from "components/cookie-banner.html" import cookie_banner %}
{% from "components/webauthn-api-check.html" import webauthn_api_check %}
{% block headIcons %}
<link rel="shortcut icon" sizes="16x16 32x32 48x48" href="{{ asset_url('images/favicon.ico') }}" type="image/x-icon" />
@@ -38,6 +39,10 @@
{% endblock %}
{% block bodyStart %}
{% block webauthn_api %}
{{ webauthn_api_check() }}
{% endblock %}
{% block cookie_message %}
{{ cookie_banner() }}
{% endblock %}