Enhance WebAuthn origin handling and debug logging for passkey registration
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 48s
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:
@@ -53,9 +53,17 @@ export default defineEventHandler(async (event) => {
|
||||
rpId,
|
||||
rpName,
|
||||
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 registrationId = crypto.randomBytes(16).toString('hex')
|
||||
|
||||
|
||||
@@ -2,12 +2,20 @@ function deriveFromBaseUrl() {
|
||||
const base = process.env.NUXT_PUBLIC_BASE_URL || 'http://localhost:3100'
|
||||
try {
|
||||
const u = new URL(base)
|
||||
// Für HTTPS (Port 443) den Port weglassen, da er standardmäßig ist
|
||||
// Für andere Ports (z.B. Dev auf 3100) den Port beibehalten
|
||||
const port = u.port && u.port !== '443' && u.port !== '80' ? `:${u.port}` : ''
|
||||
const origin = u.protocol === 'https:' && !port
|
||||
? `${u.protocol}//${u.hostname}`
|
||||
: `${u.protocol}//${u.hostname}${port}`
|
||||
// Für HTTPS (Port 443) den Port IMMER weglassen, da er standardmäßig ist
|
||||
// Für HTTP in Production sollte auch Port 80 weggelassen werden
|
||||
// Nur für Development (localhost mit Port) den Port beibehalten
|
||||
let origin
|
||||
if (u.protocol === 'https:') {
|
||||
// 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 {
|
||||
origin,
|
||||
@@ -23,15 +31,19 @@ export function getWebAuthnConfig() {
|
||||
|
||||
const rpId = process.env.WEBAUTHN_RP_ID || derived.rpId
|
||||
const rpName = process.env.WEBAUTHN_RP_NAME || 'Harheimer TC'
|
||||
|
||||
// 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
|
||||
|
||||
// Sicherstellen, dass HTTPS-Origins keinen Port haben (außer es ist explizit gesetzt)
|
||||
if (origin.startsWith('https://') && !process.env.WEBAUTHN_ORIGIN) {
|
||||
// Sicherstellen, dass HTTPS-Origins KEINEN Port haben (auch wenn in ENV gesetzt)
|
||||
if (origin.startsWith('https://')) {
|
||||
try {
|
||||
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}`
|
||||
}
|
||||
} catch {
|
||||
@@ -47,7 +59,8 @@ export function getWebAuthnConfig() {
|
||||
origin,
|
||||
requireUV,
|
||||
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 }
|
||||
|
||||
Reference in New Issue
Block a user