Skip to content

Commit

Permalink
Added Array.isArray check during redaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed Feb 12, 2024
1 parent 2cf57f5 commit c76165b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function redactObject (obj: Record<string, any>, additionalKeys: string[]
value = `${value.origin}${value.pathname}${value.search}`
}

if (typeof value === 'object' && value !== null) {
if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
if (seen.get(value) !== true) {
// if this Object hasn't been seen, recursively redact it
seen.set(value, true)
Expand Down
23 changes: 23 additions & 0 deletions test/unit/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,26 @@ test('redact extra keys when passed', t => {

t.end()
})

test('redaction does not transform array properties into objects', t => {
const errResponse = new errors.ResponseError({
body: {
error: {
root_cause: [
{
type: 'index_not_found_exception',
reason: 'no such index [poop]',
},
],
},
status: 404,
},
statusCode: 404,
headers: {},
warnings: [],
meta: {} as any,
});

t.equal(Array.isArray(errResponse.body.error.root_cause), true)
t.end()
})

0 comments on commit c76165b

Please sign in to comment.