Skip to content

Commit

Permalink
fix: exception in redactHeaders
Browse files Browse the repository at this point in the history
Avoid accessing properties of `undefined`.
  • Loading branch information
cgawron committed Apr 25, 2024
1 parent d99bbb5 commit c12bde7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ const checkAuth = (req, res, next) => {
})
}

const redacHeaders = (req, res, next) => {
const redactHeaders = Object.keys(req.headers)
const redactHeaders = (req, res, next) => {
const _redactHeaders = Object.keys(req.headers)
.filter((header) => header == 'cookie' || header.startsWith('x-'));
logger.debug('redactHeaders', redactHeaders);
redactHeaders.forEach((header) => {
if (req.headers['origin'].startsWith('http://localhost')) {
logger.debug('redactHeaders', _redactHeaders);
_redactHeaders.forEach((header) => {
if (req.headers['origin']?.startsWith('http://localhost')) {
req.headers[header] = 'redacted';
}
else {
Expand All @@ -224,7 +224,7 @@ const redacHeaders = (req, res, next) => {
if (!process.env.IGNORE_AUTH) {
app.use(checkAuth);
/** redact headers */
app.use(redacHeaders);
app.use(redactHeaders);
}


Expand Down

0 comments on commit c12bde7

Please sign in to comment.