Enhance WebAuthn origin handling and debug logging for passkey registration
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 48s

Refine the WebAuthn configuration to ensure that HTTPS origins do not include ports, improving compliance with standards. Add additional debug logging in the passkey registration process to verify the webauthnOrigin and provide guidance for configuration issues, aiding in troubleshooting and enhancing the clarity of the registration flow.
This commit is contained in:
Torsten Schulz (local)
2026-01-07 22:01:28 +01:00
parent 83a2166399
commit 994aabfb85
2 changed files with 33 additions and 12 deletions

View File

@@ -53,9 +53,17 @@ export default defineEventHandler(async (event) => {
rpId, rpId,
rpName, rpName,
webauthnOrigin, webauthnOrigin,
requestOrigin requestOrigin,
webauthnOriginEnv: process.env.WEBAUTHN_ORIGIN,
baseUrlEnv: process.env.NUXT_PUBLIC_BASE_URL
}) })
// WICHTIG: Sicherstellen, dass die Origin KEINEN Port hat
if (webauthnOrigin.includes(':3100')) {
console.error('[DEBUG] ERROR: webauthnOrigin contains port 3100! This will cause verification to fail.')
console.error('[DEBUG] Fix: Set WEBAUTHN_ORIGIN=https://harheimertc.tsschulz.de (without port) in .env')
}
const userId = crypto.randomUUID() const userId = crypto.randomUUID()
const registrationId = crypto.randomBytes(16).toString('hex') const registrationId = crypto.randomBytes(16).toString('hex')

View File

@@ -2,12 +2,20 @@ function deriveFromBaseUrl() {
const base = process.env.NUXT_PUBLIC_BASE_URL || 'http://localhost:3100' const base = process.env.NUXT_PUBLIC_BASE_URL || 'http://localhost:3100'
try { try {
const u = new URL(base) const u = new URL(base)
// Für HTTPS (Port 443) den Port weglassen, da er standardmäßig ist // Für HTTPS (Port 443) den Port IMMER weglassen, da er standardmäßig ist
// Für andere Ports (z.B. Dev auf 3100) den Port beibehalten // Für HTTP in Production sollte auch Port 80 weggelassen werden
const port = u.port && u.port !== '443' && u.port !== '80' ? `:${u.port}` : '' // Nur für Development (localhost mit Port) den Port beibehalten
const origin = u.protocol === 'https:' && !port let origin
? `${u.protocol}//${u.hostname}` if (u.protocol === 'https:') {
: `${u.protocol}//${u.hostname}${port}` // HTTPS: Port immer weglassen (443 ist Standard)
origin = `https://${u.hostname}`
} else if (u.protocol === 'http:' && u.hostname === 'localhost') {
// Development: Port beibehalten
origin = `${u.protocol}//${u.host}`
} else {
// HTTP Production: Port 80 weglassen
origin = u.port === '80' ? `http://${u.hostname}` : `${u.protocol}//${u.host}`
}
return { return {
origin, origin,
@@ -23,15 +31,19 @@ export function getWebAuthnConfig() {
const rpId = process.env.WEBAUTHN_RP_ID || derived.rpId const rpId = process.env.WEBAUTHN_RP_ID || derived.rpId
const rpName = process.env.WEBAUTHN_RP_NAME || 'Harheimer TC' const rpName = process.env.WEBAUTHN_RP_NAME || 'Harheimer TC'
// WEBAUTHN_ORIGIN hat Priorität, sonst von BASE_URL ableiten // WEBAUTHN_ORIGIN hat Priorität, sonst von BASE_URL ableiten
// WICHTIG: Origin sollte KEINEN Port enthalten für HTTPS (443 ist Standard)
let origin = process.env.WEBAUTHN_ORIGIN || derived.origin let origin = process.env.WEBAUTHN_ORIGIN || derived.origin
// Sicherstellen, dass HTTPS-Origins keinen Port haben (außer es ist explizit gesetzt) // Sicherstellen, dass HTTPS-Origins KEINEN Port haben (auch wenn in ENV gesetzt)
if (origin.startsWith('https://') && !process.env.WEBAUTHN_ORIGIN) { if (origin.startsWith('https://')) {
try { try {
const u = new URL(origin) const u = new URL(origin)
if (u.port === '443' || (!u.port && u.protocol === 'https:')) { // Port 443 oder kein Port = Standard, also Port weglassen
if (u.port === '443' || !u.port) {
origin = `https://${u.hostname}`
} else {
// Auch andere Ports bei HTTPS entfernen (nicht Standard für WebAuthn)
origin = `https://${u.hostname}` origin = `https://${u.hostname}`
} }
} catch { } catch {
@@ -47,7 +59,8 @@ export function getWebAuthnConfig() {
origin, origin,
requireUV, requireUV,
webauthnOriginEnv: process.env.WEBAUTHN_ORIGIN, webauthnOriginEnv: process.env.WEBAUTHN_ORIGIN,
baseUrlEnv: process.env.NUXT_PUBLIC_BASE_URL baseUrlEnv: process.env.NUXT_PUBLIC_BASE_URL,
derivedOrigin: derived.origin
}) })
return { rpId, rpName, origin, requireUV } return { rpId, rpName, origin, requireUV }