@vtex/api 3.77.2 → 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 +14 -0
- package/lib/clients/Segment.d.ts +1 -1
- package/lib/clients/Segment.js +3 -9
- package/lib/clients/Session.d.ts +1 -0
- package/lib/clients/Session.js +13 -5
- package/lib/service/graphql/middlewares/formatters.js +3 -2
- package/lib/service/http/middlewares/error.js +2 -1
- package/lib/service/logger/index.js +2 -0
- 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,20 @@ 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
|
+
|
|
14
|
+
## [3.77.4] - 2021-10-22
|
|
15
|
+
|
|
16
|
+
## [3.77.3] - 2021-10-22
|
|
17
|
+
### Fixed
|
|
18
|
+
- Extract session cookie in a safe manner
|
|
19
|
+
|
|
20
|
+
## [3.77.2] - 2021-08-26
|
|
21
|
+
### Fixed
|
|
22
|
+
- Extract session cookie in a safe manner
|
|
23
|
+
|
|
10
24
|
## [3.77.1] - 2021-02-05
|
|
11
25
|
- Increase HTTP agents connection pools freeSockets and lifetime
|
|
12
26
|
|
package/lib/clients/Segment.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare class Segment extends JanusClient {
|
|
|
34
34
|
getSegmentByToken: (token: string | null) => Promise<SegmentData>;
|
|
35
35
|
getOrCreateSegment: (query?: Record<string, string> | undefined, token?: string | undefined) => Promise<{
|
|
36
36
|
segmentData: SegmentData;
|
|
37
|
-
segmentToken: string;
|
|
37
|
+
segmentToken: string | undefined;
|
|
38
38
|
}>;
|
|
39
39
|
private rawSegment;
|
|
40
40
|
}
|
package/lib/clients/Segment.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const cookie_1 = __importDefault(require("cookie"));
|
|
7
3
|
const ramda_1 = require("ramda");
|
|
8
4
|
const constants_1 = require("../constants");
|
|
9
5
|
const HttpClient_1 = require("../HttpClient");
|
|
10
|
-
const
|
|
6
|
+
const Session_1 = require("./Session");
|
|
11
7
|
const SEGMENT_MAX_AGE_S = 60 * 60; // 60 minutes - segment is actually immutable
|
|
12
8
|
const ALLOWED_QUERY_PREFIXES = ['utm', 'cultureInfo', 'supportedLocales'];
|
|
13
9
|
const filterAndSortQuery = (query) => {
|
|
@@ -48,12 +44,10 @@ class Segment extends HttpClient_1.JanusClient {
|
|
|
48
44
|
*/
|
|
49
45
|
this.getSegmentByToken = (token) => this.rawSegment(token).then(ramda_1.prop('data'));
|
|
50
46
|
this.getOrCreateSegment = async (query, token) => {
|
|
51
|
-
const { data: segmentData, headers
|
|
52
|
-
const parsedCookie = cookie_1.default.parse(setCookies);
|
|
53
|
-
const segmentToken = ramda_1.prop(SEGMENT_COOKIE, parsedCookie);
|
|
47
|
+
const { data: segmentData, headers, } = await this.rawSegment(token, query);
|
|
54
48
|
return {
|
|
55
49
|
segmentData,
|
|
56
|
-
segmentToken,
|
|
50
|
+
segmentToken: Session_1.extractSessionCookie(headers) || token,
|
|
57
51
|
};
|
|
58
52
|
};
|
|
59
53
|
this.rawSegment = (token, query) => {
|
package/lib/clients/Session.d.ts
CHANGED
package/lib/clients/Session.js
CHANGED
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const cookie_1 = __importDefault(require("cookie"));
|
|
7
|
-
const ramda_1 = require("ramda");
|
|
8
7
|
const HttpClient_1 = require("./../HttpClient");
|
|
9
8
|
const SESSION_COOKIE = 'vtex_session';
|
|
10
9
|
const routes = {
|
|
@@ -17,7 +16,7 @@ class Session extends HttpClient_1.JanusClient {
|
|
|
17
16
|
* Get the session data using the given token
|
|
18
17
|
*/
|
|
19
18
|
this.getSession = async (token, items) => {
|
|
20
|
-
const { data: sessionData, headers
|
|
19
|
+
const { data: sessionData, headers } = await this.http.getRaw(routes.base, ({
|
|
21
20
|
headers: {
|
|
22
21
|
'Content-Type': 'application/json',
|
|
23
22
|
'Cookie': `vtex_session=${token};`,
|
|
@@ -27,11 +26,9 @@ class Session extends HttpClient_1.JanusClient {
|
|
|
27
26
|
items: items.join(','),
|
|
28
27
|
},
|
|
29
28
|
}));
|
|
30
|
-
const parsedCookie = cookie_1.default.parse(setCookies);
|
|
31
|
-
const sessionToken = ramda_1.prop(SESSION_COOKIE, parsedCookie);
|
|
32
29
|
return {
|
|
33
30
|
sessionData,
|
|
34
|
-
sessionToken,
|
|
31
|
+
sessionToken: extractSessionCookie(headers) || token,
|
|
35
32
|
};
|
|
36
33
|
};
|
|
37
34
|
/**
|
|
@@ -54,3 +51,14 @@ class Session extends HttpClient_1.JanusClient {
|
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
53
|
exports.Session = Session;
|
|
54
|
+
function extractSessionCookie(headers) {
|
|
55
|
+
for (const setCookie of headers['set-cookie'] || []) {
|
|
56
|
+
const parsedCookie = cookie_1.default.parse(setCookie);
|
|
57
|
+
const sessionCookie = parsedCookie[SESSION_COOKIE];
|
|
58
|
+
if (sessionCookie != null) {
|
|
59
|
+
return sessionCookie;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
exports.extractSessionCookie = extractSessionCookie;
|
|
@@ -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(
|
|
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(
|
|
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
|
-
|
|
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,
|
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
|
+
};
|