From a31a5c7526800bf35c0400f85039c89aa3cef123 Mon Sep 17 00:00:00 2001 From: kc1r74p <7422353+kc1r74p@users.noreply.github.com> Date: Sat, 6 Apr 2024 23:42:13 +0200 Subject: [PATCH] Mask auth headers in url-plugin --- bin/url-plugin.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/url-plugin.js b/bin/url-plugin.js index 8f187ff..cf21ebd 100644 --- a/bin/url-plugin.js +++ b/bin/url-plugin.js @@ -47,11 +47,14 @@ stream.on('json', function(job) { if (params.headers) { // allow headers to be substituted using [placeholders] params.headers = Tools.sub( params.headers, job ); - - print("\nRequest Headers:\n" + params.headers.trim() + "\n"); + print("\nRequest Headers:\n"); params.headers.replace(/\r\n/g, "\n").trim().split(/\n/).forEach( function(pair) { if (pair.match(/^([^\:]+)\:\s*(.+)$/)) { - request.setHeader( RegExp.$1, RegExp.$2 ); + const headerKey = RegExp.$1; + const headerValue = RegExp.$2; + request.setHeader( headerKey, headerValue ); + const maskedValue = (headerKey.toLowerCase() === 'authorization' && headerValue.trim().includes(' ')) ? headerValue.replace(headerValue.trim().split(' ')[1], '*'.repeat(headerValue.trim().split(' ')[1].length)) : headerValue; + print(`${headerKey}: ${maskedValue.trim()}\n` ); } } ); }