@dexto/core 1.14.0 → 1.14.1

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.
@@ -70,8 +70,8 @@ const AWS_ACCESS_KEY_ID_PATTERN = /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g;
70
70
  const AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN = /(?<![?&]X-Amz-Credential=)(?<![?&]AWSAccessKeyId=)\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g;
71
71
  const URL_PATTERN = /(https?:\/\/(?:(?!https?:\/\/)[A-Za-z0-9._~/?&=%+-])+)/i;
72
72
  const SIGNED_URL_PLACEHOLDER = /\uE000(\d+)\uE000/g;
73
- const JWT_PATTERN = /\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*/g;
74
- const JWT_OUTSIDE_TOKEN_VALUE_PATTERN = /(?<![?&]token=)\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*/g;
73
+ const JWT_RUN_PATTERN = /(?<![A-Za-z0-9_-])[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]*){2,}/g;
74
+ const TOKEN_VALUE_PREFIX = /[?&]token=$/;
75
75
  const SIGNED_URL_PATTERNS = [
76
76
  // Each provider's link counts as signed only on its own host and with a non-empty signature
77
77
  // in its query (after the "?") that has the provider's own shape: a 64-hex SigV4 signature, a
@@ -110,7 +110,32 @@ function truncateFileData(value, key, parent) {
110
110
  function isSignedUrl(value) {
111
111
  return SIGNED_URL_PATTERNS.some((pattern) => pattern.test(value));
112
112
  }
113
- function redactText(text, awsAccessKeyIdPattern, jwtPattern) {
113
+ function redactJwtsInRun(run, keepRunStart) {
114
+ const segments = run.split(".");
115
+ const kept = [];
116
+ let index = 0;
117
+ while (index < segments.length) {
118
+ const segment = segments[index] ?? "";
119
+ const start = index + 2 < segments.length ? jwtStart(segment, keepRunStart && index === 0) : -1;
120
+ if (start < 0) {
121
+ kept.push(segment);
122
+ index += 1;
123
+ continue;
124
+ }
125
+ kept.push(`${segment.slice(0, start)}${REDACTED}`);
126
+ index += 3;
127
+ }
128
+ return kept.join(".");
129
+ }
130
+ function jwtStart(segment, skipSegmentStart) {
131
+ let start = segment.indexOf("eyJ");
132
+ while (start >= 0) {
133
+ if (start === 0 ? !skipSegmentStart : segment[start - 1] === "-") return start;
134
+ start = segment.indexOf("eyJ", start + 1);
135
+ }
136
+ return -1;
137
+ }
138
+ function redactText(text, awsAccessKeyIdPattern, keepTokenValue) {
114
139
  let result = text;
115
140
  for (const pattern of SENSITIVE_PATTERNS) {
116
141
  result = result.replace(pattern, REDACTED);
@@ -119,7 +144,15 @@ function redactText(text, awsAccessKeyIdPattern, jwtPattern) {
119
144
  SK_KEY_CANDIDATE_PATTERN,
120
145
  (candidate) => isSkKey(candidate) ? REDACTED : candidate
121
146
  );
122
- return result.replace(awsAccessKeyIdPattern, REDACTED).replace(jwtPattern, REDACTED);
147
+ result = result.replace(awsAccessKeyIdPattern, REDACTED);
148
+ if (!result.includes("eyJ")) return result;
149
+ return result.replace(
150
+ JWT_RUN_PATTERN,
151
+ (run, offset, whole) => redactJwtsInRun(
152
+ run,
153
+ keepTokenValue && TOKEN_VALUE_PREFIX.test(whole.slice(Math.max(0, offset - 7), offset))
154
+ )
155
+ );
123
156
  }
124
157
  function redactSensitiveData(input, seen = /* @__PURE__ */ new WeakSet()) {
125
158
  if (typeof input === "string") {
@@ -129,14 +162,10 @@ function redactSensitiveData(input, seen = /* @__PURE__ */ new WeakSet()) {
129
162
  signedUrls.push(part);
130
163
  return `\uE000${signedUrls.length - 1}\uE000`;
131
164
  }).join("");
132
- const result = redactText(withPlaceholders, AWS_ACCESS_KEY_ID_PATTERN, JWT_PATTERN);
165
+ const result = redactText(withPlaceholders, AWS_ACCESS_KEY_ID_PATTERN, false);
133
166
  return signedUrls.length === 0 ? result : result.replace(SIGNED_URL_PLACEHOLDER, (_placeholder, index) => {
134
167
  const url = signedUrls[Number(index)];
135
- return url === void 0 ? REDACTED : redactText(
136
- url,
137
- AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN,
138
- JWT_OUTSIDE_TOKEN_VALUE_PATTERN
139
- );
168
+ return url === void 0 ? REDACTED : redactText(url, AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN, true);
140
169
  });
141
170
  }
142
171
  if (Array.isArray(input)) {
@@ -1 +1 @@
1
- {"version":3,"file":"redactor.d.ts","sourceRoot":"","sources":["../../src/utils/redactor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAqKH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,kBAAgB,GAAG,OAAO,CAyDjF"}
1
+ {"version":3,"file":"redactor.d.ts","sourceRoot":"","sources":["../../src/utils/redactor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAgNH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,kBAAgB,GAAG,OAAO,CAqDjF"}
@@ -48,8 +48,8 @@ const AWS_ACCESS_KEY_ID_PATTERN = /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g;
48
48
  const AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN = /(?<![?&]X-Amz-Credential=)(?<![?&]AWSAccessKeyId=)\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g;
49
49
  const URL_PATTERN = /(https?:\/\/(?:(?!https?:\/\/)[A-Za-z0-9._~/?&=%+-])+)/i;
50
50
  const SIGNED_URL_PLACEHOLDER = /\uE000(\d+)\uE000/g;
51
- const JWT_PATTERN = /\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*/g;
52
- const JWT_OUTSIDE_TOKEN_VALUE_PATTERN = /(?<![?&]token=)\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*/g;
51
+ const JWT_RUN_PATTERN = /(?<![A-Za-z0-9_-])[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]*){2,}/g;
52
+ const TOKEN_VALUE_PREFIX = /[?&]token=$/;
53
53
  const SIGNED_URL_PATTERNS = [
54
54
  // Each provider's link counts as signed only on its own host and with a non-empty signature
55
55
  // in its query (after the "?") that has the provider's own shape: a 64-hex SigV4 signature, a
@@ -88,7 +88,32 @@ function truncateFileData(value, key, parent) {
88
88
  function isSignedUrl(value) {
89
89
  return SIGNED_URL_PATTERNS.some((pattern) => pattern.test(value));
90
90
  }
91
- function redactText(text, awsAccessKeyIdPattern, jwtPattern) {
91
+ function redactJwtsInRun(run, keepRunStart) {
92
+ const segments = run.split(".");
93
+ const kept = [];
94
+ let index = 0;
95
+ while (index < segments.length) {
96
+ const segment = segments[index] ?? "";
97
+ const start = index + 2 < segments.length ? jwtStart(segment, keepRunStart && index === 0) : -1;
98
+ if (start < 0) {
99
+ kept.push(segment);
100
+ index += 1;
101
+ continue;
102
+ }
103
+ kept.push(`${segment.slice(0, start)}${REDACTED}`);
104
+ index += 3;
105
+ }
106
+ return kept.join(".");
107
+ }
108
+ function jwtStart(segment, skipSegmentStart) {
109
+ let start = segment.indexOf("eyJ");
110
+ while (start >= 0) {
111
+ if (start === 0 ? !skipSegmentStart : segment[start - 1] === "-") return start;
112
+ start = segment.indexOf("eyJ", start + 1);
113
+ }
114
+ return -1;
115
+ }
116
+ function redactText(text, awsAccessKeyIdPattern, keepTokenValue) {
92
117
  let result = text;
93
118
  for (const pattern of SENSITIVE_PATTERNS) {
94
119
  result = result.replace(pattern, REDACTED);
@@ -97,7 +122,15 @@ function redactText(text, awsAccessKeyIdPattern, jwtPattern) {
97
122
  SK_KEY_CANDIDATE_PATTERN,
98
123
  (candidate) => isSkKey(candidate) ? REDACTED : candidate
99
124
  );
100
- return result.replace(awsAccessKeyIdPattern, REDACTED).replace(jwtPattern, REDACTED);
125
+ result = result.replace(awsAccessKeyIdPattern, REDACTED);
126
+ if (!result.includes("eyJ")) return result;
127
+ return result.replace(
128
+ JWT_RUN_PATTERN,
129
+ (run, offset, whole) => redactJwtsInRun(
130
+ run,
131
+ keepTokenValue && TOKEN_VALUE_PREFIX.test(whole.slice(Math.max(0, offset - 7), offset))
132
+ )
133
+ );
101
134
  }
102
135
  function redactSensitiveData(input, seen = /* @__PURE__ */ new WeakSet()) {
103
136
  if (typeof input === "string") {
@@ -107,14 +140,10 @@ function redactSensitiveData(input, seen = /* @__PURE__ */ new WeakSet()) {
107
140
  signedUrls.push(part);
108
141
  return `\uE000${signedUrls.length - 1}\uE000`;
109
142
  }).join("");
110
- const result = redactText(withPlaceholders, AWS_ACCESS_KEY_ID_PATTERN, JWT_PATTERN);
143
+ const result = redactText(withPlaceholders, AWS_ACCESS_KEY_ID_PATTERN, false);
111
144
  return signedUrls.length === 0 ? result : result.replace(SIGNED_URL_PLACEHOLDER, (_placeholder, index) => {
112
145
  const url = signedUrls[Number(index)];
113
- return url === void 0 ? REDACTED : redactText(
114
- url,
115
- AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN,
116
- JWT_OUTSIDE_TOKEN_VALUE_PATTERN
117
- );
146
+ return url === void 0 ? REDACTED : redactText(url, AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN, true);
118
147
  });
119
148
  }
120
149
  if (Array.isArray(input)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dexto/core",
3
- "version": "1.14.0",
3
+ "version": "1.14.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -174,7 +174,7 @@
174
174
  "nanoid": "^5.1.6",
175
175
  "winston": "^3.17.0",
176
176
  "yaml": "^2.8.3",
177
- "@dexto/llm": "1.14.0"
177
+ "@dexto/llm": "1.14.1"
178
178
  },
179
179
  "devDependencies": {
180
180
  "@opentelemetry/context-async-hooks": "^1.28.0",