Skip to content

Commit

Permalink
feat(utils): improve redactSensitiveHeaders types (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
melikhov-dev authored Sep 1, 2023
1 parent 6e34496 commit 86763d5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/lib/utils/redact-sensitive-headers.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import {IncomingHttpHeaders} from 'http';

import {Dict} from '../../types';

import {prepareSensitiveKeysRedacter} from './redact-sensitive-keys';

export type SensitiveHeadersRedacter = (inputHeaders: Dict | IncomingHttpHeaders) => Dict;
export type SensitiveHeadersRedacter = (inputHeaders?: IncomingHttpHeaders) => IncomingHttpHeaders;

export default function prepareSensitiveHeadersRedacter(
sensitiveHeaders: Array<string> = [],
headersWithSensitiveUrls: Array<string> = [],
redactSensitiveQueryParams: (input: string) => string = (input) => input,
isDevMode = false,
) {
const redactSensitiveHeaders: SensitiveHeadersRedacter = (inputHeaders) => {
const redactSensitiveHeaders: SensitiveHeadersRedacter = (inputHeaders = {}) => {
if (isDevMode) {
return inputHeaders;
}

const redactSensitiveKeys = prepareSensitiveKeysRedacter(sensitiveHeaders);

const result = redactSensitiveKeys(inputHeaders);
const result = redactSensitiveKeys(inputHeaders) as IncomingHttpHeaders;

Object.keys(result).forEach((headerName) => {
if (headersWithSensitiveUrls.includes(headerName.toLowerCase())) {
Expand Down

0 comments on commit 86763d5

Please sign in to comment.