Skip to content

Commit 10a7fda

Browse files
Merge pull request #488 from vtex/3.x-sensitive-data
[3.x] Fix / Remove sensitive data from logs
2 parents 7527df8 + a884741 commit 10a7fda

7 files changed

Lines changed: 27 additions & 5 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.5] - 2022-02-24
11+
### Fixed
12+
- Remove sensitive data from logs.
13+
1014
## [3.77.4] - 2021-10-22
1115

1216
## [3.77.3] - 2021-10-22

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.4",
3+
"version": "3.77.5",
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { formatApolloErrors } from 'apollo-server-errors'
22
import { omit, pick } from 'ramda'
33

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

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

src/service/http/middlewares/error.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ 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, SENSITIVE_EXCEPTION_FIELDS } from '../../../utils/error'
6+
import { cleanError } from '../../../utils/error'
7+
import { FIRST_LEVEL_SENSITIVE_FIELDS as SENSITIVE_EXCEPTION_FIELDS } from '../../../utils/log'
78
import { ServiceContext } from '../../typings'
89

910
const CACHE_CONTROL_HEADER = 'cache-control'

src/service/logger/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IOContext } from '../../service/typings'
22
import { cleanError } from '../../utils/error'
3+
import { cleanLog } from '../../utils/log'
34

45
const linked = !!process.env.VTEX_APP_LINK
56
const app = process.env.VTEX_APP_ID
@@ -44,7 +45,9 @@ export class Logger {
4445

4546
public log = (message: any, level: LogLevel): void => {
4647
const data = message ? cleanError(message) : EMPTY_MESSAGE
47-
48+
49+
cleanLog(data)
50+
4851
/* tslint:disable:object-literal-sort-keys */
4952
const inflatedLog = {
5053
__VTEX_IO_LOG: true,

src/utils/error.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
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']
65

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

src/utils/log.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const FIRST_LEVEL_SENSITIVE_FIELDS = ['config', 'request', 'stack', 'error']
2+
export const SECOND_LEVEL_SENSITIVE_FIELDS = [ ['parsedInfo', 'requestConfig'], ['headers', 'cookie'] ]
3+
4+
export const cleanLog = (log: any) => {
5+
FIRST_LEVEL_SENSITIVE_FIELDS.forEach(field => {
6+
delete log[field]
7+
})
8+
9+
SECOND_LEVEL_SENSITIVE_FIELDS.forEach(field => {
10+
if (field[0] in log) {
11+
delete log[field[0]][field[1]]
12+
}
13+
})
14+
}

0 commit comments

Comments
 (0)