diff --git a/src/porchlight/static/webauthn.js b/src/porchlight/static/webauthn.js index c2dd181..0ed2a50 100644 --- a/src/porchlight/static/webauthn.js +++ b/src/porchlight/static/webauthn.js @@ -14,6 +14,11 @@ function bytesToBase64url(bytes) { return btoa(raw).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); } +function getCsrfToken() { + const meta = document.querySelector('meta[name="csrf-token"]'); + return meta ? meta.getAttribute('content') : ''; +} + async function beginRegistration() { const statusEl = document.getElementById('webauthn-status'); @@ -21,7 +26,7 @@ async function beginRegistration() { // Step 1: Get options from server const beginRes = await fetch('/manage/credentials/webauthn/begin', { method: 'POST', - headers: { 'Content-Type': 'application/json' }, + headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': getCsrfToken() }, }); if (!beginRes.ok) { if (statusEl) statusEl.innerHTML = '
This application is requesting access to your account.