leakshield 0.5.2 → 0.5.3

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.
@@ -138,8 +138,26 @@ const CODE_CHAIN = new RegExp(`^${IDENT}${STEP}*${TAIL}`);
138
138
  const CONFIG_MEMBER = new RegExp(`^(?:process\\.env|import\\.meta\\.env|os\\.environ|ENV|this|self|config|cfg|conf|settings|options|opts|props|params|args|req|request|ctx|context|env|secrets)${STEP}+${TAIL}`);
139
139
  /** Longer values are not exempted; a real expression on one line is short. */
140
140
  const MAX_EXPRESSION_LENGTH = 256;
141
+ function assignedValue(match) {
142
+ return match.replace(/^[^:=]*[:=]\s*/, "");
143
+ }
144
+ /** A whole issued placeholder as an unquoted value. A quoted value is
145
+ * ambiguous (a shell word can continue after the closing quote), so it stays
146
+ * a finding and refuses as token_overlap rather than risking a hidden suffix. */
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
+ function isIssuedPlaceholderValue(match, text, index) {
149
+ if (!ISSUED_PLACEHOLDER_VALUE.test(assignedValue(match).trim()))
150
+ return false;
151
+ // 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.
153
+ const end = index + match.length;
154
+ const after = text[end];
155
+ if (after === undefined || after === " " || after === "\t" || after === "\n")
156
+ return true;
157
+ return after === "\r" && text[end + 1] === "\n";
158
+ }
141
159
  function isCodeExpressionValue(match) {
142
- const value = match.replace(/^[^:=]*[:=]\s*/, "");
160
+ const value = assignedValue(match);
143
161
  if (value.length > MAX_EXPRESSION_LENGTH)
144
162
  return false;
145
163
  if (value.startsWith("'") || value.startsWith('"'))
@@ -266,8 +284,9 @@ export const BUILTIN_RULES = [
266
284
  // 同時涵蓋有引號(YAML/JSON)與無引號(.env)寫法
267
285
  // (?!\$\{) 排除環境變數參照 ${VAR};(?!\*) 排除遮罩值 ********
268
286
  pattern: /(?:password|passwd|secret|private_key|client_secret)\s*[:=]\s*(?:['"](?!\$\{)[^'"]{8,}['"]|(?!['"\$\*])\S{8,})/gi,
269
- // 無引號值若是程式碼表達式(process.env.X、z.string()、config.secret)不算機密(#49)
270
- validate: (match) => !isCodeExpressionValue(match),
287
+ // 無引號值若是程式碼表達式(process.env.X、z.string()、config.secret)不算機密(#49);
288
+ // 值「整個」是已發出的 placeholder 時才是已遮罩內容;混入其他文字仍要偵測(可能跨 token 而拒絕)。
289
+ validate: (match, context) => !isCodeExpressionValue(match) && !isIssuedPlaceholderValue(match, context.text, context.index),
271
290
  },
272
291
  {
273
292
  id: "url-userinfo",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leakshield",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
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",