leakshield 0.5.3 → 0.5.4

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.
@@ -146,14 +146,20 @@ function assignedValue(match) {
146
146
  * a finding and refuses as token_overlap rather than risking a hidden suffix. */
147
147
  const ISSUED_PLACEHOLDER_VALUE = /^\[SGP(?:1:[0-9a-f]{32}-\d{8,12}|2:[A-Z][A-Z_]{0,31}-[a-z]{4}-[a-z]{4}-[a-z]{4})\]$/;
148
148
  function isIssuedPlaceholderValue(match, text, index) {
149
- if (!ISSUED_PLACEHOLDER_VALUE.test(assignedValue(match).trim()))
149
+ // The unquoted value branch swallows a trailing `;` (`\S` includes it); in a
150
+ // connection string that semicolon is the field delimiter, not the value.
151
+ const value = assignedValue(match).replace(/;+$/, "").trim();
152
+ if (!ISSUED_PLACEHOLDER_VALUE.test(value))
150
153
  return false;
151
154
  // JS `\S` stops at some characters a shell keeps in the word (NBSP, VT, FF,
152
- // lone CR). Only end-of-text, space, tab, LF and CRLF end the value.
155
+ // lone CR). Only end-of-text, space, tab, LF, `;` and CRLF end the value.
153
156
  const end = index + match.length;
154
157
  const after = text[end];
155
158
  if (after === undefined || after === " " || after === "\t" || after === "\n")
156
159
  return true;
160
+ // `;` ends a shell word (command separator) and a connection-string field.
161
+ if (after === ";")
162
+ return true;
157
163
  return after === "\r" && text[end + 1] === "\n";
158
164
  }
159
165
  function isCodeExpressionValue(match) {
@@ -175,13 +181,38 @@ const PLACEHOLDER = /^(?:\$\{\s*[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*\s*\}|\{\
175
181
  * as in `mongodb://${user}:${pass}@host` or `postgres://<user>:<password>@…`.
176
182
  * `userinfo` runs from just after `://` to (and possibly including) the `@`.
177
183
  */
178
- function placeholderPassword(userinfo) {
184
+ function passwordPart(userinfo) {
179
185
  const at = userinfo.lastIndexOf("@");
180
186
  const body = at === -1 ? userinfo : userinfo.slice(0, at);
181
187
  const colon = body.indexOf(":");
182
- if (colon === -1)
188
+ return colon === -1 ? undefined : body.slice(colon + 1);
189
+ }
190
+ function placeholderPassword(userinfo) {
191
+ const password = passwordPart(userinfo);
192
+ return password !== undefined && PLACEHOLDER.test(password);
193
+ }
194
+ /**
195
+ * The password part is exactly one issued placeholder: the secret it replaced
196
+ * is already masked, and the rule's own delimiter (`@` or `;`/end) ends the
197
+ * value. Any surrounding text, quoting, or continuation makes the segment
198
+ * differ from the token and stays a finding.
199
+ */
200
+ function issuedPlaceholderPassword(userinfo) {
201
+ const password = passwordPart(userinfo);
202
+ return password !== undefined && ISSUED_PLACEHOLDER_VALUE.test(password);
203
+ }
204
+ /** The `Password=`/`Pwd=` field at the end of an ADO string, checked whole. */
205
+ function issuedPlaceholderAdoPassword(match) {
206
+ // The pattern's greedy middle can cover more than one password field. Only a
207
+ // match with a single field can be exempted: an earlier plaintext field would
208
+ // otherwise pass next to the masked one. Embedded or quoted `Password=` text
209
+ // also counts, so the overcount refuses conservatively instead of exempting a
210
+ // match that might hide another field.
211
+ const fields = match.match(/(?:Password|Pwd)\s*=/gi);
212
+ if (fields === null || fields.length !== 1)
183
213
  return false;
184
- return PLACEHOLDER.test(body.slice(colon + 1));
214
+ const field = /(?:Password|Pwd)\s*=\s*([^;]*)$/i.exec(match);
215
+ return field !== null && ISSUED_PLACEHOLDER_VALUE.test(field[1].trim());
185
216
  }
186
217
  const UUID_SHAPE = /[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}/g;
187
218
  /** True when [index, index+length) lies inside a UUID-shaped run in `text`. */
@@ -299,8 +330,9 @@ export const BUILTIN_RULES = [
299
330
  // 重掃造成二次方成長。
300
331
  pattern: /:\/\/[^\s/?#:]*:[^\s/?#]*@/gi,
301
332
  skipPrefix: 3,
302
- // 密碼段是 ${…}/{{…}}/<…> 模板佔位時不是憑證(#49)
303
- validate: (match) => !placeholderPassword(match),
333
+ // 密碼段是 ${…}/{{…}}/<…> 模板佔位時不是憑證(#49);整個密碼段剛好是
334
+ // 已發出的 placeholder 時,憑證內容已遮罩(#154)。
335
+ validate: (match) => !placeholderPassword(match) && !issuedPlaceholderPassword(match),
304
336
  },
305
337
  {
306
338
  id: "jwt",
@@ -440,8 +472,12 @@ export const BUILTIN_RULES = [
440
472
  severity: "HIGH",
441
473
  description: "資料庫連線字串(含密碼)",
442
474
  pattern: /(?:mongodb(?:\+srv)?|postgresql|postgres|mysql|redis|mssql):\/\/[^:\s]+:[^@\s]+@[^\s"']+/gi,
443
- // 密碼段是模板佔位時不是憑證(#49)
444
- validate: (match) => !placeholderPassword(match.slice(match.indexOf("://") + 3)),
475
+ // 密碼段是模板佔位時不是憑證(#49);整個密碼段剛好是已發出的 placeholder
476
+ // 時,憑證內容已遮罩(#154)。
477
+ validate: (match) => {
478
+ const userinfo = match.slice(match.indexOf("://") + 3);
479
+ return !placeholderPassword(userinfo) && !issuedPlaceholderPassword(userinfo);
480
+ },
445
481
  },
446
482
  {
447
483
  id: "db-connection-ado",
@@ -450,6 +486,9 @@ export const BUILTIN_RULES = [
450
486
  description: "DB Connection String(ADO 格式)",
451
487
  // (?:[^;]+;)* 允許 Server 與 Password 之間存在任意數量的中間欄位
452
488
  pattern: /(?:Data Source|Server|Host)\s*=\s*[^;]+;(?:[^;]+;)*\s*(?:Password|Pwd)\s*=\s*[^;]+/gi,
489
+ // 密碼欄位整個值剛好是已發出的 placeholder 時,憑證內容已遮罩(#154);
490
+ // 值前後有任何其他字元就不豁免。
491
+ validate: (match) => !issuedPlaceholderAdoPassword(match),
453
492
  },
454
493
  // ── 金融/網路 PII(regex 框形狀,validate 再驗校驗碼/可路由性)────────
455
494
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leakshield",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Masks sensitive content before it reaches an AI model: OpenCode plugin, pi extension, Claude Code proxy, CLI, and web scanner",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Jared Wang",