Skip to content

Commit

Permalink
Merge pull request cronicle-edge#96 from kc1r74p/fix_output_format
Browse files Browse the repository at this point in the history
Mask auth headers in url-plugin
  • Loading branch information
mikeTWC1984 authored Apr 22, 2024
2 parents 466cad1 + a31a5c7 commit b1ec9b7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bin/url-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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` );
}
} );
}
Expand Down

0 comments on commit b1ec9b7

Please sign in to comment.