@riocrypto/common-server 1.0.1716 → 1.0.1718
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.
|
@@ -6,11 +6,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const logger_1 = __importDefault(require("../services/logger"));
|
|
8
8
|
const axiosWithLogging = axios_1.default.create();
|
|
9
|
+
const sensitiveHeaders = [
|
|
10
|
+
"Authorization",
|
|
11
|
+
"x-api-key",
|
|
12
|
+
"Api-Key",
|
|
13
|
+
"x-cluster-api-key",
|
|
14
|
+
"X-API-KEY",
|
|
15
|
+
"CB-ACCESS-KEY",
|
|
16
|
+
"CB-ACCESS-SIGN",
|
|
17
|
+
"CB-ACCESS-TIMESTAMP",
|
|
18
|
+
"CB-ACCESS-PASSPHRASE",
|
|
19
|
+
];
|
|
20
|
+
function maskHeaderValue(value) {
|
|
21
|
+
return value.length > 4
|
|
22
|
+
? "*".repeat(value.length - 4) + value.slice(-4)
|
|
23
|
+
: value;
|
|
24
|
+
}
|
|
25
|
+
// Masking function to selectively mask headers
|
|
26
|
+
function maskHeaders(headers) {
|
|
27
|
+
const maskedHeaders = Object.assign({}, headers);
|
|
28
|
+
Object.keys(maskedHeaders).forEach((header) => {
|
|
29
|
+
if (sensitiveHeaders.includes(header)) {
|
|
30
|
+
maskedHeaders[header] = maskHeaderValue(maskedHeaders[header]);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return maskedHeaders;
|
|
34
|
+
}
|
|
9
35
|
// Request Interceptor
|
|
10
36
|
axiosWithLogging.interceptors.request.use((config) => {
|
|
11
37
|
var _a;
|
|
12
|
-
//
|
|
13
|
-
const
|
|
38
|
+
// Mask sensitive headers in the configuration
|
|
39
|
+
const maskedHeaders = maskHeaders(config.headers);
|
|
40
|
+
// Combine and log the full request configuration with masked headers
|
|
41
|
+
const logMessage = `Request: method=${config.method}, url=${config.url}, headers=${JSON.stringify(maskedHeaders)}, data=${JSON.stringify(config.data)}`;
|
|
14
42
|
((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(logMessage)) || console.log(logMessage);
|
|
15
43
|
return config;
|
|
16
44
|
}, (error) => {
|
package/build/services/logger.js
CHANGED
|
@@ -93,6 +93,7 @@ class LoggerService {
|
|
|
93
93
|
format: winston_1.format.combine(winston_1.format.timestamp(), this.maskSensitiveData(), winston_1.format.json(), winston_1.format.prettyPrint()),
|
|
94
94
|
transports: [
|
|
95
95
|
new winston_1.transports.Console(),
|
|
96
|
+
//@ts-ignore
|
|
96
97
|
getWinstonTransport("info", {
|
|
97
98
|
apiKey: process.env.HYPERDX_API_KEY,
|
|
98
99
|
service: process.env.OTEL_SERVICE_NAME,
|