@lumigo/node-core
Advanced tools
Comparing version 1.12.0 to 1.12.1
@@ -7,4 +7,3 @@ import { HttpRawRequest, HttpRawResponse, RequestRawData } from '../types/spans'; | ||
export declare function scrubRequestDataPayload(requestData: HttpRawRequest | HttpRawResponse): string; | ||
export declare const shouldScrubDomain: (url: any, domains?: any) => boolean; | ||
export declare const spanHasErrors: (requestRawData: RequestRawData) => boolean; | ||
export declare const decodeHttpBody: (httpBody: any, hasError: boolean) => any | string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decodeHttpBody = exports.spanHasErrors = exports.shouldScrubDomain = exports.scrubRequestDataPayload = exports.scrub = exports.payloadStringify = exports.prune = exports.keyToOmitRegexes = void 0; | ||
exports.decodeHttpBody = exports.spanHasErrors = exports.scrubRequestDataPayload = exports.scrub = exports.payloadStringify = exports.prune = exports.keyToOmitRegexes = void 0; | ||
const utils_1 = require("../utils"); | ||
@@ -146,7 +146,2 @@ const utils_2 = require("../utils"); | ||
exports.scrubRequestDataPayload = scrubRequestDataPayload; | ||
const domainScrubbers = () => JSON.parse(process.env.LUMIGO_DOMAINS_SCRUBBER || utils_1.LUMIGO_DEFAULT_DOMAIN_SCRUBBERS).map((x) => new RegExp(x, 'i')); | ||
const shouldScrubDomain = (url, domains = domainScrubbers()) => { | ||
return !!url && domains.some((regex) => url.match(regex)); | ||
}; | ||
exports.shouldScrubDomain = shouldScrubDomain; | ||
const spanHasErrors = (requestRawData) => { var _a; return !!(requestRawData.hasError || ((_a = requestRawData.response) === null || _a === void 0 ? void 0 : _a.statusCode) >= 400); }; | ||
@@ -161,42 +156,2 @@ exports.spanHasErrors = spanHasErrors; | ||
exports.decodeHttpBody = decodeHttpBody; | ||
const scrubRequest = (requestData) => { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
const res = { | ||
host: requestData.host, | ||
uri: requestData.uri, | ||
request: { | ||
truncated: ((_a = requestData === null || requestData === void 0 ? void 0 : requestData.request) === null || _a === void 0 ? void 0 : _a.truncated) || false, | ||
}, | ||
response: { | ||
truncated: ((_b = requestData === null || requestData === void 0 ? void 0 : requestData.request) === null || _b === void 0 ? void 0 : _b.truncated) || false, | ||
}, | ||
}; | ||
const { request, response, host } = requestData; | ||
if ((requestData.response && request && (0, exports.shouldScrubDomain)(host)) || | ||
(((_c = requestData.request) === null || _c === void 0 ? void 0 : _c.host) && (0, exports.shouldScrubDomain)(request.host)) || | ||
(((_d = requestData.response) === null || _d === void 0 ? void 0 : _d.host) && (0, exports.shouldScrubDomain)(response.host))) { | ||
res.request.body = 'The data is not available'; | ||
res.response.body = 'The data is not available'; | ||
delete requestData.request.headers; | ||
delete requestData.response.headers; | ||
delete res.uri; | ||
} | ||
else { | ||
const isError = (0, exports.spanHasErrors)(requestData); | ||
res.hasError = isError; | ||
const sizeLimit = (0, utils_1.getEventEntitySize)(isError); | ||
if ((_e = requestData.response) === null || _e === void 0 ? void 0 : _e.body) { | ||
res.response.body = scrubRequestDataPayload(requestData.response); | ||
} | ||
if ((_f = requestData.request) === null || _f === void 0 ? void 0 : _f.body) { | ||
res.request.body = scrubRequestDataPayload(requestData.response); | ||
} | ||
if ((_g = requestData.request) === null || _g === void 0 ? void 0 : _g.headers) { | ||
res.request.headers = (0, exports.payloadStringify)(requestData.request.headers, sizeLimit); | ||
} | ||
if ((_h = requestData.response) === null || _h === void 0 ? void 0 : _h.headers) | ||
res.response.headers = (0, exports.payloadStringify)(requestData.response.headers, sizeLimit); | ||
} | ||
return res; | ||
}; | ||
//# sourceMappingURL=httpUtils.js.map |
@@ -12,8 +12,12 @@ export declare type LogSeverity = 'INFO' | 'WARNING' | 'FATAL' | 'DEBUG'; | ||
log: (levelname: LogSeverity, msg: string, obj?: LogObject) => void; | ||
warnClient: (msg: string, obj?: LogObject) => void; | ||
warnClient: (msg: string, obj?: LogObject) => boolean; | ||
debug: (msg: string, obj?: LogObject) => void; | ||
LOG_LEVELS: Record<LogSeverity, LogSeverity>; | ||
} | ||
export declare const LogStore: { | ||
addLog: (type: any, message: any, object: any) => void; | ||
clean: () => void; | ||
}; | ||
export declare const setLogger: (logger: LoggerInterface) => LoggerInterface; | ||
export declare const setLoggerPrefix: (prefix: string) => string; | ||
export declare const getLogger: () => LoggerInterface; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getLogger = exports.setLoggerPrefix = exports.setLogger = exports.LOG_LEVELS = void 0; | ||
exports.getLogger = exports.setLoggerPrefix = exports.setLogger = exports.LogStore = exports.LOG_LEVELS = void 0; | ||
const utils_1 = require("./utils"); | ||
const WARN_CLIENT_PREFIX = 'Lumigo Warning'; | ||
let LOG_PREFIX = '#LUMIGO#'; | ||
const MAX_DUPLICATE_LOGS = 50; | ||
exports.LOG_LEVELS = { | ||
@@ -12,2 +14,42 @@ INFO: 'INFO', | ||
}; | ||
const removeCircleFromJson = () => { | ||
const cache = []; | ||
return (key, value) => { | ||
if (typeof value === 'object' && value !== null) { | ||
// Duplicate reference found, discard key | ||
if (cache.includes(value)) | ||
return; | ||
// Store value in our collection | ||
cache.push(value); | ||
} | ||
return value; | ||
}; | ||
}; | ||
exports.LogStore = (() => { | ||
let logSet = new Set([]); | ||
let duplicateLogsCount = 0; | ||
const addLog = (type, message, object) => { | ||
const logObj = JSON.stringify({ type, message, object }, removeCircleFromJson()); | ||
if (!logSet.has(logObj)) { | ||
logSet.add(logObj); | ||
} | ||
else { | ||
duplicateLogsCount++; | ||
} | ||
isEmergencyMode() && printLogs(); | ||
}; | ||
const printLogs = () => { | ||
logSet.forEach((logObj) => { | ||
const { message, obj } = JSON.parse(logObj); | ||
forceLog('FATAL', message, obj); | ||
}); | ||
logSet.clear(); | ||
}; | ||
const isEmergencyMode = () => duplicateLogsCount >= MAX_DUPLICATE_LOGS; | ||
const clean = () => { | ||
logSet = new Set([]); | ||
duplicateLogsCount = 0; | ||
}; | ||
return { addLog, clean }; | ||
})(); | ||
/** | ||
@@ -36,3 +78,7 @@ @deprecated | ||
const log = (levelname, message, obj) => { | ||
forceLog(levelname, message, obj); | ||
const storeLogsIsOn = (0, utils_1.isStoreLogs)(); | ||
storeLogsIsOn && exports.LogStore.addLog(levelname, message, obj); | ||
if ((0, utils_1.isDebug)() && !storeLogsIsOn) { | ||
forceLog(levelname, message, obj); | ||
} | ||
}; | ||
@@ -39,0 +85,0 @@ const invokeLog = (type) => (msg, obj = undefined) => log(type, msg, obj); |
export declare const LUMIGO_SECRET_MASKING_REGEX_BACKWARD_COMP = "LUMIGO_BLACKLIST_REGEX"; | ||
export declare const LUMIGO_SECRET_MASKING_REGEX = "LUMIGO_SECRET_MASKING_REGEX"; | ||
export declare const LUMIGO_WHITELIST_KEYS_REGEXES = "LUMIGO_WHITELIST_KEYS_REGEXES"; | ||
export declare const LUMIGO_DEFAULT_DOMAIN_SCRUBBERS = "[\"secretsmanager.*.amazonaws.com\", \"ssm.*.amazonaws.com\", \"kms.*.amazonaws.com\", \"sts..*amazonaws.com\"]"; | ||
export declare const OMITTING_KEYS_REGEXES: string[]; | ||
export declare function isString(x: any): x is string; | ||
export declare const isStoreLogs: () => boolean; | ||
export declare function isString(x: any): x is string; | ||
export declare const setStoreLogsOn: () => string; | ||
export declare const isDebug: () => boolean; | ||
export declare const setDebug: () => string; | ||
export declare const setWarm: () => string; | ||
export declare const isWarm: () => boolean; | ||
export declare const LUMIGO_MAX_ENTRY_SIZE = 2048; | ||
@@ -9,0 +13,0 @@ export declare const getEventEntitySize: (hasError?: boolean) => number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.safeExecute = exports.parseJsonFromEnvVar = exports.getEventEntitySize = exports.LUMIGO_MAX_ENTRY_SIZE = exports.isString = exports.isStoreLogs = exports.OMITTING_KEYS_REGEXES = exports.LUMIGO_DEFAULT_DOMAIN_SCRUBBERS = exports.LUMIGO_WHITELIST_KEYS_REGEXES = exports.LUMIGO_SECRET_MASKING_REGEX = exports.LUMIGO_SECRET_MASKING_REGEX_BACKWARD_COMP = void 0; | ||
exports.safeExecute = exports.parseJsonFromEnvVar = exports.getEventEntitySize = exports.LUMIGO_MAX_ENTRY_SIZE = exports.isWarm = exports.setWarm = exports.setDebug = exports.isDebug = exports.setStoreLogsOn = exports.isStoreLogs = exports.isString = exports.OMITTING_KEYS_REGEXES = exports.LUMIGO_WHITELIST_KEYS_REGEXES = exports.LUMIGO_SECRET_MASKING_REGEX = exports.LUMIGO_SECRET_MASKING_REGEX_BACKWARD_COMP = void 0; | ||
const logger_1 = require("./logger"); | ||
const DEBUG_FLAG = 'LUMIGO_DEBUG'; | ||
const STORE_LOGS_FLAG = 'LUMIGO_STORE_LOGS'; | ||
const WARM_FLAG = 'LUMIGO_IS_WARM'; | ||
exports.LUMIGO_SECRET_MASKING_REGEX_BACKWARD_COMP = 'LUMIGO_BLACKLIST_REGEX'; | ||
exports.LUMIGO_SECRET_MASKING_REGEX = 'LUMIGO_SECRET_MASKING_REGEX'; | ||
exports.LUMIGO_WHITELIST_KEYS_REGEXES = 'LUMIGO_WHITELIST_KEYS_REGEXES'; | ||
exports.LUMIGO_DEFAULT_DOMAIN_SCRUBBERS = '["secretsmanager.*.amazonaws.com", "ssm.*.amazonaws.com", "kms.*.amazonaws.com", "sts..*amazonaws.com"]'; | ||
exports.OMITTING_KEYS_REGEXES = [ | ||
@@ -22,6 +23,2 @@ '.*pass.*', | ||
]; | ||
const STORE_LOGS_FLAG = 'LUMIGO_STORE_LOGS'; | ||
const validateEnvVar = (envVar, value = 'TRUE') => !!(process.env[envVar] && process.env[envVar].toUpperCase() === value.toUpperCase()); | ||
const isStoreLogs = () => validateEnvVar(STORE_LOGS_FLAG); | ||
exports.isStoreLogs = isStoreLogs; | ||
function isString(x) { | ||
@@ -31,2 +28,15 @@ return Object.prototype.toString.call(x) === '[object String]'; | ||
exports.isString = isString; | ||
const isStoreLogs = () => validateEnvVar(STORE_LOGS_FLAG); | ||
exports.isStoreLogs = isStoreLogs; | ||
const validateEnvVar = (envVar, value = 'TRUE') => !!(process.env[envVar] && process.env[envVar].toUpperCase() === value.toUpperCase()); | ||
const setStoreLogsOn = () => (process.env[STORE_LOGS_FLAG] = 'TRUE'); | ||
exports.setStoreLogsOn = setStoreLogsOn; | ||
const isDebug = () => validateEnvVar(DEBUG_FLAG); | ||
exports.isDebug = isDebug; | ||
const setDebug = () => (process.env['LUMIGO_DEBUG'] = 'TRUE'); | ||
exports.setDebug = setDebug; | ||
const setWarm = () => (process.env[WARM_FLAG] = 'TRUE'); | ||
exports.setWarm = setWarm; | ||
const isWarm = () => validateEnvVar(WARM_FLAG); | ||
exports.isWarm = isWarm; | ||
exports.LUMIGO_MAX_ENTRY_SIZE = 2048; | ||
@@ -50,3 +60,3 @@ const getEventEntitySize = (hasError = false) => { | ||
} | ||
return undefined; | ||
return defaultReturnValue; | ||
}; | ||
@@ -66,20 +76,2 @@ exports.parseJsonFromEnvVar = parseJsonFromEnvVar; | ||
exports.safeExecute = safeExecute; | ||
const recursiveGetKeyByDepth = (event, keyToSearch, maxDepth) => { | ||
if (maxDepth === 0) { | ||
return undefined; | ||
} | ||
let foundValue = undefined; | ||
const examineKey = (k) => { | ||
if (k === keyToSearch) { | ||
foundValue = event[k]; | ||
return true; | ||
} | ||
if (event[k] && typeof event[k] === 'object') { | ||
foundValue = recursiveGetKeyByDepth(event[k], keyToSearch, maxDepth - 1); | ||
return foundValue !== undefined; | ||
} | ||
}; | ||
Object.keys(event).some(examineKey); | ||
return foundValue; | ||
}; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@lumigo/node-core", | ||
"version": "1.12.0", | ||
"version": "1.12.1", | ||
"description": "Lumigo core node sdk", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,3 +0,24 @@ | ||
# node-core | ||
# node-core :stars: | ||
[![CircleCI](https://circleci.com/gh/lumigo-io/lumigo-node.svg?style=svg&circle-token=47f40cb5e95e8532e73f69754fac65830b5e86a1)](https://circleci.com/gh/lumigo-io/lumigo-core) | ||
[![codecov](https://codecov.io/gh/lumigo-io/lumigo-node/branch/master/graph/badge.svg?token=mUkKlI8ifC)](https://codecov.io/gh/lumigo-io/lumigo-core) | ||
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) | ||
Work in progress | ||
This is [`@lumigo/node-core`](https://), Lumigo's Node.js agent core tracing logic for distributed tracing and performance monitoring. | ||
it is used by all our Node tracers to perform manny of the shared logic across services | ||
Supported NodeJS runtimes: 8.10, 10.x, 12.x, 14.x | ||
## Configuration | ||
`@lumigo/node-core` offers several different configuration options. Pass these to the Lambda function as environment variables: | ||
* `LUMIGO_DEBUG=TRUE` - Enables debug logging | ||
* `LUMIGO_SECRET_MASKING_REGEX='["regex1", "regex2"]'` - Prevents Lumigo from sending keys that match the supplied regular expressions. All regular expressions are case-insensitive. By default, Lumigo applies the following regular expressions: `[".*pass.*", ".*key.*", ".*secret.*", ".*credential.*", ".*passphrase.*"]`. | ||
* `LUMIGO_DOMAINS_SCRUBBER='[".*secret.*"]'` - Prevents Lumigo from collecting both request and response details from a list of domains. This accepts a comma-separated list of regular expressions that is JSON-formatted. By default, the tracer uses `["secretsmanager\..*\.amazonaws\.com", "ssm\..*\.amazonaws\.com", "kms\..*\.amazonaws\.com"]`. **Note** - These defaults are overridden when you define a different list of regular expressions. | ||
## Functionality | ||
### Secret masking: | ||
Secrets scrubbing by list for regexes: | ||
* support only json data secrets scrubbing |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
24
107154
53
1107
12