Skip to content

Commit

Permalink
Fix redact order
Browse files Browse the repository at this point in the history
  • Loading branch information
aklarfeld committed May 10, 2024
1 parent ac1d7fa commit 9c347a7
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ function getKeyPaths(obj: any, path: string = ''): string[] {
return paths;
}

const getAllKeyPathsForLeavesOnEvent = (event: { request?: RequestType; response?: ResponseType }) => [
...getKeyPaths(event.request?.headers, 'request.headers'),
...getKeyPaths(event.request?.body, 'request.body'),
...getKeyPaths(event.response?.headers, 'response.headers'),
...getKeyPaths(event.response?.body, 'response.body')
].map((key) => ({ keyPath: key, action: SensitiveKeyActions.REDACT }));

const redactValuesFromKeys = (
event: { request?: RequestType; response?: ResponseType, tags?: TagType },
config: ConfigType
Expand Down Expand Up @@ -223,12 +230,6 @@ const redactValuesFromKeys = (
return { event, sensitiveKeyMetadata, tags };
} else {

const keyPathsForLeavesOnEvent = [
...getKeyPaths(event.request?.headers, 'request.headers'),
...getKeyPaths(event.request?.body, 'request.body'),
...getKeyPaths(event.response?.headers, 'response.headers'),
...getKeyPaths(event.response?.body, 'response.body')
].map((key) => ({ keyPath: key, action: SensitiveKeyActions.REDACT }))

let sensitiveKeys = expandSensitiveKeySetForArrays(
event,
Expand All @@ -237,10 +238,10 @@ const redactValuesFromKeys = (

if (forceRedactAll) {
// Sensitive keys = every leaf on the event
sensitiveKeys = keyPathsForLeavesOnEvent
sensitiveKeys = getAllKeyPathsForLeavesOnEvent(event) || [];
} else if (redactByDefault) {
// Sensitive keys = All of the leaves on the event EXCEPT the ones marked allwoed from the remote config
sensitiveKeys = keyPathsForLeavesOnEvent.filter(
sensitiveKeys = (getAllKeyPathsForLeavesOnEvent(event) || []).filter(
(key) => !sensitiveKeys.some(sk => sk.keyPath === key.keyPath && sk.action === SensitiveKeyActions.ALLOW)
);
} else {
Expand Down

0 comments on commit 9c347a7

Please sign in to comment.