@vtex/api 6.45.4 → 6.45.7
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 +18 -0
- package/lib/clients/janus/Segment.d.ts +1 -1
- package/lib/clients/janus/Segment.js +16 -7
- package/lib/clients/janus/Session.js +2 -2
- package/lib/service/logger/logger.js +2 -0
- package/lib/service/worker/runtime/graphql/utils/error.js +5 -4
- package/lib/service/worker/runtime/http/middlewares/error.js +2 -1
- package/lib/utils/error.d.ts +0 -1
- package/lib/utils/error.js +0 -1
- package/lib/utils/log.d.ts +3 -0
- package/lib/utils/log.js +14 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [6.45.7] - 2022-02-23
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Remove sensitive data from logs.
|
|
15
|
+
|
|
16
|
+
## [6.45.6] - 2021-10-26
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- `vtex_segment` cookie extraction
|
|
21
|
+
|
|
22
|
+
## [6.54.5] - 2021-10-22
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- Extract session cookie in a safe manner
|
|
27
|
+
|
|
10
28
|
## [6.45.4] - 2021-09-16
|
|
11
29
|
|
|
12
30
|
### Removed
|
|
@@ -30,7 +30,7 @@ export declare class Segment extends JanusClient {
|
|
|
30
30
|
getSegmentByToken: (token: string | null, tracingConfig?: RequestTracingConfig | undefined) => Promise<SegmentData>;
|
|
31
31
|
getOrCreateSegment: (query?: Record<string, string> | undefined, token?: string | undefined, tracingConfig?: RequestTracingConfig | undefined) => Promise<{
|
|
32
32
|
segmentData: SegmentData;
|
|
33
|
-
segmentToken: string;
|
|
33
|
+
segmentToken: string | null;
|
|
34
34
|
}>;
|
|
35
35
|
private rawSegment;
|
|
36
36
|
}
|
|
@@ -25,7 +25,7 @@ const filterAndSortQuery = (query) => {
|
|
|
25
25
|
};
|
|
26
26
|
const routes = {
|
|
27
27
|
base: '/api/segments',
|
|
28
|
-
segments: (token) => token ? `${routes.base}/${token}` : routes.base,
|
|
28
|
+
segments: (token) => (token ? `${routes.base}/${token}` : routes.base),
|
|
29
29
|
};
|
|
30
30
|
class Segment extends JanusClient_1.JanusClient {
|
|
31
31
|
constructor() {
|
|
@@ -43,19 +43,17 @@ class Segment extends JanusClient_1.JanusClient {
|
|
|
43
43
|
*/
|
|
44
44
|
this.getSegmentByToken = (token, tracingConfig) => this.rawSegment(token, undefined, tracingConfig).then(ramda_1.prop('data'));
|
|
45
45
|
this.getOrCreateSegment = async (query, token, tracingConfig) => {
|
|
46
|
-
const { data: segmentData, headers
|
|
47
|
-
const parsedCookie = cookie_1.default.parse(setCookies);
|
|
48
|
-
const segmentToken = ramda_1.prop(SEGMENT_COOKIE, parsedCookie);
|
|
46
|
+
const { data: segmentData, headers } = await this.rawSegment(token, query, tracingConfig);
|
|
49
47
|
return {
|
|
50
48
|
segmentData,
|
|
51
|
-
segmentToken,
|
|
49
|
+
segmentToken: extractSegmentCookie(headers),
|
|
52
50
|
};
|
|
53
51
|
};
|
|
54
52
|
this.rawSegment = (token, query, tracingConfig) => {
|
|
55
53
|
const { product, workspace } = this.context;
|
|
56
54
|
const filteredQuery = filterAndSortQuery(query);
|
|
57
55
|
const metric = token ? 'segment-get-token' : 'segment-get-new';
|
|
58
|
-
return this.http.getRaw(routes.segments(token),
|
|
56
|
+
return this.http.getRaw(routes.segments(token), {
|
|
59
57
|
forceMaxAge: SEGMENT_MAX_AGE_S,
|
|
60
58
|
headers: {
|
|
61
59
|
'Content-Type': 'application/json',
|
|
@@ -72,8 +70,19 @@ class Segment extends JanusClient_1.JanusClient {
|
|
|
72
70
|
requestSpanNameSuffix: metric,
|
|
73
71
|
...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
|
|
74
72
|
},
|
|
75
|
-
})
|
|
73
|
+
});
|
|
76
74
|
};
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
77
|
exports.Segment = Segment;
|
|
78
|
+
function extractSegmentCookie(headers) {
|
|
79
|
+
var _a;
|
|
80
|
+
for (const setCookie of (_a = headers['set-cookie']) !== null && _a !== void 0 ? _a : []) {
|
|
81
|
+
const parsedCookie = cookie_1.default.parse(setCookie);
|
|
82
|
+
const segmentCookie = parsedCookie[SEGMENT_COOKIE];
|
|
83
|
+
if (segmentCookie != null) {
|
|
84
|
+
return segmentCookie;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
@@ -21,7 +21,7 @@ class Session extends JanusClient_1.JanusClient {
|
|
|
21
21
|
const { data: sessionData, headers } = await this.http.getRaw(routes.base, {
|
|
22
22
|
headers: {
|
|
23
23
|
'Content-Type': 'application/json',
|
|
24
|
-
|
|
24
|
+
Cookie: `vtex_session=${token};`,
|
|
25
25
|
},
|
|
26
26
|
metric,
|
|
27
27
|
params: {
|
|
@@ -46,7 +46,7 @@ class Session extends JanusClient_1.JanusClient {
|
|
|
46
46
|
const config = {
|
|
47
47
|
headers: {
|
|
48
48
|
'Content-Type': 'application/json',
|
|
49
|
-
|
|
49
|
+
Cookie: `vtex_session=${token};`,
|
|
50
50
|
},
|
|
51
51
|
metric,
|
|
52
52
|
params: {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const constants_1 = require("../../constants");
|
|
4
4
|
const error_1 = require("../../utils/error");
|
|
5
|
+
const log_1 = require("../../utils/log");
|
|
5
6
|
const console_1 = require("./console");
|
|
6
7
|
const linked = !!process.env.VTEX_APP_LINK;
|
|
7
8
|
const app = constants_1.APP.ID;
|
|
@@ -22,6 +23,7 @@ class Logger {
|
|
|
22
23
|
this.log = (message, level) => {
|
|
23
24
|
var _a;
|
|
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,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ramda_1 = require("ramda");
|
|
4
4
|
const error_1 = require("../../../../../utils/error");
|
|
5
|
+
const log_1 = require("../../../../../utils/log");
|
|
5
6
|
const ERROR_FIELD_WHITELIST = ['message', 'path', 'stack', 'extensions', 'statusCode', 'name', 'headers', 'originalError', 'code'];
|
|
6
7
|
const QUERY_FIELDS = ['query', 'operationName', 'variables'];
|
|
7
8
|
const trimVariables = (variables) => {
|
|
@@ -48,8 +49,8 @@ const formatError = (error, details) => {
|
|
|
48
49
|
formattedError.extensions.exception = {
|
|
49
50
|
message: formattedError.originalError.message,
|
|
50
51
|
name: formattedError.originalError.name,
|
|
51
|
-
...ramda_1.omit(
|
|
52
|
-
sensitive: ramda_1.pick(
|
|
52
|
+
...ramda_1.omit(log_1.FIRST_LEVEL_SENSITIVE_FIELDS, formattedError.originalError),
|
|
53
|
+
sensitive: ramda_1.pick(log_1.FIRST_LEVEL_SENSITIVE_FIELDS, formattedError.originalError),
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
else {
|
|
@@ -59,8 +60,8 @@ const formatError = (error, details) => {
|
|
|
59
60
|
const extendedException = {
|
|
60
61
|
message: formattedError.originalError.message,
|
|
61
62
|
name: formattedError.originalError.name,
|
|
62
|
-
...ramda_1.omit(
|
|
63
|
-
sensitive: ramda_1.pick(
|
|
63
|
+
...ramda_1.omit(log_1.FIRST_LEVEL_SENSITIVE_FIELDS, mergedException),
|
|
64
|
+
sensitive: ramda_1.pick(log_1.FIRST_LEVEL_SENSITIVE_FIELDS, mergedException),
|
|
64
65
|
};
|
|
65
66
|
formattedError.extensions.exception = error_1.cleanError(extendedException);
|
|
66
67
|
}
|
|
@@ -4,6 +4,7 @@ const constants_1 = require("../../../../../constants");
|
|
|
4
4
|
const RequestCancelledError_1 = require("../../../../../errors/RequestCancelledError");
|
|
5
5
|
const TooManyRequestsError_1 = require("../../../../../errors/TooManyRequestsError");
|
|
6
6
|
const error_1 = require("../../../../../utils/error");
|
|
7
|
+
const log_1 = require("../../../../../utils/log");
|
|
7
8
|
const logger_1 = require("../../../../logger");
|
|
8
9
|
const CACHE_CONTROL_HEADER = 'cache-control';
|
|
9
10
|
const META_HEADER = 'x-vtex-meta';
|
|
@@ -39,7 +40,7 @@ const logAndRemoveSensitiveData = (ctx, err) => {
|
|
|
39
40
|
// Use sendLog directly to avoid cleaning error twice.
|
|
40
41
|
ctx.vtex.logger.log(log, level);
|
|
41
42
|
if (!constants_1.LINKED) {
|
|
42
|
-
|
|
43
|
+
log_1.FIRST_LEVEL_SENSITIVE_FIELDS.forEach(field => {
|
|
43
44
|
delete err[field];
|
|
44
45
|
});
|
|
45
46
|
}
|
package/lib/utils/error.d.ts
CHANGED
package/lib/utils/error.js
CHANGED
|
@@ -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) => {
|
package/lib/utils/log.js
ADDED
|
@@ -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
|
+
};
|