@vtex/api 3.77.4 → 3.77.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [3.77.5] - 2022-02-24
11
+ ### Fixed
12
+ - Remove sensitive data from logs.
13
+
10
14
  ## [3.77.4] - 2021-10-22
11
15
 
12
16
  ## [3.77.3] - 2021-10-22
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const apollo_server_errors_1 = require("apollo-server-errors");
4
4
  const ramda_1 = require("ramda");
5
5
  const error_1 = require("../../../utils/error");
6
+ const log_1 = require("../../../utils/log");
6
7
  const ERROR_FIELD_WHITELIST = ['message', 'path', 'stack', 'extensions', 'statusCode', 'name', 'headers', 'originalError', 'code'];
7
8
  // formatError overrides the default option in runHttpQuery, which
8
9
  // does not keep track of the error stack. All non-enumerable
@@ -21,11 +22,11 @@ const createFormatError = (details) => (error) => {
21
22
  delete formattedError.originalError.stack;
22
23
  }
23
24
  if (!formattedError.extensions.exception) {
24
- formattedError.extensions.exception = Object.assign({ message: formattedError.originalError.message, name: formattedError.originalError.name }, ramda_1.omit(error_1.SENSITIVE_EXCEPTION_FIELDS, formattedError.originalError), { sensitive: ramda_1.pick(error_1.SENSITIVE_EXCEPTION_FIELDS, formattedError.originalError) });
25
+ formattedError.extensions.exception = Object.assign({ message: formattedError.originalError.message, name: formattedError.originalError.name }, ramda_1.omit(log_1.FIRST_LEVEL_SENSITIVE_FIELDS, formattedError.originalError), { sensitive: ramda_1.pick(log_1.FIRST_LEVEL_SENSITIVE_FIELDS, formattedError.originalError) });
25
26
  }
26
27
  else {
27
28
  const mergedExceptions = Object.assign({}, formattedError.originalError, formattedError.extensions.exception);
28
- const extendedException = Object.assign({ message: formattedError.originalError.message, name: formattedError.originalError.name }, ramda_1.omit(error_1.SENSITIVE_EXCEPTION_FIELDS, mergedExceptions), { sensitive: ramda_1.pick(error_1.SENSITIVE_EXCEPTION_FIELDS, mergedExceptions) });
29
+ const extendedException = Object.assign({ message: formattedError.originalError.message, name: formattedError.originalError.name }, ramda_1.omit(log_1.FIRST_LEVEL_SENSITIVE_FIELDS, mergedExceptions), { sensitive: ramda_1.pick(log_1.FIRST_LEVEL_SENSITIVE_FIELDS, mergedExceptions) });
29
30
  formattedError.extensions.exception = error_1.cleanError(extendedException);
30
31
  }
31
32
  // Make originalError not enumerable to prevent duplicated log and response information
@@ -5,6 +5,7 @@ const constants_1 = require("../../../constants");
5
5
  const RequestCancelledError_1 = require("../../../errors/RequestCancelledError");
6
6
  const TooManyRequestsError_1 = require("../../../errors/TooManyRequestsError");
7
7
  const error_1 = require("../../../utils/error");
8
+ const log_1 = require("../../../utils/log");
8
9
  const CACHE_CONTROL_HEADER = 'cache-control';
9
10
  const META_HEADER = 'x-vtex-meta';
10
11
  const ETAG_HEADER = 'etag';
@@ -32,7 +33,7 @@ const logAndRemoveSensitiveData = (ctx, err) => {
32
33
  // Use sendLog directly to avoid cleaning error twice.
33
34
  ctx.vtex.logger.log(log, level);
34
35
  if (!constants_1.LINKED) {
35
- error_1.SENSITIVE_EXCEPTION_FIELDS.forEach(field => {
36
+ log_1.FIRST_LEVEL_SENSITIVE_FIELDS.forEach(field => {
36
37
  delete err[field];
37
38
  });
38
39
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const error_1 = require("../../utils/error");
4
+ const log_1 = require("../../utils/log");
4
5
  const linked = !!process.env.VTEX_APP_LINK;
5
6
  const app = process.env.VTEX_APP_ID;
6
7
  const EMPTY_MESSAGE = 'Logger.log was called with null or undefined message';
@@ -22,6 +23,7 @@ class Logger {
22
23
  this.error = (error) => this.log(error, LogLevel.Error);
23
24
  this.log = (message, level) => {
24
25
  const data = message ? error_1.cleanError(message) : EMPTY_MESSAGE;
26
+ log_1.cleanLog(data);
25
27
  /* tslint:disable:object-literal-sort-keys */
26
28
  const inflatedLog = {
27
29
  __VTEX_IO_LOG: true,
@@ -1,5 +1,4 @@
1
1
  export declare const PICKED_AXIOS_PROPS: string[];
2
- export declare const SENSITIVE_EXCEPTION_FIELDS: string[];
3
2
  /**
4
3
  * Cleans errors by removing circular properties, truncating large strings and picking axios properties
5
4
  *
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // Inspired by https://github.com/sindresorhus/serialize-error
4
4
  const ramda_1 = require("ramda");
5
5
  exports.PICKED_AXIOS_PROPS = ['baseURL', 'cacheable', 'data', 'finished', 'headers', 'method', 'timeout', 'status', 'path', 'url', 'metric', 'inflightKey', 'forceMaxAge', 'params', 'responseType'];
6
- exports.SENSITIVE_EXCEPTION_FIELDS = ['config', 'request', 'stack'];
7
6
  const MAX_ERROR_STRING_LENGTH = process.env.MAX_ERROR_STRING_LENGTH ? parseInt(process.env.MAX_ERROR_STRING_LENGTH, 10) : 8 * 1024;
8
7
  const findCaseInsensitive = (target, set) => ramda_1.find(t => t.toLocaleLowerCase() === target, set);
9
8
  const destroyCircular = (from, seen) => {
@@ -0,0 +1,3 @@
1
+ export declare const FIRST_LEVEL_SENSITIVE_FIELDS: string[];
2
+ export declare const SECOND_LEVEL_SENSITIVE_FIELDS: string[][];
3
+ export declare const cleanLog: (log: any) => void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FIRST_LEVEL_SENSITIVE_FIELDS = ['config', 'request', 'stack', 'error'];
4
+ exports.SECOND_LEVEL_SENSITIVE_FIELDS = [['parsedInfo', 'requestConfig'], ['headers', 'cookie']];
5
+ exports.cleanLog = (log) => {
6
+ exports.FIRST_LEVEL_SENSITIVE_FIELDS.forEach(field => {
7
+ delete log[field];
8
+ });
9
+ exports.SECOND_LEVEL_SENSITIVE_FIELDS.forEach(field => {
10
+ if (field[0] in log) {
11
+ delete log[field[0]][field[1]];
12
+ }
13
+ });
14
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/api",
3
- "version": "3.77.4",
3
+ "version": "3.77.5",
4
4
  "description": "VTEX I/O API client",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",