fix(api): ошибки типов, скрытые отсутствием typecheck

- jose v6 не экспортирует KeyLike → CryptoKey
- SimpleWebAuthn v13 требует Uint8Array<ArrayBuffer>
- targetType 'credential' в AUDIT_TARGET_TYPES (писался в аудит passkey-ов)
- target-app: начальные значения host/path/search никогда не читались
This commit is contained in:
Denozordec
2026-09-23 14:51:38 +07:00
parent e107af8e43
commit c48132e89e
3 changed files with 12 additions and 12 deletions
+5 -7
View File
@@ -5,17 +5,15 @@ export function targetAppFromReturnTo(
returnTo: string | undefined | null, returnTo: string | undefined | null,
): AuditSourceApp { ): AuditSourceApp {
if (!returnTo) return 'portal' if (!returnTo) return 'portal'
let host = '' let u: URL
let path = ''
let search = ''
try { try {
const u = new URL(returnTo) u = new URL(returnTo)
host = u.hostname.toLowerCase()
path = u.pathname.toLowerCase()
search = u.search
} catch { } catch {
return 'portal' return 'portal'
} }
const host = u.hostname.toLowerCase()
const path = u.pathname.toLowerCase()
const search = u.search
// Portal OIDC authorize as return_to → map via client's redirect_uri // Portal OIDC authorize as return_to → map via client's redirect_uri
if (path === '/oauth/authorize' || path.endsWith('/oauth/authorize')) { if (path === '/oauth/authorize' || path.endsWith('/oauth/authorize')) {
+6 -5
View File
@@ -14,16 +14,17 @@ export function webauthnRelyingParty(app: FastifyInstance): {
} }
} }
export function userIdToBytes(userId: string): Uint8Array { export function userIdToBytes(userId: string): Uint8Array<ArrayBuffer> {
return isoUint8Array.fromUTF8String(userId) // Копия через конструктор даёт Uint8Array<ArrayBuffer>, которого требует SimpleWebAuthn v13.
return new Uint8Array(isoUint8Array.fromUTF8String(userId))
} }
export function encodePublicKey(publicKey: Uint8Array): string { export function encodePublicKey(publicKey: Uint8Array<ArrayBuffer>): string {
return isoBase64URL.fromBuffer(publicKey) return isoBase64URL.fromBuffer(publicKey)
} }
export function decodePublicKey(stored: string): Uint8Array { export function decodePublicKey(stored: string): Uint8Array<ArrayBuffer> {
return isoBase64URL.toBuffer(stored) return new Uint8Array(isoBase64URL.toBuffer(stored))
} }
export function asTransports( export function asTransports(
+1
View File
@@ -23,6 +23,7 @@ export const AUDIT_TARGET_TYPES = [
'session', 'session',
'system', 'system',
'app_resource', 'app_resource',
'credential',
] as const ] as const
export type AuditTargetType = (typeof AUDIT_TARGET_TYPES)[number] export type AuditTargetType = (typeof AUDIT_TARGET_TYPES)[number]
export const auditTargetTypeSchema = z.enum(AUDIT_TARGET_TYPES) export const auditTargetTypeSchema = z.enum(AUDIT_TARGET_TYPES)