leakshield 0.1.2 → 0.2.0

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.
@@ -1,10 +1,11 @@
1
1
  import { BUILTIN_RULES } from "../rules/builtin.js";
2
2
  import { buildDynamicRules } from "../rules/dynamic.js";
3
+ import { allowSet, isAllowlisted, noteAllowlistSuppression } from "./allowlist.js";
3
4
  import { containsAddressInRun, parseCidrList } from "./cidr.js";
4
- import { redact, getLineCol, getIgnoredLines } from "./utils.js";
5
+ import { redact, createLineIndex, lineColAt, getIgnoredLines } from "./utils.js";
5
6
  import { t } from "../i18n/index.js";
6
7
  import * as encoding from "./encoding.js";
7
- import { detectSuspiciousUnicode } from "./unicode.js";
8
+ import { foldConfusables } from "./unicode.js";
8
9
  // Dynamic rules are derived from config; cache per config object so they are
9
10
  // rebuilt only when the config reference changes (e.g. after reload_config).
10
11
  const dynamicCache = new WeakMap();
@@ -28,8 +29,8 @@ function getRules(config) {
28
29
  : rule);
29
30
  return [...configuredBuiltins, ...dynamic];
30
31
  }
31
- function hasMatchingRange(findings, index, length) {
32
- return findings.some((finding) => finding.match_start === index && finding.match_end === index + length);
32
+ function hasHighFindingAtRange(findings, index, length) {
33
+ return findings.some((finding) => finding.severity === "HIGH" && finding.match_start === index && finding.match_end === index + length);
33
34
  }
34
35
  function collapseOverlappingMatches(matches) {
35
36
  const sorted = [...matches].sort((left, right) => left.index - right.index || right.length - left.length);
@@ -55,16 +56,24 @@ function collapseOverlappingMatches(matches) {
55
56
  }))
56
57
  .sort((left, right) => right.index - left.index);
57
58
  }
