Skip to content

Commit 5035d8a

Browse files
Merge pull request #495 from vtex/3.x-sensitive-data
[3.x] Fix / Only remove cookie fields when removing sensitive data from logs
2 parents 10a7fda + 5b478af commit 5035d8a

7 files changed

Lines changed: 30 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [3.77.6] - 2022-03-08
11+
### Fixed
12+
- Only remove cookie fields when removing sensitive data from logs.
13+
1014
## [3.77.5] - 2022-02-24
1115
### Fixed
1216
- Remove sensitive data from logs.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vtex/api",
3-
"version": "3.77.5",
3+
"version": "3.77.6",
44
"description": "VTEX I/O API client",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",

src/service/graphql/middlewares/formatters.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { formatApolloErrors } from 'apollo-server-errors'
22
import { omit, pick } from 'ramda'
33

4-
import { cleanError } from '../../../utils/error'
5-
import { FIRST_LEVEL_SENSITIVE_FIELDS as SENSITIVE_EXCEPTION_FIELDS } from '../../../utils/log'
4+
import { cleanError, SENSITIVE_EXCEPTION_FIELDS } from '../../../utils/error'
65
import { GraphQLServiceContext } from '../typings'
76

87
const ERROR_FIELD_WHITELIST = ['message', 'path', 'stack', 'extensions', 'statusCode', 'name', 'headers', 'originalError', 'code']

src/service/http/middlewares/error.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { LogLevel } from '../../../clients/Logger'
33
import { LINKED } from '../../../constants'
44
import { cancelledRequestStatus, RequestCancelledError } from '../../../errors/RequestCancelledError'
55
import { TooManyRequestsError, tooManyRequestsStatus } from '../../../errors/TooManyRequestsError'
6-
import { cleanError } from '../../../utils/error'
7-
import { FIRST_LEVEL_SENSITIVE_FIELDS as SENSITIVE_EXCEPTION_FIELDS } from '../../../utils/log'
6+
import { cleanError, SENSITIVE_EXCEPTION_FIELDS } from '../../../utils/error'
87
import { ServiceContext } from '../../typings'
98

109
const CACHE_CONTROL_HEADER = 'cache-control'

src/utils/error.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { find, keys, pick } from 'ramda'
33

44
export const PICKED_AXIOS_PROPS = ['baseURL', 'cacheable', 'data', 'finished', 'headers', 'method', 'timeout', 'status', 'path', 'url', 'metric', 'inflightKey', 'forceMaxAge', 'params', 'responseType']
5+
export const SENSITIVE_EXCEPTION_FIELDS = ['config', 'request', 'stack']
56

67
const MAX_ERROR_STRING_LENGTH = process.env.MAX_ERROR_STRING_LENGTH ? parseInt(process.env.MAX_ERROR_STRING_LENGTH, 10) : 8 * 1024
78

src/utils/json.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export function cleanJson(json: {[k: string]: any}, targetFields: string[]) {
2+
for (const key of Object.keys(json)) {
3+
let deleted = false
4+
for (const field of targetFields) {
5+
if (key === field) {
6+
delete json[key]
7+
deleted = true
8+
}
9+
}
10+
11+
if (!deleted && json[key] && typeof json[key] === 'object') {
12+
json[key] = cleanJson(json[key], targetFields)
13+
}
14+
}
15+
16+
return json
17+
}

src/utils/log.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
export const FIRST_LEVEL_SENSITIVE_FIELDS = ['config', 'request', 'stack', 'error']
2-
export const SECOND_LEVEL_SENSITIVE_FIELDS = [ ['parsedInfo', 'requestConfig'], ['headers', 'cookie'] ]
1+
import { cleanJson } from './json'
32

4-
export const cleanLog = (log: any) => {
5-
FIRST_LEVEL_SENSITIVE_FIELDS.forEach(field => {
6-
delete log[field]
7-
})
3+
const SENSITIVE_FIELDS = ['cookie', 'Cookie', 'vtexIdclientautcookie', 'error']
84

9-
SECOND_LEVEL_SENSITIVE_FIELDS.forEach(field => {
10-
if (field[0] in log) {
11-
delete log[field[0]][field[1]]
12-
}
13-
})
14-
}
5+
export const cleanLog = (log: {[k: string]: any}) => {
6+
return cleanJson(log, SENSITIVE_FIELDS)
7+
}

0 commit comments

Comments
 (0)