Files
harheimertc/server/utils/webauthn-config.js
Torsten Schulz (local) 83a2166399
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 45s
Refine WebAuthn configuration and enhance debug logging for origin verification
Update the WebAuthn configuration to ensure HTTPS origins do not include ports, improving compliance with standards. Add detailed debug logging in the passkey registration process to verify the actual origin from the client response, aiding in troubleshooting and enhancing the clarity of the registration flow.
2026-01-07 21:54:02 +01:00

57 lines
1.7 KiB
JavaScript

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}`
return {
origin,
rpId: u.hostname
}
} catch {
return { origin: 'http://localhost:3100', rpId: 'localhost' }
}
}
export function getWebAuthnConfig() {
const derived = deriveFromBaseUrl()
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) {
try {
const u = new URL(origin)
if (u.port === '443' || (!u.port && u.protocol === 'https:')) {
origin = `https://${u.hostname}`
}
} catch {
// Ignore
}
}
const requireUV = (process.env.WEBAUTHN_REQUIRE_UV || '').toLowerCase() === 'true'
console.log('[DEBUG] WebAuthn Config', {
rpId,
rpName,
origin,
requireUV,
webauthnOriginEnv: process.env.WEBAUTHN_ORIGIN,
baseUrlEnv: process.env.NUXT_PUBLIC_BASE_URL
})
return { rpId, rpName, origin, requireUV }
}