58
- function addExactValueFindings(text, config, ignoredLines, findings) {
59
+ function addExactValueFindings(text, lineStarts, config, ignoredLines, findings) {
59
60
  const detector = config.exact_value_detector;
60
61
  if (!detector)
61
62
  return;
63
+ const globalAllow = allowSet(config.settings.allowlist);
62
64
  for (const match of detector.findAll(text)) {
63
- if (hasMatchingRange(findings, match.index, match.length))
65
+ // A HIGH rule finding already says all ENV_SECRET would. A weaker one must
66
+ // not hide it, or the decision drops and --min-severity high loses the match.
67
+ if (hasHighFindingAtRange(findings, match.index, match.length))
64
68
  continue;
65
- const { line, col } = getLineCol(text, match.index);
69
+ const { line, col } = lineColAt(lineStarts, match.index);
66
70
  if (ignoredLines.has(line))
67
71
  continue;
72
+ const matchedText = text.slice(match.index, match.index + match.length);
73
+ if (isAllowlisted(matchedText, globalAllow, undefined)) {
74
+ noteAllowlistSuppression();
75
+ continue;
76
+ }
68
77
  findings.push({
69
78
  type: "ENV_SECRET",
70
79
  severity: "HIGH",
@@ -74,7 +83,7 @@ function addExactValueFindings(text, config, ignoredLines, findings) {
74
83
  description: "Value from configured env file",
75
84
  match_start: match.index,
76
85
  match_end: match.index + match.length,
77
- match_text: text.slice(match.index, match.index + match.length),
86
+ match_text: matchedText,
78
87
  });
79
88
  }
80
89
  }
@@ -83,30 +92,58 @@ function honorDirectives(opts) {
83
92
  }
84
93
  /** Invisible format characters that can splice a value so the rules miss it. */
85
94
  export const ZERO_WIDTH_CHARS = /[\u200B-\u200D\uFEFF\u2060\u180E]/g;
86
- /** Rule and exact-value findings for one text, in rule order. */
95
+ const SEVERITY_RANK = { HIGH: 3, MEDIUM: 2, LOW: 1 };
96
+ /**
97
+ * Rule and exact-value findings for one text, in rule order. Rules of one type
98
+ * matching at one offset report one finding: the highest severity, over the
99
+ * longest span. Rule order must not decide either, or a LOW rule listed first
100
+ * would downgrade the decision and leave the tail of a longer match unmasked.
101
+ */
87
102
  function collectRuleFindings(text, rules, config, ignoredLines) {
103
+ const lineStarts = createLineIndex(text);
88
104
  const findings = [];
89
- const seen = new Set();
105
+ const findingAtOffset = new Map();
106
+ const globalAllow = allowSet(config.settings.allowlist);
90
107
  for (const rule of rules) {
91
- // Reuse the compiled RegExp; reset lastIndex before each scan so the
92
- // stateful global flag starts from the beginning of the input.
108
+ // Start from the beginning. matchAll advances after empty matches (by a
109
+ // code point under /u); exec alone leaves lastIndex unchanged and can hang.
93
110
  rule.pattern.lastIndex = 0;
94
- let match;
95
- while ((match = rule.pattern.exec(text)) !== null) {
111
+ for (const match of text.matchAll(rule.pattern)) {
112
+ // A zero-width match contains no value to report or mask. Skip it before
113
+ // dedupe, validation or suppression, without losing later real matches.
114
+ if (match[0].length === 0)
115
+ continue;
96
116
  const offset = rule.skipPrefix ?? 0;
97
117
  const matchedText = match[0].slice(offset);
98
118
  const start = match.index + offset;
99
119
  if (rule.validate !== undefined && !rule.validate(matchedText, { text, index: start }))
100
120
  continue;
101
- const key = `${rule.type}:${start}`;
102
- if (seen.has(key))
103
- continue;
104
- seen.add(key);
105
- const { line, col } = getLineCol(text, start);
121
+ const end = match.index + match[0].length;
122
+ const { line, col } = lineColAt(lineStarts, start);
106
123
  if (ignoredLines.has(line))
107
124
  continue;
125
+ if (isAllowlisted(matchedText, globalAllow, rule.allow)) {
126
+ noteAllowlistSuppression();
127
+ // Do NOT reserve the dedupe key: another rule may match a longer span
128
+ // at the same offset, and suppressing the short one must not hide it.
129
+ continue;
130
+ }
108
131
  const preview = redact(matchedText, config.settings.preview_length);
109
- findings.push({
132
+ const key = `${rule.type}:${start}`;
133
+ const earlier = findingAtOffset.get(key);
134
+ if (earlier) {
135
+ if (SEVERITY_RANK[rule.severity] > SEVERITY_RANK[earlier.severity]) {
136
+ earlier.severity = rule.severity;
137
+ earlier.description = rule.description;
138
+ }
139
+ if (end > (earlier.match_end ?? 0)) {
140
+ earlier.preview = preview;
141
+ earlier.match_end = end;
142
+ earlier.match_text = matchedText;
143
+ }
144
+ continue;
145
+ }
146
+ const finding = {
110
147
  type: rule.type,
111
148
  severity: rule.severity,
112
149
  line: config.settings.show_line_numbers ? line : undefined,
@@ -114,33 +151,33 @@ function collectRuleFindings(text, rules, config, ignoredLines) {
114
151
  preview,
115
152
  description: rule.description,
116
153
  match_start: start,
117
- match_end: match.index + match[0].length,
154
+ match_end: end,
118
155
  match_text: matchedText,
119
- });
156
+ };
157
+ findingAtOffset.set(key, finding);
158
+ findings.push(finding);
120
159
  }
121
160
  }
122
- addExactValueFindings(text, config, ignoredLines, findings);
161
+ addExactValueFindings(text, lineStarts, config, ignoredLines, findings);
123
162
  return findings;
124
163
  }
125
164
  /**
126
- * Zero-width characters are common in harmless text: emoji ZWJ sequences, a
127
- * BOM at the start of a file, ZWNJ in Persian. They only matter when they
128
- * splice a sensitive value so the rules miss it (`pass\u200Dword=…`, a key
129
- * split by ZWSP). Strip them, rescan, and report only when the stripped text
130
- * yields a finding the raw text does not. Line breaks are untouched, so the
131
- * raw text's ignored lines still apply.
165
+ * True when `transform` (an evasion-undoing normalization that never moves
166
+ * line breaks) makes the rules find something the raw text does not. Raw
167
+ * findings are compared by type and transformed matched text, so a value that
168
+ * is already detected raw does not count twice.
132
169
  */
133
- function zeroWidthHidesFinding(text, rawFindings, rules, config, ignoredLines) {
134
- const stripped = text.replace(ZERO_WIDTH_CHARS, "");
135
- if (stripped === text)
170
+ function transformHidesFinding(text, transform, rawFindings, rules, config, ignoredLines) {
171
+ const transformed = transform(text);
172
+ if (transformed === text)
136
173
  return false;
137
- const identity = (finding) => `${finding.type}\0${(finding.match_text ?? "").replace(ZERO_WIDTH_CHARS, "")}`;
174
+ const identity = (finding) => `${finding.type}\0${transform(finding.match_text ?? "")}`;
138
175
  const unmatched = new Map();
139
176
  for (const finding of rawFindings) {
140
177
  const id = identity(finding);
141
178
  unmatched.set(id, (unmatched.get(id) ?? 0) + 1);
142
179
  }
143
- for (const finding of collectRuleFindings(stripped, rules, config, ignoredLines)) {
180
+ for (const finding of collectRuleFindings(transformed, rules, config, ignoredLines)) {
144
181
  const id = identity(finding);
145
182
  const remaining = unmatched.get(id) ?? 0;
146
183
  if (remaining === 0)
@@ -149,6 +186,38 @@ function zeroWidthHidesFinding(text, rawFindings, rules, config, ignoredLines) {
149
186
  }
150
187
  return false;
151
188
  }
189
+ const stripZeroWidth = (value) => value.replace(ZERO_WIDTH_CHARS, "");
190
+ /**
191
+ * Zero-width characters are common in harmless text: emoji ZWJ sequences, a
192
+ * BOM at the start of a file, ZWNJ in Persian. They only matter when they
193
+ * splice a sensitive value so the rules miss it (`pass\u200Dword=…`, a key
194
+ * split by ZWSP). Strip them, rescan, and report only when the stripped text
195
+ * yields a finding the raw text does not. Line breaks are untouched, so the
196
+ * raw text's ignored lines still apply.
197
+ */
198
+ function zeroWidthHidesFinding(text, rawFindings, rules, config, ignoredLines) {
199
+ return transformHidesFinding(text, stripZeroWidth, rawFindings, rules, config, ignoredLines);
200
+ }
201
+ /**
202
+ * Cyrillic and Greek text is common and harmless in source code: locale
203
+ * files, comments, UI strings, math. Look-alike letters only matter when they
204
+ * disguise a sensitive value (`рassword=…` with a Cyrillic `р`, an `sk-` key
205
+ * with a Greek `κ`). Fold confusables to Latin (zero-width characters removed
206
+ * too, so a combined splice is caught), rescan, and report only when the
207
+ * folded text yields a finding the raw text does not (issue #46).
208
+ */
209
+ function homoglyphHidesFinding(text, rawFindings, rules, config, ignoredLines) {
210
+ // Text with zero-width characters but no look-alikes was already judged by
211
+ // zeroWidthHidesFinding; skip the identical rescan.
212
+ if (foldConfusables(text) === text)
213
+ return false;
214
+ const fold = (value) => foldConfusables(stripZeroWidth(value));
215
+ return transformHidesFinding(text, fold, rawFindings, rules, config, ignoredLines);
216
+ }
217
+ /** Appends the ` [WARNING: a, b]` suffix to a summary; no suffix when there is none. */
218
+ export function appendWarnings(summary, warnings) {
219
+ return warnings !== undefined && warnings.length > 0 ? `${summary} [WARNING: ${warnings.join(", ")}]` : summary;
220
+ }
152
221
  /**
153
222
  * Internal scan function without encoding detection.
154
223
  * Used by scanTextWithDecoding to avoid infinite recursion.
@@ -164,13 +233,13 @@ function scanTextInternal(text, config, opts) {
164
233
  const ruleFindings = collectRuleFindings(truncated, allRules, config, ignoredLines);
165
234
  // Step 3: Flag suspicious Unicode only when it is an actual threat. This
166
235
  // doesn't modify the text, just detects issues.
167
- const suspicious = detectSuspiciousUnicode(truncated);
168
236
  const zeroWidthEvasion = zeroWidthHidesFinding(truncated, ruleFindings, allRules, config, ignoredLines);
237
+ const homoglyphEvasion = !zeroWidthEvasion && homoglyphHidesFinding(truncated, ruleFindings, allRules, config, ignoredLines);
169
238
  const findings = [];
170
- if (zeroWidthEvasion || suspicious.hasHomographs) {
239
+ if (zeroWidthEvasion || homoglyphEvasion) {
171
240
  findings.push({
172
241
  type: "CUSTOM",
173
- severity: zeroWidthEvasion ? "HIGH" : "MEDIUM",
242
+ severity: "HIGH",
174
243
  line: 1,
175
244
  column: 1,
176
245
  preview: "****",
@@ -182,8 +251,8 @@ function scanTextInternal(text, config, opts) {
182
251
  match_text: truncated.substring(0, 50), // Only store first 50 chars
183
252
  unicode_detected: {
184
253
  had_zero_width: zeroWidthEvasion,
185
- had_homographs: suspicious.hasHomographs,
186
- details: suspicious.details,
254
+ had_homographs: homoglyphEvasion,
255
+ details: [zeroWidthEvasion ? "zero-width characters hide a finding" : "look-alike letters hide a finding"],
187
256
  },
188
257
  });
189
258
  }
@@ -205,36 +274,37 @@ function scanTextInternal(text, config, opts) {
205
274
  // Add warnings for Unicode issues and truncation
206
275
  const warnings = [];
207
276
  if (zeroWidthEvasion)
208
- warnings.push("零寬字符");
209
- if (suspicious.hasHomographs)
210
- warnings.push("可疑 Unicode");
277
+ warnings.push(t("scan.warning_zero_width"));
278
+ if (homoglyphEvasion)
279
+ warnings.push(t("scan.warning_suspicious_unicode"));
211
280
  if (wasTruncated)
212
- warnings.push("內容截斷");
213
- const finalSummary = warnings.length > 0
214
- ? summary + ` [WARNING: ${warnings.join(', ')}]`
215
- : summary;
281
+ warnings.push(t("scan.warning_truncated"));
216
282
  return {
217
283
  safe,
218
284
  total_findings: findings.length,
219
285
  findings,
220
- summary: finalSummary,
286
+ summary: appendWarnings(summary, warnings),
221
287
  recommendation,
222
288
  was_truncated: wasTruncated || undefined,
289
+ ...(warnings.length > 0 ? { warnings } : {}),
223
290
  };
224
291
  }
225
292
  export function scanText(text, config, opts) {
226
293
  // If encoding detection is enabled, use the enhanced scanner
227
294
  if (config.settings.encoding_detection) {
228
295
  const result = encoding.scanTextWithDecoding(text, config, opts);
229
- // Generate proper summary based on merged results
230
- const safe = result.safe;
231
- const highCount = result.findings.filter((f) => f.severity === "HIGH").length;
232
- const medCount = result.findings.filter((f) => f.severity === "MEDIUM").length;
233
- const lowCount = result.findings.length - highCount - medCount;
296
+ // Decoded findings carry offsets of the decoded string; anchor them to
297
+ // spans of `text` so redaction and previews apply to the right bytes.
298
+ const findings = encoding.anchorDecodedFindings(text, result, config, opts);
299
+ // Generate proper summary based on the anchored results
300
+ const safe = findings.length === 0;
301
+ const highCount = findings.filter((f) => f.severity === "HIGH").length;
302
+ const medCount = findings.filter((f) => f.severity === "MEDIUM").length;
303
+ const lowCount = findings.length - highCount - medCount;
234
304
  const summary = safe
235
305
  ? t("scan.safe_summary")
236
306
  : t("scan.unsafe_summary", {
237
- count: result.findings.length,
307
+ count: findings.length,
238
308
  high: highCount,
239
309
  med: medCount,
240
310
  low: lowCount,
@@ -245,21 +315,19 @@ export function scanText(text, config, opts) {
245
315
  // Add warnings for encoding detection and truncation
246
316
  const warnings = [];
247
317
  if (result.was_decoded) {
248
- warnings.push(`編碼檢測: ${result.encoding_types_found.join(', ')}`);
318
+ warnings.push(t("scan.warning_encoded", { types: result.encoding_types_found.join(", ") }));
249
319
  }
250
320
  if (result.original.was_truncated) {
251
- warnings.push("內容截斷");
321
+ warnings.push(t("scan.warning_truncated"));
252
322
  }
253
- const finalSummary = warnings.length > 0
254
- ? summary + ` [WARNING: ${warnings.join(', ')}]`
255
- : summary;
256
323
  return {
257
324
  safe,
258
- total_findings: result.total_findings,
259
- findings: result.findings,
260
- summary: finalSummary,
325
+ total_findings: findings.length,
326
+ findings,
327
+ summary: appendWarnings(summary, warnings),
261
328
  recommendation,
262
329
  was_truncated: result.original.was_truncated,
330
+ ...(warnings.length > 0 ? { warnings } : {}),
263
331
  };
264
332
  }
265
333
  // Otherwise, use internal scan without encoding detection
@@ -283,26 +351,35 @@ protectedSpans = []) {
283
351
  const truncated = text.slice(0, config.settings.max_chars);
284
352
  const allRules = getRules(config);
285
353
  const ignoredLines = honorDirectives(opts) ? getIgnoredLines(truncated) : new Set();
354
+ const truncatedLineStarts = createLineIndex(truncated);
286
355
  const matches = [];
287
356
  const seen = new Set();
357
+ const globalAllow = allowSet(config.settings.allowlist);
288
358
  for (const rule of allRules) {
289
359
  rule.pattern.lastIndex = 0;
290
- let match;
291
- while ((match = rule.pattern.exec(truncated)) !== null) {
360
+ // Keep the same progress and empty-span contract as collectRuleFindings.
361
+ for (const match of truncated.matchAll(rule.pattern)) {
362
+ if (match[0].length === 0)
363
+ continue;
292
364
  const offset = rule.skipPrefix ?? 0;
293
365
  const start = match.index + offset;
294
366
  const end = match.index + match[0].length;
295
- if (rule.validate !== undefined && !rule.validate(match[0].slice(offset), { text: truncated, index: start }))
367
+ const matchedText = match[0].slice(offset);
368
+ if (rule.validate !== undefined && !rule.validate(matchedText, { text: truncated, index: start }))
296
369
  continue;
297
370
  if (overlapsSpan(start, end, protectedSpans))
298
371
  continue;
299
372
  const key = `${start}:${end - start}`;
300
373
  if (seen.has(key))
301
374
  continue;
302
- seen.add(key);
303
- const { line } = getLineCol(truncated, start);
375
+ const { line } = lineColAt(truncatedLineStarts, start);
304
376
  if (ignoredLines.has(line))
305
377
  continue;
378
+ // An allowlisted literal is left as written, exactly as the scanner leaves
379
+ // it unreported; redacting it would contradict the bypass the user chose.
380
+ if (isAllowlisted(matchedText, globalAllow, rule.allow))
381
+ continue;
382
+ seen.add(key);
306
383
  matches.push({ index: start, length: end - start, type: rule.type });
307
384
  }
308
385
  }
@@ -311,11 +388,16 @@ protectedSpans = []) {
311
388
  for (const match of detector.findAll(truncated)) {
312
389
  if (overlapsSpan(match.index, match.index + match.length, protectedSpans))
313
390
  continue;
391
+ // Only the mask is decided here, so any match on this range already covers
392
+ // it. Severity is reported by the scanText call below.
314
393
  if (matches.some((entry) => entry.index === match.index && entry.length === match.length))
315
394
  continue;
316
- const { line } = getLineCol(truncated, match.index);
395
+ const { line } = lineColAt(truncatedLineStarts, match.index);
317
396
  if (ignoredLines.has(line))
318
397
  continue;
398
+ const matchedText = truncated.slice(match.index, match.index + match.length);
399
+ if (isAllowlisted(matchedText, globalAllow, undefined))
400
+ continue;
319
401
  matches.push({ index: match.index, length: match.length, type: "ENV_SECRET" });
320
402
  }
321
403
  }
@@ -155,3 +155,33 @@ export function sanitizeForScanning(text) {
155
155
  },
156
156
  };
157
157
  }
158
+ /**
159
+ * Cyrillic and Greek letters that render like a Latin letter in common fonts,
160
+ * mapped to that Latin letter. One UTF-16 unit in, one out, so offsets and
161
+ * line numbers of the folded text match the original.
162
+ */
163
+ const CONFUSABLE_TO_LATIN = {
164
+ // Cyrillic lowercase
165
+ "а": "a", "е": "e", "о": "o", "р": "p", "с": "c",
166
+ "х": "x", "у": "y", "і": "i", "ј": "j", "ѕ": "s",
167
+ "ԁ": "d", "һ": "h", "ӏ": "l", "ԛ": "q", "ԝ": "w",
168
+ // Cyrillic uppercase
169
+ "А": "A", "В": "B", "Е": "E", "К": "K", "М": "M",
170
+ "Н": "H", "О": "O", "Р": "P", "С": "C", "Т": "T",
171
+ "Х": "X", "У": "Y", "І": "I", "Ј": "J", "Ѕ": "S",
172
+ // Greek lowercase
173
+ "α": "a", "ο": "o", "ρ": "p", "ν": "v", "ι": "i",
174
+ "κ": "k", "υ": "u", "χ": "x",
175
+ // Greek uppercase
176
+ "Α": "A", "Β": "B", "Ε": "E", "Ζ": "Z", "Η": "H",
177
+ "Ι": "I", "Κ": "K", "Μ": "M", "Ν": "N", "Ο": "O",
178
+ "Ρ": "P", "Τ": "T", "Υ": "Y", "Χ": "X",
179
+ };
180
+ const CONFUSABLE_PATTERN = new RegExp(`[${Object.keys(CONFUSABLE_TO_LATIN).join("")}]`, "g");
181
+ /**
182
+ * Replaces Cyrillic/Greek look-alike letters with their Latin counterparts.
183
+ * Length-preserving; returns the input unchanged when it has none.
184
+ */
185
+ export function foldConfusables(text) {
186
+ return text.replace(CONFUSABLE_PATTERN, (char) => CONFUSABLE_TO_LATIN[char] ?? char);
187
+ }
@@ -7,8 +7,32 @@ export function redact(_value, _previewLen) {
7
7
  }
8
8
  export function getLineCol(text, index) {
9
9
  const before = text.slice(0, index);
10
- const lines = before.split(/\r?\n/);
11
- return { line: lines.length, col: lines[lines.length - 1].length + 1 };
10
+ return lineColAt(createLineIndex(before), before.length);
11
+ }
12
+ /** Start offset of every line in a text; a line break is `\r?\n`, so only `\n` ends a line. */
13
+ export function createLineIndex(text) {
14
+ const starts = [0];
15
+ let from = 0;
16
+ for (;;) {
17
+ const nl = text.indexOf("\n", from);
18
+ if (nl === -1)
19
+ return starts;
20
+ from = nl + 1;
21
+ starts.push(from);
22
+ }
23
+ }
24
+ /** Line (1-based) and column (1-based) of `index`, given the starts from createLineIndex of the same text. */
25
+ export function lineColAt(lineStarts, index) {
26
+ let lo = 0;
27
+ let hi = lineStarts.length - 1;
28
+ while (lo < hi) {
29
+ const mid = (lo + hi + 1) >> 1;
30
+ if (lineStarts[mid] <= index)
31
+ lo = mid;
32
+ else
33
+ hi = mid - 1;
34
+ }
35
+ return { line: lo + 1, col: index - lineStarts[lo] + 1 };
12
36
  }
13
37
  /**
14
38
  * Multiple ignore patterns to prevent bypass attempts.
@@ -2,7 +2,7 @@ import * as fs from "fs";
2
2
  import * as path from "path";
3
3
  import chalk from "chalk";
4
4
  import { loadConfig } from "../config/loader.js";
5
- import { scanText, redactText } from "../scanner/engine.js";
5
+ import { scanText, redactText, appendWarnings } from "../scanner/engine.js";
6
6
  import { redactAndVerify } from "../scanner/redaction-verifier.js";
7
7
  import { sanitizeRedactResultForExport } from "../decision/redaction.js";
8
8
  import { toDecisionResult } from "../decision/model.js";
@@ -28,7 +28,7 @@ export function filterBySeverity(result, min) {
28
28
  med: medCount,
29
29
  low: findings.length - highCount - medCount,
30
30
  });
31
- return { ...result, findings, total_findings: findings.length, safe, summary };
31
+ return { ...result, findings, total_findings: findings.length, safe, summary: appendWarnings(summary, result.warnings) };
32
32
  }
33
33
  // ─── Decision-aware CLI formatting ──────────────────────────────────────────
34
34
  const SEPARATOR = "─".repeat(60);
@@ -147,7 +147,8 @@ function handleScanRequest(req, res, config) {
147
147
  : undefined;
148
148
  writeJson(res, 200, {
149
149
  ...decision,
150
- redactedContent: redaction?.redacted,
150
+ // Replaces the decision's copy too: only text the verifier passed is returned.
151
+ redactedContent: redaction?.verified ? redaction.redacted : undefined,
151
152
  redactionVerified: redaction?.verified,
152
153
  residualFindings: redaction?.residualFindings,
153
154
  wasTruncated: redaction?.wasTruncated ?? scan.was_truncated ?? false,
@@ -164,8 +165,7 @@ function handleScanRequest(req, res, config) {
164
165
  res.destroy();
165
166
  });
166
167
  }
167
- export function createWebServer() {
168
- const config = loadConfig();
168
+ export function createWebServer(config = loadConfig()) {
169
169
  return http.createServer((req, res) => {
170
170
  if (!isAllowedHost(req.headers.host)) {
171
171
  writeError(res, 403, "不允許的 Host");
package/dist/types.js CHANGED
@@ -20,4 +20,5 @@ export const FINDING_TYPES = [
20
20
  "PII_IBAN",
21
21
  "PII_IP",
22
22
  "PII_URL",
23
+ "ENCODED",
23
24
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leakshield",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "OpenCode plugin, CLI, and web scanner for sensitive content before sending it to AI",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -55,12 +55,12 @@
55
55
  "bundle:mac": "npm run binary && bash scripts/bundle-mac.sh"
56
56
  },
57
57
  "dependencies": {
58
- "@opencode-ai/plugin": "^1.17.18",
59
58
  "chalk": "^5.3.0",
60
59
  "js-yaml": "^4.3.2",
61
- "zod": "^3.22.0"
60
+ "zod": "^4.6.7"
62
61
  },
63
62
  "devDependencies": {
63
+ "@opencode-ai/plugin": "^1.17.18",
64
64
  "@opencode-ai/sdk": "^1.17.18",
65
65
  "@opencode/plugin": "^2.0.19",
66
66
  "@types/js-yaml": "^4.0.9",