diff --git a/apps/api/src/oidc/oidc-interaction.controller.ts b/apps/api/src/oidc/oidc-interaction.controller.ts index cc0caae..ffdacce 100644 --- a/apps/api/src/oidc/oidc-interaction.controller.ts +++ b/apps/api/src/oidc/oidc-interaction.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Param, Post, Req, Res, UnauthorizedException } from '@nestjs/common'; +import { Body, Controller, Get, Logger, Param, Post, Req, Res, UnauthorizedException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { Request, Response } from 'express'; import type { Interaction } from 'oidc-provider'; @@ -9,6 +9,8 @@ import { OidcProviderService } from './oidc-provider.service'; @Controller('interaction') export class OidcInteractionController { + private readonly logger = new Logger(OidcInteractionController.name); + constructor( private readonly oidc: OidcProviderService, private readonly config: ConfigService, @@ -22,7 +24,10 @@ export class OidcInteractionController { try { details = await this.oidc.interactionDetails(request, response); } catch (error) { - await this.logInteractionSessionError(error, uid, request); + this.logInteractionSessionError(error, uid, request).catch((logError) => { + const message = logError instanceof Error ? logError.message : String(logError); + this.logger.error(`OIDC interaction session logging failed: ${message}`); + }); response .status(400) .send( @@ -217,6 +222,12 @@ export class OidcInteractionController { private async logInteractionSessionError(error: unknown, uid: string, request: Request): Promise { const cookieHeader = request.headers.cookie ?? ''; + const hasCookieHeader = Boolean(cookieHeader); + const hasInteractionCookie = /(?:^|;\s*)_interaction=/.test(cookieHeader); + this.logger.warn( + `OIDC interaction session not found uid=${uid} hasCookieHeader=${hasCookieHeader} hasInteractionCookie=${hasInteractionCookie} host=${request.headers.host ?? ''} forwardedProto=${request.headers['x-forwarded-proto'] ?? ''}`, + ); + await this.applicationErrorLogger.log({ error, category: ApplicationErrorCategory.OIDC, @@ -232,8 +243,8 @@ export class OidcInteractionController { }, context: { uid, - hasCookieHeader: Boolean(cookieHeader), - hasInteractionCookie: /(?:^|;\s*)_interaction=/.test(cookieHeader), + hasCookieHeader, + hasInteractionCookie, forwardedProto: request.headers['x-forwarded-proto'], forwardedHost: request.headers['x-forwarded-host'], host: request.headers.host,