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.
70 lines
2.1 KiB
JavaScript
70 lines
2.1 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 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,
|
|
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
|
|
let origin = process.env.WEBAUTHN_ORIGIN || derived.origin
|
|
|
|
// Sicherstellen, dass HTTPS-Origins KEINEN Port haben (auch wenn in ENV gesetzt)
|
|
if (origin.startsWith('https://')) {
|
|
try {
|
|
const u = new URL(origin)
|
|
// 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 {
|
|
// 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,
|
|
derivedOrigin: derived.origin
|
|
})
|
|
|
|
return { rpId, rpName, origin, requireUV }
|
|
}
|
|
|
|
|