@vtex/api 3.77.5 → 3.77.6
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 +4 -0
- package/lib/service/graphql/middlewares/formatters.js +2 -3
- package/lib/service/http/middlewares/error.js +1 -2
- package/lib/utils/error.d.ts +1 -0
- package/lib/utils/error.js +1 -0
- package/lib/utils/json.d.ts +5 -0
- package/lib/utils/json.js +18 -0
- package/lib/utils/log.d.ts +5 -3
- package/lib/utils/log.js +3 -10
- package/package.json +1 -1
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.6] - 2022-03-08
|
|
11
|
+
### Fixed
|
|
12
|
+
- Only remove cookie fields when removing sensitive data from logs.
|
|
13
|
+
|
|
10
14
|
## [3.77.5] - 2022-02-24
|
|
11
15
|
### Fixed
|
|
12
16
|
- Remove sensitive data from logs.
|
|
@@ -3,7 +3,6 @@ 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");
|
|
7
6
|
const ERROR_FIELD_WHITELIST = ['message', 'path', 'stack', 'extensions', 'statusCode', 'name', 'headers', 'originalError', 'code'];
|
|
8
7
|
// formatError overrides the default option in runHttpQuery, which
|
|
9
8
|
// does not keep track of the error stack. All non-enumerable
|
|
@@ -22,11 +21,11 @@ const createFormatError = (details) => (error) => {
|
|
|
22
21
|
delete formattedError.originalError.stack;
|
|
23
22
|
}
|
|
24
23
|
if (!formattedError.extensions.exception) {
|
|
25
|
-
formattedError.extensions.exception = Object.assign({ message: formattedError.originalError.message, name: formattedError.originalError.name }, ramda_1.omit(
|
|
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) });
|
|
26
25
|
}
|
|
27
26
|
else {
|
|
28
27
|
const mergedExceptions = Object.assign({}, formattedError.originalError, formattedError.extensions.exception);
|
|
29
|
-
const extendedException = Object.assign({ message: formattedError.originalError.message, name: formattedError.originalError.name }, ramda_1.omit(
|
|
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) });
|
|
30
29
|
formattedError.extensions.exception = error_1.cleanError(extendedException);
|
|
31
30
|
}
|
|
32
31
|
// Make originalError not enumerable to prevent duplicated log and response information
|
|
@@ -5,7 +5,6 @@ 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");
|
|
9
8
|
const CACHE_CONTROL_HEADER = 'cache-control';
|
|
10
9
|
const META_HEADER = 'x-vtex-meta';
|
|
11
10
|
const ETAG_HEADER = 'etag';
|
|
@@ -33,7 +32,7 @@ const logAndRemoveSensitiveData = (ctx, err) => {
|
|
|
33
32
|
// Use sendLog directly to avoid cleaning error twice.
|
|
34
33
|
ctx.vtex.logger.log(log, level);
|
|
35
34
|
if (!constants_1.LINKED) {
|
|
36
|
-
|
|
35
|
+
error_1.SENSITIVE_EXCEPTION_FIELDS.forEach(field => {
|
|
37
36
|
delete err[field];
|
|
38
37
|
});
|
|
39
38
|
}
|
package/lib/utils/error.d.ts
CHANGED
package/lib/utils/error.js
CHANGED
|
@@ -3,6 +3,7 @@ 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'];
|
|
6
7
|
const MAX_ERROR_STRING_LENGTH = process.env.MAX_ERROR_STRING_LENGTH ? parseInt(process.env.MAX_ERROR_STRING_LENGTH, 10) : 8 * 1024;
|
|
7
8
|
const findCaseInsensitive = (target, set) => ramda_1.find(t => t.toLocaleLowerCase() === target, set);
|
|
8
9
|
const destroyCircular = (from, seen) => {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function cleanJson(json, targetFields) {
|
|
4
|
+
for (const key of Object.keys(json)) {
|
|
5
|
+
let deleted = false;
|
|
6
|
+
for (const field of targetFields) {
|
|
7
|
+
if (key === field) {
|
|
8
|
+
delete json[key];
|
|
9
|
+
deleted = true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (!deleted && json[key] && typeof json[key] === 'object') {
|
|
13
|
+
json[key] = cleanJson(json[key], targetFields);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return json;
|
|
17
|
+
}
|
|
18
|
+
exports.cleanJson = cleanJson;
|
package/lib/utils/log.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export declare const cleanLog: (log: {
|
|
2
|
+
[k: string]: any;
|
|
3
|
+
}) => {
|
|
4
|
+
[k: string]: any;
|
|
5
|
+
};
|
package/lib/utils/log.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const json_1 = require("./json");
|
|
4
|
+
const SENSITIVE_FIELDS = ['cookie', 'Cookie', 'vtexIdclientautcookie', 'error'];
|
|
5
5
|
exports.cleanLog = (log) => {
|
|
6
|
-
|
|
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
|
-
});
|
|
6
|
+
return json_1.cleanJson(log, SENSITIVE_FIELDS);
|
|
14
7
|
};
|