lhisp-logger 3.1.3 → 3.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lhisp-logger",
3
- "version": "3.1.3",
3
+ "version": "3.1.5",
4
4
  "description": "",
5
5
  "main": "src/lhisp-logger",
6
6
  "types": "src/lhisp-logger.d.ts",
@@ -8,8 +8,33 @@ const MAX_STRING_LENGTH = 128;
8
8
  function isProbablyBase64(value) {
9
9
  if (!value || value.length < 16 || value.length % 4 !== 0)
10
10
  return false;
11
- // Base64 strings should only contain valid chars and optional padding.
12
- return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value);
11
+ // Keep this check iterative to avoid regex engine recursion on pathological inputs.
12
+ // Padding can only appear at the end and can be at most two '=' chars.
13
+ let paddingStart = -1;
14
+ for (let i = 0; i < value.length; i++) {
15
+ const code = value.charCodeAt(i);
16
+ const isUpper = code >= 65 && code <= 90; // A-Z
17
+ const isLower = code >= 97 && code <= 122; // a-z
18
+ const isDigit = code >= 48 && code <= 57; // 0-9
19
+ const isPlus = code === 43; // +
20
+ const isSlash = code === 47; // /
21
+ const isPad = code === 61; // =
22
+ if (isPad) {
23
+ if (paddingStart === -1)
24
+ paddingStart = i;
25
+ continue;
26
+ }
27
+ // Non-padding chars after padding started are invalid.
28
+ if (paddingStart !== -1)
29
+ return false;
30
+ if (!(isUpper || isLower || isDigit || isPlus || isSlash)) {
31
+ return false;
32
+ }
33
+ }
34
+ if (paddingStart === -1)
35
+ return true;
36
+ const padCount = value.length - paddingStart;
37
+ return padCount === 1 || padCount === 2;
13
38
  }
14
39
  function truncateString(value, maxLength) {
15
40
  if (value.length <= maxLength)
@@ -20,7 +45,11 @@ function truncateString(value, maxLength) {
20
45
  // Handles arrays, plain objects, and protects against circular structures.
21
46
  function deepSerializeAxiosErrors(value, seen) {
22
47
  if (typeof value === "string") {
23
- if (isProbablyBase64(value) || value.length > MAX_STRING_LENGTH) {
48
+ // Avoid expensive checks for very long payload-like strings.
49
+ if (value.length > MAX_STRING_LENGTH) {
50
+ return truncateString(value, MAX_STRING_LENGTH);
51
+ }
52
+ if (isProbablyBase64(value)) {
24
53
  return truncateString(value, MAX_STRING_LENGTH);
25
54
  }
26
55
  return value;
@@ -18,7 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  const fs_1 = __importDefault(require("fs"));
21
- const os_1 = __importDefault(require("os"));
22
21
  const pino_1 = __importDefault(require("pino"));
23
22
  const axiosErrorSerializer_1 = require("./axiosErrorSerializer");
24
23
  const deepSerializeAxiosErrors_1 = require("./deepSerializeAxiosErrors");
@@ -63,7 +62,7 @@ if (lokiEnabled) {
63
62
  labels: {
64
63
  app: appName,
65
64
  env: process.env.NODE_ENV || "development",
66
- servidor: process.env.SERVERTAG || getEtcHostname() || os_1.default.hostname(),
65
+ servidor: process.env.SERVERTAG || getEtcHostname() || "no-host-name",
67
66
  },
68
67
  propsToLabels: ["dbname", "traceId"],
69
68
  batching: true, // 🔑