react-smart-copy 1.19.1 → 1.21.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.
@@ -0,0 +1,544 @@
1
+
2
+ import { n as copyFailure } from "./chunks/errors-9h8sdFFX.js";
3
+ import { n as insertText, t as asTextField } from "./chunks/text-field-DUvrMMaK.js";
4
+ //#region src/secrets/checks.ts
5
+ /** Checks that tell real secrets from look-alikes: checksums, structure and randomness. */
6
+ /** The Luhn checksum of card numbers. `digits` holds only digits. */
7
+ function luhn(digits) {
8
+ let sum = 0;
9
+ for (let index = 0; index < digits.length; index += 1) {
10
+ let digit = digits.charCodeAt(digits.length - 1 - index) - 48;
11
+ if (index % 2 === 1) {
12
+ digit *= 2;
13
+ if (digit > 9) digit -= 9;
14
+ }
15
+ sum += digit;
16
+ }
17
+ return sum % 10 === 0;
18
+ }
19
+ /** Card brands by their number ranges (IIN) and lengths. */
20
+ const BRANDS = [
21
+ {
22
+ prefix: /^4/,
23
+ lengths: [
24
+ 13,
25
+ 16,
26
+ 19
27
+ ]
28
+ },
29
+ {
30
+ prefix: /^(?:5[1-5]|222[1-9]|22[3-9]\d|2[3-6]\d\d|27[01]\d|2720)/,
31
+ lengths: [16]
32
+ },
33
+ {
34
+ prefix: /^3[47]/,
35
+ lengths: [15]
36
+ },
37
+ {
38
+ prefix: /^(?:6011|65|64[4-9])/,
39
+ lengths: [
40
+ 16,
41
+ 17,
42
+ 18,
43
+ 19
44
+ ]
45
+ },
46
+ {
47
+ prefix: /^35(?:2[89]|[3-8]\d)/,
48
+ lengths: [
49
+ 16,
50
+ 17,
51
+ 18,
52
+ 19
53
+ ]
54
+ },
55
+ {
56
+ prefix: /^3(?:0[0-5]|[689])/,
57
+ lengths: [
58
+ 14,
59
+ 15,
60
+ 16,
61
+ 17,
62
+ 18,
63
+ 19
64
+ ]
65
+ },
66
+ {
67
+ prefix: /^62/,
68
+ lengths: [
69
+ 16,
70
+ 17,
71
+ 18,
72
+ 19
73
+ ]
74
+ }
75
+ ];
76
+ /**
77
+ * Whether `candidate` is a card number: a known brand's range and length, a valid Luhn
78
+ * checksum, and separators (spaces or dashes) used the way cards print them: none, or one
79
+ * kind in groups of 4 (Amex: 4-6-5).
80
+ */
81
+ function isCardNumber(candidate) {
82
+ const digits = candidate.replace(/[ -]/g, "");
83
+ const separators = new Set(candidate.replace(/\d/g, ""));
84
+ if (separators.size > 1) return false;
85
+ if (separators.size === 1) {
86
+ const groups = candidate.split(/[ -]/).map((group) => group.length);
87
+ const fours = groups.slice(0, -1).every((length) => length === 4) && groups[groups.length - 1] <= 4;
88
+ const amex = groups.join("-") === "4-6-5";
89
+ if (!fours && !amex) return false;
90
+ }
91
+ if (/^(\d)\1+$/.test(digits)) return false;
92
+ return BRANDS.some((brand) => brand.prefix.test(digits) && brand.lengths.includes(digits.length)) && luhn(digits);
93
+ }
94
+ /** IBAN lengths by country (ISO 13616 registry), for the countries that use one. */
95
+ const IBAN_LENGTHS = {
96
+ AD: 24,
97
+ AE: 23,
98
+ AL: 28,
99
+ AT: 20,
100
+ AZ: 28,
101
+ BA: 20,
102
+ BE: 16,
103
+ BG: 22,
104
+ BH: 22,
105
+ BR: 29,
106
+ BY: 28,
107
+ CH: 21,
108
+ CR: 22,
109
+ CY: 28,
110
+ CZ: 24,
111
+ DE: 22,
112
+ DK: 18,
113
+ DO: 28,
114
+ EE: 20,
115
+ EG: 29,
116
+ ES: 24,
117
+ FI: 18,
118
+ FO: 18,
119
+ FR: 27,
120
+ GB: 22,
121
+ GE: 22,
122
+ GI: 23,
123
+ GL: 18,
124
+ GR: 27,
125
+ GT: 28,
126
+ HR: 21,
127
+ HU: 28,
128
+ IE: 22,
129
+ IL: 23,
130
+ IQ: 23,
131
+ IS: 26,
132
+ IT: 27,
133
+ JO: 30,
134
+ KW: 30,
135
+ KZ: 20,
136
+ LB: 28,
137
+ LC: 32,
138
+ LI: 21,
139
+ LT: 20,
140
+ LU: 20,
141
+ LV: 21,
142
+ MC: 27,
143
+ MD: 24,
144
+ ME: 22,
145
+ MK: 19,
146
+ MR: 27,
147
+ MT: 31,
148
+ MU: 30,
149
+ NL: 18,
150
+ NO: 15,
151
+ PK: 24,
152
+ PL: 28,
153
+ PS: 29,
154
+ PT: 25,
155
+ QA: 29,
156
+ RO: 24,
157
+ RS: 22,
158
+ SA: 24,
159
+ SC: 31,
160
+ SE: 24,
161
+ SI: 19,
162
+ SK: 24,
163
+ SM: 27,
164
+ ST: 25,
165
+ SV: 28,
166
+ TL: 23,
167
+ TN: 24,
168
+ TR: 26,
169
+ UA: 29,
170
+ VA: 22,
171
+ VG: 24,
172
+ XK: 20
173
+ };
174
+ /** Whether `candidate` (spaces allowed) is an IBAN: its country's length and a valid mod-97 checksum. */
175
+ function isIban(candidate) {
176
+ const iban = candidate.replace(/ /g, "");
177
+ if (IBAN_LENGTHS[iban.slice(0, 2)] !== iban.length) return false;
178
+ const rearranged = iban.slice(4) + iban.slice(0, 4);
179
+ let remainder = 0;
180
+ for (const char of rearranged) {
181
+ const code = char.charCodeAt(0);
182
+ const value = code >= 65 ? code - 55 : code - 48;
183
+ remainder = (value > 9 ? remainder * 100 + value : remainder * 10 + value) % 97;
184
+ }
185
+ return remainder === 1;
186
+ }
187
+ /** Shannon entropy of `text`, in bits per character. */
188
+ function entropy(text) {
189
+ const counts = /* @__PURE__ */ new Map();
190
+ for (const char of text) counts.set(char, (counts.get(char) ?? 0) + 1);
191
+ let bits = 0;
192
+ for (const count of counts.values()) {
193
+ const p = count / text.length;
194
+ bits -= p * Math.log2(p);
195
+ }
196
+ return bits;
197
+ }
198
+ /** Values that stand in for a secret in examples and templates, never a secret themselves. */
199
+ const PLACEHOLDER = /^(?:x+|\*+|\.+|-+|_+|#+|0+|<[^>]*>|\[[^\]]*\]|\$\{[^}]*\}|\{\{[^}]*\}\}|%[^%]*%|\$[A-Z_][A-Z0-9_]*|your[_-]?[\w-]*|my[_-][\w-]*|change[_-]?me|example[\w-]*|sample[\w-]*|dummy[\w-]*|fake[\w-]*|placeholder[\w-]*|redacted|null|none|undefined)$/i;
200
+ /** A reference to another value, not a value: `process.env.TOKEN`, `config.api.key`. */
201
+ const REFERENCE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/;
202
+ /** Whether `value` looks like a real secret: random enough, and not a placeholder or a reference. */
203
+ function looksSecret(value, minEntropy) {
204
+ return !PLACEHOLDER.test(value) && !REFERENCE.test(value) && entropy(value) >= minEntropy;
205
+ }
206
+ /** Whether the first part of a JWT decodes to a JSON header with an algorithm. */
207
+ function isJwtHeader(part) {
208
+ if (typeof atob !== "function") return true;
209
+ try {
210
+ const base64 = part.replace(/-/g, "+").replace(/_/g, "/");
211
+ const header = JSON.parse(atob(base64 + "=".repeat((4 - base64.length % 4) % 4)));
212
+ return typeof header === "object" && header !== null && typeof header.alg === "string";
213
+ } catch {
214
+ return false;
215
+ }
216
+ }
217
+ //#endregion
218
+ //#region src/secrets/rules.ts
219
+ const high = (secret) => ({
220
+ confidence: "high",
221
+ length: secret.length
222
+ });
223
+ const medium = (secret) => ({
224
+ confidence: "medium",
225
+ length: secret.length
226
+ });
227
+ /** Start of a token: the start of the text, or a character that can't be part of one. */
228
+ const B = "(^|[^A-Za-z0-9_])";
229
+ /** After a token: nothing that could continue it. */
230
+ const E = "(?![A-Za-z0-9_])";
231
+ const token = (kind, body, keep, options = {}) => ({
232
+ kind,
233
+ pattern: new RegExp(`${B}(${body})${options.end ?? E}`, `g${options.flags ?? ""}`),
234
+ group: 2,
235
+ keep,
236
+ tail: true,
237
+ check: options.confidence === "medium" ? medium : high
238
+ });
239
+ /** A name, an assignment (`=`, `:`, `=>`, `:=`) and a value: `API_KEY="..."`, `"password": "..."`. */
240
+ const ASSIGNMENT = /(^|[^A-Za-z0-9_])(["']?([A-Za-z_][A-Za-z0-9_.-]{0,63})["']?\s{0,8}(?:=>|:=|[:=])\s{0,8}["'`]?)([^\s"'`,;()[\]{}<>]{8,200})/g;
241
+ /** Names that hold secrets, at the end of the name: `password`, `GITHUB_TOKEN`, `db.apiKey`. */
242
+ const SECRET_NAME = /(?:pass(?:word|wd|phrase)?|pwd|secret|token|api[_.-]?key|access[_.-]?key|private[_.-]?key|auth[_.-]?key|credentials?|client[_.-]?secret|signing[_.-]?key)$/i;
243
+ /**
244
+ * A card number, grouped as cards print it or not. The last group is tried without itself
245
+ * too: what follows a card is often more digits (`4242 4242 4242 4242 12/26`, a date).
246
+ */
247
+ function card(candidate) {
248
+ if (isCardNumber(candidate)) return {
249
+ confidence: /[ -]/.test(candidate) ? "high" : "medium",
250
+ length: candidate.length
251
+ };
252
+ const cut = candidate.search(/[ -]\d{1,4}$/);
253
+ return cut !== -1 && isCardNumber(candidate.slice(0, cut)) ? {
254
+ confidence: "high",
255
+ length: cut
256
+ } : null;
257
+ }
258
+ /** An IBAN, cut to its country's length: what follows (a BIC, a word) is not part of it. */
259
+ function iban(candidate) {
260
+ let letters = 0;
261
+ for (let index = 0; index < candidate.length; index += 1) {
262
+ if (candidate[index] !== " ") letters += 1;
263
+ if (letters >= 15 && (index + 1 === candidate.length || candidate[index + 1] === " ") && isIban(candidate.slice(0, index + 1))) return {
264
+ confidence: "high",
265
+ length: index + 1
266
+ };
267
+ }
268
+ return null;
269
+ }
270
+ /** Rules in priority order: when findings overlap, the earlier rule's finding is kept. */
271
+ const RULES = [
272
+ token("aws-access-key-id", "(?:AKIA|ASIA|ABIA|ACCA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|APKA)[A-Z2-7]{16}", 4),
273
+ token("github-token", "(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9]{22}_[A-Za-z0-9]{59}", (secret) => secret.indexOf("_") + (secret.startsWith("github_pat_") ? 5 : 1)),
274
+ token("gitlab-token", "glpat-[A-Za-z0-9_-]{20,64}", 6, { end: "(?![A-Za-z0-9_-])" }),
275
+ token("slack-webhook", "https://hooks\\.slack\\.com/services/[A-Z0-9]{8,12}/[A-Z0-9]{8,12}/[A-Za-z0-9]{24}", 33),
276
+ token("slack-token", "xox[abposr]-[A-Za-z0-9-]{10,250}", 5, { end: "(?![A-Za-z0-9-])" }),
277
+ token("stripe-key", "(?:sk|rk)_live_[A-Za-z0-9]{24,247}", 8),
278
+ token("google-api-key", "AIza[A-Za-z0-9_-]{35}", 4, { end: "(?![A-Za-z0-9_-])" }),
279
+ token("npm-token", "npm_[A-Za-z0-9]{36}", 4),
280
+ token("pypi-token", "pypi-AgEIcHlwaS5vcmc[A-Za-z0-9_-]{50,1000}", 5, { end: "(?![A-Za-z0-9_-])" }),
281
+ token("sendgrid-key", "SG\\.[A-Za-z0-9_-]{22}\\.[A-Za-z0-9_-]{43}", 3, { end: "(?![A-Za-z0-9_-])" }),
282
+ {
283
+ kind: "jwt",
284
+ pattern: /(^|[^A-Za-z0-9_-])(eyJ[A-Za-z0-9_-]{8,4000}\.eyJ[A-Za-z0-9_-]{8,16000}\.[A-Za-z0-9_-]{16,4000})(?![A-Za-z0-9_-])/g,
285
+ group: 2,
286
+ keep: 3,
287
+ tail: true,
288
+ check: (secret) => isJwtHeader(secret.slice(0, secret.indexOf("."))) ? high(secret) : null
289
+ },
290
+ {
291
+ kind: "azure-storage-key",
292
+ pattern: /(^|[;\s"'])(AccountKey\s{0,4}=\s{0,4})([A-Za-z0-9+/]{86}==)/gi,
293
+ group: 3,
294
+ keep: 0,
295
+ tail: false,
296
+ check: high
297
+ },
298
+ {
299
+ kind: "url-credentials",
300
+ pattern: /((?:^|[^A-Za-z0-9+.-])[A-Za-z][A-Za-z0-9+.-]{1,30}:\/\/[^\s:/?#@]{0,256}:)([^\s/?#@]{1,256})(?=@)/g,
301
+ group: 2,
302
+ keep: 0,
303
+ tail: false,
304
+ check: (secret) => looksSecret(secret, 0) ? high(secret) : null
305
+ },
306
+ {
307
+ kind: "connection-string",
308
+ pattern: /(;\s{0,4}(?:password|pwd)\s{0,4}=\s{0,4})([^;'"\s]{1,256})/gi,
309
+ group: 2,
310
+ keep: 0,
311
+ tail: false,
312
+ check: (secret) => looksSecret(secret, 0) ? high(secret) : null
313
+ },
314
+ token("twilio-key", "SK[0-9a-fA-F]{32}", 2, { confidence: "medium" }),
315
+ {
316
+ kind: "card-number",
317
+ pattern: /(^|[^0-9A-Za-z])(\d{4}[ -]\d{6}[ -]\d{5}|\d{4}(?:[ -]\d{4}){2,3}(?:[ -]\d{1,4})?|\d{13,19})(?![0-9])/g,
318
+ group: 2,
319
+ keep: 0,
320
+ tail: true,
321
+ check: card,
322
+ retry: true
323
+ },
324
+ {
325
+ kind: "iban",
326
+ pattern: /(^|[^A-Za-z0-9])([A-Z]{2}\d{2}(?: ?[A-Z0-9]){11,40})(?![A-Za-z0-9])/g,
327
+ group: 2,
328
+ keep: 2,
329
+ tail: true,
330
+ check: iban,
331
+ retry: true
332
+ },
333
+ {
334
+ kind: "generic-secret",
335
+ pattern: ASSIGNMENT,
336
+ group: 4,
337
+ keep: 0,
338
+ tail: false,
339
+ check: (secret, match) => {
340
+ const name = match[3];
341
+ if (/^[A-Za-z0-9/+]{40}$/.test(secret) && /aws/i.test(name) && /secret/i.test(name)) return {
342
+ kind: "aws-secret-access-key",
343
+ confidence: "medium",
344
+ length: secret.length
345
+ };
346
+ return SECRET_NAME.test(name) && looksSecret(secret, 3) ? medium(secret) : null;
347
+ }
348
+ }
349
+ ];
350
+ /** `-----BEGIN ... PRIVATE KEY-----`, through its `END` line (or the end of the text, when cut off). */
351
+ const PRIVATE_KEY = /-----BEGIN (?:[A-Z0-9]{1,16} ){0,3}PRIVATE KEY(?: BLOCK)?-----/g;
352
+ //#endregion
353
+ //#region src/secrets/types.ts
354
+ /** People-facing names of the kinds, for messages and redaction marks. */
355
+ const SECRET_LABELS = Object.freeze({
356
+ "private-key": "private key",
357
+ "aws-access-key-id": "AWS access key ID",
358
+ "aws-secret-access-key": "AWS secret access key",
359
+ "github-token": "GitHub token",
360
+ "gitlab-token": "GitLab token",
361
+ "slack-token": "Slack token",
362
+ "slack-webhook": "Slack webhook URL",
363
+ "stripe-key": "Stripe live key",
364
+ "google-api-key": "Google API key",
365
+ "npm-token": "npm token",
366
+ "pypi-token": "PyPI token",
367
+ "sendgrid-key": "SendGrid API key",
368
+ "twilio-key": "Twilio API key",
369
+ "azure-storage-key": "Azure storage key",
370
+ jwt: "JSON Web Token",
371
+ "url-credentials": "password in a URL",
372
+ "connection-string": "password in a connection string",
373
+ "card-number": "card number",
374
+ iban: "IBAN",
375
+ "generic-secret": "secret"
376
+ });
377
+ /** Every kind, in a stable order. */
378
+ const SECRET_KINDS = Object.freeze(Object.keys(SECRET_LABELS));
379
+ //#endregion
380
+ //#region src/secrets/scan.ts
381
+ /** Longest text scanned, in characters. Default 1,000,000; the rest is not scanned (`truncated`). */
382
+ const DEFAULT_SECRET_SCAN_LENGTH = 1e6;
383
+ /** A preview of `secret` safe to show: a known prefix and, where allowed, the last 4 characters. */
384
+ function mask(kind, secret, keep, tail) {
385
+ if (kind === "private-key") return "-----BEGIN … PRIVATE KEY-----";
386
+ const compact = kind === "card-number" || kind === "iban" ? secret.replace(/[ -]/g, "") : secret;
387
+ if (kind === "card-number") return `\u2022\u2022\u2022\u2022 ${compact.slice(-4)}`;
388
+ if (!tail) return "•".repeat(8);
389
+ return compact.length - keep < 12 ? `${compact.slice(0, keep)}\u2026` : `${compact.slice(0, keep)}\u2026${compact.slice(-4)}`;
390
+ }
391
+ function finding(kind, confidence, start, secret, keep, tail, priority) {
392
+ return {
393
+ kind,
394
+ label: SECRET_LABELS[kind],
395
+ confidence,
396
+ start,
397
+ end: start + secret.length,
398
+ masked: mask(kind, secret, keep, tail),
399
+ priority
400
+ };
401
+ }
402
+ /** Private keys: from their `BEGIN` line to their `END` line, or to the end of the text when it is cut off. */
403
+ function privateKeys(text) {
404
+ const found = [];
405
+ for (const match of text.matchAll(PRIVATE_KEY)) {
406
+ const start = match.index;
407
+ const endLine = /-----END [A-Z0-9 ]{0,80}-----/g;
408
+ endLine.lastIndex = start + match[0].length;
409
+ const end = endLine.exec(text);
410
+ const stop = end === null ? text.length : end.index + end[0].length;
411
+ found.push(finding("private-key", "high", start, text.slice(start, stop), 0, false, -1));
412
+ }
413
+ return found;
414
+ }
415
+ /**
416
+ * Finds secrets in `text`: keys and tokens of services by their documented formats, private
417
+ * keys, passwords in URLs and connection strings, card numbers and IBANs by their checksums,
418
+ * and random-looking values assigned to names such as `password` or `api_key`.
419
+ *
420
+ * Findings say where each secret is and what kind it is, with a masked preview; they never
421
+ * hold the secret. Every pattern runs in linear time, so any text is safe to scan. Works
422
+ * anywhere, including servers.
423
+ *
424
+ * @example
425
+ * const { findings } = scanSecrets(pastedText);
426
+ * if (findings.length > 0) warn(`This contains a ${findings[0].label}.`);
427
+ *
428
+ * @throws {CopyFailure} `invalid-payload` for an unknown kind or a negative `maxLength`.
429
+ */
430
+ function scanSecrets(text, options = {}) {
431
+ const kinds = new Set(options.kinds ?? SECRET_KINDS);
432
+ for (const kind of kinds) if (!SECRET_KINDS.includes(kind)) throw copyFailure("invalid-payload", `Unknown secret kind: ${kind}.`);
433
+ const maxLength = options.maxLength ?? 1e6;
434
+ if (!(maxLength >= 0)) throw copyFailure("invalid-payload", "maxLength must be a number of at least 0.");
435
+ const scanned = text.length > maxLength ? text.slice(0, maxLength) : text;
436
+ const highOnly = options.minConfidence === "high";
437
+ const candidates = kinds.has("private-key") ? privateKeys(scanned) : [];
438
+ RULES.forEach((rule, priority) => {
439
+ if (!kinds.has(rule.kind) && !(rule.kind === "generic-secret" && kinds.has("aws-secret-access-key"))) return;
440
+ const pattern = rule.pattern;
441
+ pattern.lastIndex = 0;
442
+ for (let match = pattern.exec(scanned); match !== null; match = pattern.exec(scanned)) {
443
+ const secret = match[rule.group];
444
+ const start = match.index + match[0].length - secret.length;
445
+ const verdict = rule.check(secret, match);
446
+ const kind = verdict?.kind ?? rule.kind;
447
+ if (verdict === null || !kinds.has(kind)) {
448
+ if (rule.retry === true) pattern.lastIndex = start + 1;
449
+ continue;
450
+ }
451
+ const value = secret.slice(0, verdict.length);
452
+ const keep = typeof rule.keep === "number" ? rule.keep : rule.keep(value);
453
+ candidates.push(finding(kind, verdict.confidence, start, value, keep, rule.tail, priority));
454
+ pattern.lastIndex = start + verdict.length;
455
+ }
456
+ });
457
+ candidates.sort((a, b) => a.start - b.start || a.priority - b.priority);
458
+ const findings = [];
459
+ let reached = 0;
460
+ for (const candidate of candidates) {
461
+ if (highOnly && candidate.confidence !== "high" || candidate.start < reached) continue;
462
+ const { kind, label, confidence, start, end, masked } = candidate;
463
+ findings.push({
464
+ kind,
465
+ label,
466
+ confidence,
467
+ start,
468
+ end,
469
+ masked
470
+ });
471
+ reached = end;
472
+ }
473
+ return {
474
+ findings,
475
+ truncated: scanned.length < text.length
476
+ };
477
+ }
478
+ //#endregion
479
+ //#region src/secrets/redact.ts
480
+ const defaultReplace = (finding) => `[redacted ${finding.label}]`;
481
+ /**
482
+ * `text` with every secret {@link scanSecrets} finds replaced, by default with
483
+ * `[redacted <label>]`. Text past `maxLength` is dropped, never passed on unscanned.
484
+ *
485
+ * @example
486
+ * redactSecrets('token: ghp_...').text; // 'token: [redacted GitHub token]'
487
+ */
488
+ function redactSecrets(text, options = {}) {
489
+ const { findings, truncated } = scanSecrets(text, options);
490
+ const replace = options.replace ?? defaultReplace;
491
+ let out = "";
492
+ let at = 0;
493
+ for (const finding of findings) {
494
+ out += text.slice(at, finding.start) + replace(finding);
495
+ at = finding.end;
496
+ }
497
+ const end = truncated ? options.maxLength : text.length;
498
+ return {
499
+ text: out + text.slice(at, end),
500
+ findings,
501
+ truncated
502
+ };
503
+ }
504
+ /**
505
+ * A transform for `useCopyInterceptor` and `registerCopyInterceptor`: when what people copy
506
+ * from your page (logs, settings, a support console) holds secrets, the clipboard gets the
507
+ * text with them redacted; other copies are left to the browser. The redacted copy is
508
+ * plain text: formatting around a secret could carry it too.
509
+ *
510
+ * @example
511
+ * useCopyInterceptor(logViewerRef, { transform: secretRedactor() });
512
+ */
513
+ function secretRedactor(options = {}) {
514
+ return (selection) => {
515
+ const redacted = redactSecrets(selection.text, options);
516
+ return redacted.findings.length === 0 && !redacted.truncated ? null : redacted.text;
517
+ };
518
+ }
519
+ //#endregion
520
+ //#region src/secrets/paste.ts
521
+ /**
522
+ * A paste handler that keeps secrets out of a field: chat boxes, comments, tickets and
523
+ * forms where an API key or a password pasted by mistake would be seen or stored. A paste
524
+ * without secrets is left to the browser.
525
+ *
526
+ * @example
527
+ * <textarea onPaste={(event) => pasteWithoutSecrets(event, { onSecrets: (found) => toast(`Removed a ${found[0].label}.`) })} />
528
+ */
529
+ function pasteWithoutSecrets(event, options = {}) {
530
+ if (event.defaultPrevented || event.clipboardData === null) return "clean";
531
+ const text = event.clipboardData.getData("text/plain");
532
+ if (text === "") return "clean";
533
+ const redacted = redactSecrets(text, options);
534
+ if (redacted.findings.length === 0 && !redacted.truncated) return "clean";
535
+ event.preventDefault();
536
+ const field = asTextField(event.currentTarget) ?? asTextField(event.target);
537
+ const outcome = options.action !== "block" && field !== null && insertText(field, redacted.text) ? "redacted" : "blocked";
538
+ options.onSecrets?.(redacted.findings, outcome);
539
+ return outcome;
540
+ }
541
+ //#endregion
542
+ export { DEFAULT_SECRET_SCAN_LENGTH, SECRET_KINDS, SECRET_LABELS, pasteWithoutSecrets, redactSecrets, scanSecrets, secretRedactor };
543
+
544
+ //# sourceMappingURL=secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.js","names":[],"sources":["../src/secrets/checks.ts","../src/secrets/rules.ts","../src/secrets/types.ts","../src/secrets/scan.ts","../src/secrets/redact.ts","../src/secrets/paste.ts"],"sourcesContent":["/** Checks that tell real secrets from look-alikes: checksums, structure and randomness. */\n\n/** The Luhn checksum of card numbers. `digits` holds only digits. */\nexport function luhn(digits: string): boolean {\n let sum = 0;\n for (let index = 0; index < digits.length; index += 1) {\n let digit = digits.charCodeAt(digits.length - 1 - index) - 48;\n if (index % 2 === 1) {\n digit *= 2;\n if (digit > 9) digit -= 9;\n }\n sum += digit;\n }\n return sum % 10 === 0;\n}\n\n/** Card brands by their number ranges (IIN) and lengths. */\nconst BRANDS: readonly { readonly prefix: RegExp; readonly lengths: readonly number[] }[] = [\n { prefix: /^4/, lengths: [13, 16, 19] }, // Visa\n { prefix: /^(?:5[1-5]|222[1-9]|22[3-9]\\d|2[3-6]\\d\\d|27[01]\\d|2720)/, lengths: [16] }, // Mastercard\n { prefix: /^3[47]/, lengths: [15] }, // American Express\n { prefix: /^(?:6011|65|64[4-9])/, lengths: [16, 17, 18, 19] }, // Discover\n { prefix: /^35(?:2[89]|[3-8]\\d)/, lengths: [16, 17, 18, 19] }, // JCB\n { prefix: /^3(?:0[0-5]|[689])/, lengths: [14, 15, 16, 17, 18, 19] }, // Diners Club\n { prefix: /^62/, lengths: [16, 17, 18, 19] }, // UnionPay\n];\n\n/**\n * Whether `candidate` is a card number: a known brand's range and length, a valid Luhn\n * checksum, and separators (spaces or dashes) used the way cards print them: none, or one\n * kind in groups of 4 (Amex: 4-6-5).\n */\nexport function isCardNumber(candidate: string): boolean {\n const digits = candidate.replace(/[ -]/g, '');\n const separators = new Set(candidate.replace(/\\d/g, ''));\n if (separators.size > 1) return false;\n if (separators.size === 1) {\n const groups = candidate.split(/[ -]/).map((group) => group.length);\n const fours = groups.slice(0, -1).every((length) => length === 4) && (groups[groups.length - 1] as number) <= 4;\n const amex = groups.join('-') === '4-6-5';\n if (!fours && !amex) return false;\n }\n if (/^(\\d)\\1+$/.test(digits)) return false;\n return BRANDS.some((brand) => brand.prefix.test(digits) && brand.lengths.includes(digits.length)) && luhn(digits);\n}\n\n/** IBAN lengths by country (ISO 13616 registry), for the countries that use one. */\nconst IBAN_LENGTHS: Readonly<Record<string, number>> = {\n AD: 24, AE: 23, AL: 28, AT: 20, AZ: 28, BA: 20, BE: 16, BG: 22, BH: 22, BR: 29, BY: 28, CH: 21, CR: 22, CY: 28, CZ: 24,\n DE: 22, DK: 18, DO: 28, EE: 20, EG: 29, ES: 24, FI: 18, FO: 18, FR: 27, GB: 22, GE: 22, GI: 23, GL: 18, GR: 27, GT: 28,\n HR: 21, HU: 28, IE: 22, IL: 23, IQ: 23, IS: 26, IT: 27, JO: 30, KW: 30, KZ: 20, LB: 28, LC: 32, LI: 21, LT: 20, LU: 20,\n LV: 21, MC: 27, MD: 24, ME: 22, MK: 19, MR: 27, MT: 31, MU: 30, NL: 18, NO: 15, PK: 24, PL: 28, PS: 29, PT: 25, QA: 29,\n RO: 24, RS: 22, SA: 24, SC: 31, SE: 24, SI: 19, SK: 24, SM: 27, ST: 25, SV: 28, TL: 23, TN: 24, TR: 26, UA: 29, VA: 22,\n VG: 24, XK: 20,\n};\n\n/** Whether `candidate` (spaces allowed) is an IBAN: its country's length and a valid mod-97 checksum. */\nexport function isIban(candidate: string): boolean {\n const iban = candidate.replace(/ /g, '');\n if (IBAN_LENGTHS[iban.slice(0, 2)] !== iban.length) return false;\n const rearranged = iban.slice(4) + iban.slice(0, 4);\n let remainder = 0;\n for (const char of rearranged) {\n const code = char.charCodeAt(0);\n // Letters count as two digits (A = 10 ... Z = 35); digits as themselves.\n const value = code >= 65 ? code - 55 : code - 48;\n remainder = (value > 9 ? remainder * 100 + value : remainder * 10 + value) % 97;\n }\n return remainder === 1;\n}\n\n/** Shannon entropy of `text`, in bits per character. */\nexport function entropy(text: string): number {\n const counts = new Map<string, number>();\n for (const char of text) counts.set(char, (counts.get(char) ?? 0) + 1);\n let bits = 0;\n for (const count of counts.values()) {\n const p = count / text.length;\n bits -= p * Math.log2(p);\n }\n return bits;\n}\n\n/** Values that stand in for a secret in examples and templates, never a secret themselves. */\nconst PLACEHOLDER =\n /^(?:x+|\\*+|\\.+|-+|_+|#+|0+|<[^>]*>|\\[[^\\]]*\\]|\\$\\{[^}]*\\}|\\{\\{[^}]*\\}\\}|%[^%]*%|\\$[A-Z_][A-Z0-9_]*|your[_-]?[\\w-]*|my[_-][\\w-]*|change[_-]?me|example[\\w-]*|sample[\\w-]*|dummy[\\w-]*|fake[\\w-]*|placeholder[\\w-]*|redacted|null|none|undefined)$/i;\n\n/** A reference to another value, not a value: `process.env.TOKEN`, `config.api.key`. */\nconst REFERENCE = /^[A-Za-z_$][\\w$]*(?:\\.[A-Za-z_$][\\w$]*)+$/;\n\n/** Whether `value` looks like a real secret: random enough, and not a placeholder or a reference. */\nexport function looksSecret(value: string, minEntropy: number): boolean {\n return !PLACEHOLDER.test(value) && !REFERENCE.test(value) && entropy(value) >= minEntropy;\n}\n\n/** Whether the first part of a JWT decodes to a JSON header with an algorithm. */\nexport function isJwtHeader(part: string): boolean {\n if (typeof atob !== 'function') return true;\n try {\n const base64 = part.replace(/-/g, '+').replace(/_/g, '/');\n const header: unknown = JSON.parse(atob(base64 + '='.repeat((4 - (base64.length % 4)) % 4)));\n return typeof header === 'object' && header !== null && typeof (header as { alg?: unknown }).alg === 'string';\n } catch {\n return false;\n }\n}\n","import { isCardNumber, isIban, isJwtHeader, looksSecret } from './checks';\nimport type { SecretConfidence, SecretKind } from './types';\n\n/** A rule's verdict on a candidate: how sure it is, and how much of the candidate is the secret. */\nexport interface Verdict {\n readonly confidence: SecretConfidence;\n /** Characters of the candidate that are the secret (a card number followed by more digits). */\n readonly length: number;\n /** The kind, when one pattern finds two (an AWS secret key, or a generic secret). */\n readonly kind?: SecretKind;\n}\n\n/**\n * One way to find a kind of secret. Every pattern is global and linear: bounded repeats,\n * no nested quantifiers, no lookbehind (older Safari). Group `group` is the secret, and it\n * ends the match: whatever follows is only looked ahead at, so the secret's start is the\n * match's end minus its length. The scan goes on right after each secret found.\n */\nexport interface Rule {\n readonly kind: SecretKind;\n readonly pattern: RegExp;\n readonly group: number;\n /** Characters of the secret a preview may show at the start: its known prefix. */\n readonly keep: number | ((secret: string) => number);\n /** Whether a preview may show the last 4 characters (never for passwords). */\n readonly tail: boolean;\n readonly check: (secret: string, match: RegExpMatchArray) => Verdict | null;\n /**\n * When `check` turns a match down, look again from the character after its start: a short\n * candidate (a card, an IBAN) can run into the next one. Other rules go on after the match.\n */\n readonly retry?: boolean;\n}\n\nconst high = (secret: string): Verdict => ({ confidence: 'high', length: secret.length });\nconst medium = (secret: string): Verdict => ({ confidence: 'medium', length: secret.length });\n\n/** Start of a token: the start of the text, or a character that can't be part of one. */\nconst B = '(^|[^A-Za-z0-9_])';\n/** After a token: nothing that could continue it. */\nconst E = '(?![A-Za-z0-9_])';\n\nconst token = (kind: SecretKind, body: string, keep: Rule['keep'], options: { readonly end?: string; readonly flags?: string; readonly confidence?: SecretConfidence } = {}): Rule => ({\n kind,\n pattern: new RegExp(`${B}(${body})${options.end ?? E}`, `g${options.flags ?? ''}`),\n group: 2,\n keep,\n tail: true,\n check: options.confidence === 'medium' ? medium : high,\n});\n\n/** A name, an assignment (`=`, `:`, `=>`, `:=`) and a value: `API_KEY=\"...\"`, `\"password\": \"...\"`. */\nconst ASSIGNMENT = /(^|[^A-Za-z0-9_])([\"']?([A-Za-z_][A-Za-z0-9_.-]{0,63})[\"']?\\s{0,8}(?:=>|:=|[:=])\\s{0,8}[\"'`]?)([^\\s\"'`,;()[\\]{}<>]{8,200})/g;\n\n/** Names that hold secrets, at the end of the name: `password`, `GITHUB_TOKEN`, `db.apiKey`. */\nconst SECRET_NAME = /(?:pass(?:word|wd|phrase)?|pwd|secret|token|api[_.-]?key|access[_.-]?key|private[_.-]?key|auth[_.-]?key|credentials?|client[_.-]?secret|signing[_.-]?key)$/i;\n\n/**\n * A card number, grouped as cards print it or not. The last group is tried without itself\n * too: what follows a card is often more digits (`4242 4242 4242 4242 12/26`, a date).\n */\nfunction card(candidate: string): Verdict | null {\n if (isCardNumber(candidate)) return { confidence: /[ -]/.test(candidate) ? 'high' : 'medium', length: candidate.length };\n const cut = candidate.search(/[ -]\\d{1,4}$/);\n return cut !== -1 && isCardNumber(candidate.slice(0, cut)) ? { confidence: 'high', length: cut } : null;\n}\n\n/** An IBAN, cut to its country's length: what follows (a BIC, a word) is not part of it. */\nfunction iban(candidate: string): Verdict | null {\n let letters = 0;\n for (let index = 0; index < candidate.length; index += 1) {\n if (candidate[index] !== ' ') letters += 1;\n // Each possible length is tried as the end: the checksum and country length decide.\n if (letters >= 15 && (index + 1 === candidate.length || candidate[index + 1] === ' ') && isIban(candidate.slice(0, index + 1))) {\n return { confidence: 'high', length: index + 1 };\n }\n }\n return null;\n}\n\n/** Rules in priority order: when findings overlap, the earlier rule's finding is kept. */\nexport const RULES: readonly Rule[] = [\n token('aws-access-key-id', '(?:AKIA|ASIA|ABIA|ACCA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|APKA)[A-Z2-7]{16}', 4),\n token('github-token', '(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9]{22}_[A-Za-z0-9]{59}', (secret) => secret.indexOf('_') + (secret.startsWith('github_pat_') ? 5 : 1)),\n token('gitlab-token', 'glpat-[A-Za-z0-9_-]{20,64}', 6, { end: '(?![A-Za-z0-9_-])' }),\n token('slack-webhook', 'https://hooks\\\\.slack\\\\.com/services/[A-Z0-9]{8,12}/[A-Z0-9]{8,12}/[A-Za-z0-9]{24}', 33),\n token('slack-token', 'xox[abposr]-[A-Za-z0-9-]{10,250}', 5, { end: '(?![A-Za-z0-9-])' }),\n token('stripe-key', '(?:sk|rk)_live_[A-Za-z0-9]{24,247}', 8),\n token('google-api-key', 'AIza[A-Za-z0-9_-]{35}', 4, { end: '(?![A-Za-z0-9_-])' }),\n token('npm-token', 'npm_[A-Za-z0-9]{36}', 4),\n token('pypi-token', 'pypi-AgEIcHlwaS5vcmc[A-Za-z0-9_-]{50,1000}', 5, { end: '(?![A-Za-z0-9_-])' }),\n token('sendgrid-key', 'SG\\\\.[A-Za-z0-9_-]{22}\\\\.[A-Za-z0-9_-]{43}', 3, { end: '(?![A-Za-z0-9_-])' }),\n {\n kind: 'jwt',\n pattern: /(^|[^A-Za-z0-9_-])(eyJ[A-Za-z0-9_-]{8,4000}\\.eyJ[A-Za-z0-9_-]{8,16000}\\.[A-Za-z0-9_-]{16,4000})(?![A-Za-z0-9_-])/g,\n group: 2,\n keep: 3,\n tail: true,\n check: (secret) => (isJwtHeader(secret.slice(0, secret.indexOf('.'))) ? high(secret) : null),\n },\n {\n kind: 'azure-storage-key',\n pattern: /(^|[;\\s\"'])(AccountKey\\s{0,4}=\\s{0,4})([A-Za-z0-9+/]{86}==)/gi,\n group: 3,\n keep: 0,\n tail: false,\n check: high,\n },\n {\n kind: 'url-credentials',\n // `scheme://user:password@`: the password, up to the `@`.\n pattern: /((?:^|[^A-Za-z0-9+.-])[A-Za-z][A-Za-z0-9+.-]{1,30}:\\/\\/[^\\s:/?#@]{0,256}:)([^\\s/?#@]{1,256})(?=@)/g,\n group: 2,\n keep: 0,\n tail: false,\n check: (secret) => (looksSecret(secret, 0) ? high(secret) : null),\n },\n {\n kind: 'connection-string',\n // `;Password=...` in an ADO.NET or ODBC connection string.\n pattern: /(;\\s{0,4}(?:password|pwd)\\s{0,4}=\\s{0,4})([^;'\"\\s]{1,256})/gi,\n group: 2,\n keep: 0,\n tail: false,\n check: (secret) => (looksSecret(secret, 0) ? high(secret) : null),\n },\n token('twilio-key', 'SK[0-9a-fA-F]{32}', 2, { confidence: 'medium' }),\n {\n kind: 'card-number',\n // Grouped 4-6-5 (American Express), in fours (with a short group after), or not grouped.\n pattern: /(^|[^0-9A-Za-z])(\\d{4}[ -]\\d{6}[ -]\\d{5}|\\d{4}(?:[ -]\\d{4}){2,3}(?:[ -]\\d{1,4})?|\\d{13,19})(?![0-9])/g,\n group: 2,\n keep: 0,\n tail: true,\n check: card,\n retry: true,\n },\n {\n kind: 'iban',\n pattern: /(^|[^A-Za-z0-9])([A-Z]{2}\\d{2}(?: ?[A-Z0-9]){11,40})(?![A-Za-z0-9])/g,\n group: 2,\n keep: 2,\n tail: true,\n check: iban,\n retry: true,\n },\n {\n kind: 'generic-secret',\n pattern: ASSIGNMENT,\n group: 4,\n keep: 0,\n tail: false,\n check: (secret, match) => {\n const name = match[3] as string;\n // An AWS secret key: 40 characters of base64, named for both.\n if (/^[A-Za-z0-9/+]{40}$/.test(secret) && /aws/i.test(name) && /secret/i.test(name)) {\n return { kind: 'aws-secret-access-key', confidence: 'medium', length: secret.length };\n }\n return SECRET_NAME.test(name) && looksSecret(secret, 3) ? medium(secret) : null;\n },\n },\n];\n\n/** `-----BEGIN ... PRIVATE KEY-----`, through its `END` line (or the end of the text, when cut off). */\nexport const PRIVATE_KEY = /-----BEGIN (?:[A-Z0-9]{1,16} ){0,3}PRIVATE KEY(?: BLOCK)?-----/g;\n","/**\n * Kinds of secrets {@link scanSecrets} finds.\n *\n * - Keys and tokens of services, by their documented formats: `private-key` (PEM and\n * OpenSSH), `aws-access-key-id`, `aws-secret-access-key`, `github-token`, `gitlab-token`,\n * `slack-token`, `slack-webhook`, `stripe-key` (live keys), `google-api-key`,\n * `npm-token`, `pypi-token`, `sendgrid-key`, `twilio-key`, `azure-storage-key`, `jwt`.\n * - Credentials inside other text: `url-credentials` (the password in\n * `postgres://user:password@host`), `connection-string` (`Password=` in a connection string).\n * - Financial data, by checksum: `card-number` (Luhn and card brand), `iban` (mod-97 and length).\n * - `generic-secret`: a random-looking value assigned to a name such as `password`, `token`\n * or `api_key` (`API_KEY=\"...\"`, `\"password\": \"...\"`).\n */\nexport type SecretKind =\n | 'private-key'\n | 'aws-access-key-id'\n | 'aws-secret-access-key'\n | 'github-token'\n | 'gitlab-token'\n | 'slack-token'\n | 'slack-webhook'\n | 'stripe-key'\n | 'google-api-key'\n | 'npm-token'\n | 'pypi-token'\n | 'sendgrid-key'\n | 'twilio-key'\n | 'azure-storage-key'\n | 'jwt'\n | 'url-credentials'\n | 'connection-string'\n | 'card-number'\n | 'iban'\n | 'generic-secret';\n\n/** People-facing names of the kinds, for messages and redaction marks. */\nexport const SECRET_LABELS: Readonly<Record<SecretKind, string>> = Object.freeze({\n 'private-key': 'private key',\n 'aws-access-key-id': 'AWS access key ID',\n 'aws-secret-access-key': 'AWS secret access key',\n 'github-token': 'GitHub token',\n 'gitlab-token': 'GitLab token',\n 'slack-token': 'Slack token',\n 'slack-webhook': 'Slack webhook URL',\n 'stripe-key': 'Stripe live key',\n 'google-api-key': 'Google API key',\n 'npm-token': 'npm token',\n 'pypi-token': 'PyPI token',\n 'sendgrid-key': 'SendGrid API key',\n 'twilio-key': 'Twilio API key',\n 'azure-storage-key': 'Azure storage key',\n jwt: 'JSON Web Token',\n 'url-credentials': 'password in a URL',\n 'connection-string': 'password in a connection string',\n 'card-number': 'card number',\n iban: 'IBAN',\n 'generic-secret': 'secret',\n});\n\n/** Every kind, in a stable order. */\nexport const SECRET_KINDS: readonly SecretKind[] = Object.freeze(Object.keys(SECRET_LABELS) as SecretKind[]);\n\n/**\n * How sure a finding is.\n *\n * - `high`: the documented format of a service, a valid checksum (cards, IBANs), or a\n * structure that only credentials have (a PEM private key, a password in a URL).\n * - `medium`: the shape fits, but other data has it too: an AWS secret key next to its name,\n * a Twilio key, a value assigned to a secret-sounding name.\n */\nexport type SecretConfidence = 'high' | 'medium';\n\nexport interface SecretFinding {\n readonly kind: SecretKind;\n /** {@link SECRET_LABELS} for the kind. */\n readonly label: string;\n readonly confidence: SecretConfidence;\n /** Where the secret is in the scanned text: `text.slice(start, end)` is the secret. */\n readonly start: number;\n readonly end: number;\n /**\n * A preview safe to show and log: at most a known prefix and the last 4 characters\n * (`ghp_` and `a1B2` around an ellipsis; the last 4 digits of a card). Findings never hold the secret.\n */\n readonly masked: string;\n}\n","import { copyFailure } from '../core/errors';\nimport { PRIVATE_KEY, RULES } from './rules';\nimport { SECRET_KINDS, SECRET_LABELS, type SecretConfidence, type SecretFinding, type SecretKind } from './types';\n\n/** Longest text scanned, in characters. Default 1,000,000; the rest is not scanned (`truncated`). */\nexport const DEFAULT_SECRET_SCAN_LENGTH = 1_000_000;\n\nexport interface ScanSecretsOptions {\n /** Kinds to look for. Default: every kind. */\n readonly kinds?: readonly SecretKind[];\n /** Least confidence reported. Default `'medium'`: everything. `'high'` leaves out guesses. */\n readonly minConfidence?: SecretConfidence;\n /** Longest text scanned, in characters. Default {@link DEFAULT_SECRET_SCAN_LENGTH}. */\n readonly maxLength?: number;\n}\n\nexport interface SecretScan {\n /** In the order they appear; findings never overlap. */\n readonly findings: readonly SecretFinding[];\n /** The text was longer than `maxLength`: only its start was scanned. */\n readonly truncated: boolean;\n}\n\n/** A preview of `secret` safe to show: a known prefix and, where allowed, the last 4 characters. */\nfunction mask(kind: SecretKind, secret: string, keep: number, tail: boolean): string {\n if (kind === 'private-key') return '-----BEGIN \\u2026 PRIVATE KEY-----';\n const compact = kind === 'card-number' || kind === 'iban' ? secret.replace(/[ -]/g, '') : secret;\n if (kind === 'card-number') return `\\u2022\\u2022\\u2022\\u2022 ${compact.slice(-4)}`;\n if (!tail) return '\\u2022'.repeat(8);\n // Short secrets show no more than their prefix: their last characters would give too much away.\n return compact.length - keep < 12 ? `${compact.slice(0, keep)}\\u2026` : `${compact.slice(0, keep)}\\u2026${compact.slice(-4)}`;\n}\n\ninterface Candidate extends SecretFinding {\n readonly priority: number;\n}\n\nfunction finding(kind: SecretKind, confidence: SecretConfidence, start: number, secret: string, keep: number, tail: boolean, priority: number): Candidate {\n return { kind, label: SECRET_LABELS[kind], confidence, start, end: start + secret.length, masked: mask(kind, secret, keep, tail), priority };\n}\n\n/** Private keys: from their `BEGIN` line to their `END` line, or to the end of the text when it is cut off. */\nfunction privateKeys(text: string): Candidate[] {\n const found: Candidate[] = [];\n for (const match of text.matchAll(PRIVATE_KEY)) {\n const start = match.index;\n const endLine = /-----END [A-Z0-9 ]{0,80}-----/g;\n endLine.lastIndex = start + match[0].length;\n const end = endLine.exec(text);\n const stop = end === null ? text.length : end.index + end[0].length;\n found.push(finding('private-key', 'high', start, text.slice(start, stop), 0, false, -1));\n }\n return found;\n}\n\n/**\n * Finds secrets in `text`: keys and tokens of services by their documented formats, private\n * keys, passwords in URLs and connection strings, card numbers and IBANs by their checksums,\n * and random-looking values assigned to names such as `password` or `api_key`.\n *\n * Findings say where each secret is and what kind it is, with a masked preview; they never\n * hold the secret. Every pattern runs in linear time, so any text is safe to scan. Works\n * anywhere, including servers.\n *\n * @example\n * const { findings } = scanSecrets(pastedText);\n * if (findings.length > 0) warn(`This contains a ${findings[0].label}.`);\n *\n * @throws {CopyFailure} `invalid-payload` for an unknown kind or a negative `maxLength`.\n */\nexport function scanSecrets(text: string, options: ScanSecretsOptions = {}): SecretScan {\n const kinds = new Set(options.kinds ?? SECRET_KINDS);\n for (const kind of kinds) {\n if (!SECRET_KINDS.includes(kind)) throw copyFailure('invalid-payload', `Unknown secret kind: ${kind}.`);\n }\n const maxLength = options.maxLength ?? DEFAULT_SECRET_SCAN_LENGTH;\n if (!(maxLength >= 0)) throw copyFailure('invalid-payload', 'maxLength must be a number of at least 0.');\n const scanned = text.length > maxLength ? text.slice(0, maxLength) : text;\n const highOnly = options.minConfidence === 'high';\n\n const candidates: Candidate[] = kinds.has('private-key') ? privateKeys(scanned) : [];\n RULES.forEach((rule, priority) => {\n // One pattern can find two kinds (an AWS secret key, or a generic secret): both are checked below.\n if (!kinds.has(rule.kind) && !(rule.kind === 'generic-secret' && kinds.has('aws-secret-access-key'))) return;\n // Patterns are shared: the scan is synchronous, so resetting `lastIndex` is enough.\n const pattern = rule.pattern;\n pattern.lastIndex = 0;\n for (let match = pattern.exec(scanned); match !== null; match = pattern.exec(scanned)) {\n const secret = match[rule.group] as string;\n const start = match.index + match[0].length - secret.length;\n const verdict = rule.check(secret, match);\n const kind = verdict?.kind ?? rule.kind;\n if (verdict === null || !kinds.has(kind)) {\n if (rule.retry === true) pattern.lastIndex = start + 1;\n continue;\n }\n const value = secret.slice(0, verdict.length);\n const keep = typeof rule.keep === 'number' ? rule.keep : rule.keep(value);\n candidates.push(finding(kind, verdict.confidence, start, value, keep, rule.tail, priority));\n // What the match read past the secret (more digits after a card) is looked at again.\n pattern.lastIndex = start + verdict.length;\n }\n });\n\n // Overlapping findings: the earliest wins, then the most specific rule. A rule finds at most\n // one secret at a position, so no two candidates tie.\n candidates.sort((a, b) => a.start - b.start || a.priority - b.priority);\n const findings: SecretFinding[] = [];\n let reached = 0;\n for (const candidate of candidates) {\n if ((highOnly && candidate.confidence !== 'high') || candidate.start < reached) continue;\n const { kind, label, confidence, start, end, masked } = candidate;\n findings.push({ kind, label, confidence, start, end, masked });\n reached = end;\n }\n return { findings, truncated: scanned.length < text.length };\n}\n","import type { CopyInterceptTransform } from '../core/copy-interceptor';\nimport { scanSecrets, type ScanSecretsOptions } from './scan';\nimport type { SecretFinding } from './types';\n\nexport interface RedactSecretsOptions extends ScanSecretsOptions {\n /** What replaces each secret. Default: `[redacted <label>]`, as in `[redacted GitHub token]`. */\n readonly replace?: (finding: SecretFinding) => string;\n}\n\nexport interface RedactedText {\n /** The text with each secret replaced. */\n readonly text: string;\n /** What was replaced, at its place in the original text. */\n readonly findings: readonly SecretFinding[];\n /** The text was longer than `maxLength`: the rest was neither scanned nor kept. */\n readonly truncated: boolean;\n}\n\nconst defaultReplace = (finding: SecretFinding): string => `[redacted ${finding.label}]`;\n\n/**\n * `text` with every secret {@link scanSecrets} finds replaced, by default with\n * `[redacted <label>]`. Text past `maxLength` is dropped, never passed on unscanned.\n *\n * @example\n * redactSecrets('token: ghp_...').text; // 'token: [redacted GitHub token]'\n */\nexport function redactSecrets(text: string, options: RedactSecretsOptions = {}): RedactedText {\n const { findings, truncated } = scanSecrets(text, options);\n const replace = options.replace ?? defaultReplace;\n let out = '';\n let at = 0;\n for (const finding of findings) {\n out += text.slice(at, finding.start) + replace(finding);\n at = finding.end;\n }\n const end = truncated ? (options.maxLength as number) : text.length;\n return { text: out + text.slice(at, end), findings, truncated };\n}\n\n/**\n * A transform for `useCopyInterceptor` and `registerCopyInterceptor`: when what people copy\n * from your page (logs, settings, a support console) holds secrets, the clipboard gets the\n * text with them redacted; other copies are left to the browser. The redacted copy is\n * plain text: formatting around a secret could carry it too.\n *\n * @example\n * useCopyInterceptor(logViewerRef, { transform: secretRedactor() });\n */\nexport function secretRedactor(options: RedactSecretsOptions = {}): CopyInterceptTransform {\n return (selection) => {\n const redacted = redactSecrets(selection.text, options);\n return redacted.findings.length === 0 && !redacted.truncated ? null : redacted.text;\n };\n}\n","import { asTextField, insertText } from '../core/text-field';\nimport { redactSecrets, type RedactSecretsOptions } from './redact';\nimport type { SecretFinding } from './types';\n\n/** What {@link pasteWithoutSecrets} did. */\nexport type SecretPasteOutcome =\n /** No secrets (or nothing to read): the browser pasted as usual. */\n | 'clean'\n /** The paste was inserted with its secrets redacted. */\n | 'redacted'\n /** The paste was stopped: nothing was inserted. */\n | 'blocked';\n\nexport interface PasteWithoutSecretsOptions extends RedactSecretsOptions {\n /**\n * `'redact'` (default) inserts the paste with its secrets replaced, into a `<textarea>` or\n * text `<input>`, with undo intact. `'block'` inserts nothing. Where text can't be inserted\n * (another element), a paste with secrets is blocked.\n */\n readonly action?: 'redact' | 'block';\n /** Called when a paste held secrets, with what was found and what was done. */\n readonly onSecrets?: (findings: readonly SecretFinding[], outcome: Exclude<SecretPasteOutcome, 'clean'>) => void;\n}\n\n/** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */\nexport interface SecretPasteEvent {\n readonly clipboardData: { getData(format: string): string } | null;\n readonly currentTarget: EventTarget | null;\n readonly target: EventTarget | null;\n readonly defaultPrevented: boolean;\n preventDefault(): void;\n}\n\n/**\n * A paste handler that keeps secrets out of a field: chat boxes, comments, tickets and\n * forms where an API key or a password pasted by mistake would be seen or stored. A paste\n * without secrets is left to the browser.\n *\n * @example\n * <textarea onPaste={(event) => pasteWithoutSecrets(event, { onSecrets: (found) => toast(`Removed a ${found[0].label}.`) })} />\n */\nexport function pasteWithoutSecrets(event: SecretPasteEvent, options: PasteWithoutSecretsOptions = {}): SecretPasteOutcome {\n if (event.defaultPrevented || event.clipboardData === null) return 'clean';\n const text = event.clipboardData.getData('text/plain');\n if (text === '') return 'clean';\n const redacted = redactSecrets(text, options);\n if (redacted.findings.length === 0 && !redacted.truncated) return 'clean';\n event.preventDefault();\n const field = asTextField(event.currentTarget) ?? asTextField(event.target);\n const outcome = options.action !== 'block' && field !== null && insertText(field, redacted.text) ? 'redacted' : 'blocked';\n options.onSecrets?.(redacted.findings, outcome);\n return outcome;\n}\n"],"mappings":";;;;;;AAGA,SAAgB,KAAK,QAAyB;CAC5C,IAAI,MAAM;CACV,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS,GAAG;EACrD,IAAI,QAAQ,OAAO,WAAW,OAAO,SAAS,IAAI,KAAK,IAAI;EAC3D,IAAI,QAAQ,MAAM,GAAG;GACnB,SAAS;GACT,IAAI,QAAQ,GAAG,SAAS;EAC1B;EACA,OAAO;CACT;CACA,OAAO,MAAM,OAAO;AACtB;;AAGA,MAAM,SAAsF;CAC1F;EAAE,QAAQ;EAAM,SAAS;GAAC;GAAI;GAAI;EAAE;CAAE;CACtC;EAAE,QAAQ;EAA2D,SAAS,CAAC,EAAE;CAAE;CACnF;EAAE,QAAQ;EAAU,SAAS,CAAC,EAAE;CAAE;CAClC;EAAE,QAAQ;EAAwB,SAAS;GAAC;GAAI;GAAI;GAAI;EAAE;CAAE;CAC5D;EAAE,QAAQ;EAAwB,SAAS;GAAC;GAAI;GAAI;GAAI;EAAE;CAAE;CAC5D;EAAE,QAAQ;EAAsB,SAAS;GAAC;GAAI;GAAI;GAAI;GAAI;GAAI;EAAE;CAAE;CAClE;EAAE,QAAQ;EAAO,SAAS;GAAC;GAAI;GAAI;GAAI;EAAE;CAAE;AAC7C;;;;;;AAOA,SAAgB,aAAa,WAA4B;CACvD,MAAM,SAAS,UAAU,QAAQ,SAAS,EAAE;CAC5C,MAAM,aAAa,IAAI,IAAI,UAAU,QAAQ,OAAO,EAAE,CAAC;CACvD,IAAI,WAAW,OAAO,GAAG,OAAO;CAChC,IAAI,WAAW,SAAS,GAAG;EACzB,MAAM,SAAS,UAAU,MAAM,MAAM,CAAC,CAAC,KAAK,UAAU,MAAM,MAAM;EAClE,MAAM,QAAQ,OA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