From 6fac502f9ec288d7df2263e6f5a28b3a1fa84595 Mon Sep 17 00:00:00 2001 From: Daemonxiao <35677990+Daemonxiao@users.noreply.github.com> Date: Fri, 16 Dec 2022 13:10:26 +0800 Subject: [PATCH] fix(core): Fix HTTP Digest Auth for responses without an opaque parameter (#4806) --- packages/core/src/NodeExecuteFunctions.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index cd525a3d75..45afdfdc3c 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -522,9 +522,9 @@ function digestAuthAxiosConfig( const realm: string = authDetails .find((el: any) => el[0].toLowerCase().indexOf('realm') > -1)[1] .replace(/"/g, ''); - const opaque: string = authDetails - .find((el: any) => el[0].toLowerCase().indexOf('opaque') > -1)[1] - .replace(/"/g, ''); + // If authDeatials does not have opaque, we should not add it to authorization. + const opaqueKV = authDetails.find((el: any) => el[0].toLowerCase().indexOf('opaque') > -1); + const opaque: string = opaqueKV ? opaqueKV[1].replace(/"/g, '') : undefined; const nonce: string = authDetails .find((el: any) => el[0].toLowerCase().indexOf('nonce') > -1)[1] .replace(/"/g, ''); @@ -542,10 +542,14 @@ function digestAuthAxiosConfig( .createHash('md5') .update(`${ha1}:${nonce}:${nonceCount}:${cnonce}:auth:${ha2}`) .digest('hex'); - const authorization = + let authorization = `Digest username="${auth?.username as string}",realm="${realm}",` + `nonce="${nonce}",uri="${path}",qop="auth",algorithm="MD5",` + - `response="${response}",nc="${nonceCount}",cnonce="${cnonce}",opaque="${opaque}"`; + `response="${response}",nc="${nonceCount}",cnonce="${cnonce}"`; + // Only when opaque exists, add it to authorization. + if (opaque) { + authorization += `,opaque="${opaque}"`; + } if (axiosConfig.headers) { axiosConfig.headers.authorization = authorization; } else {