tazuna 0.18.0 → 0.19.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.
package/dist/core/mask.js
CHANGED
|
@@ -242,6 +242,147 @@ const ENV_LINE = /^((?:export[ \t]+|[ \t]*-[ \t]+["']?)?)([A-Za-z0-9_.-]+)(=)([^
|
|
|
242
242
|
const DOCKER_ENV = /^((?:ENV|ARG)[ \t]+)((?:[^\r\n]*\\[ \t]*\r?\n)*[^\r\n]*)/gm;
|
|
243
243
|
/** Dockerfile の ENV / ARG の KEY=value(値は空白まで。\ の後の空白は値のうち。引用符で囲んだものは引用符まで) */
|
|
244
244
|
const DOCKER_PAIR = /(?<![^ \t\r\n])([A-Za-z_][A-Za-z0-9_.-]*)(=)("(?:[^"\\\r\n]|\\.)*"|"[^"\r\n]*"|'[^'\r\n]*'|(?:\\[^\r\n]|[^\s"'\\])*)/g;
|
|
245
|
+
/**
|
|
246
|
+
* YAML・.properties・setup.cfg・HOCON などの、引用符で囲まない `キー: 値`(行の頭のキー。字下げ・一覧の `- ` の後も。
|
|
247
|
+
* v0.19.0)。値は行末まで(空白の後の # からはコメント)。引用符で囲んだ値は KEY_LITERAL で読む。
|
|
248
|
+
* コードのファイル(字句解析のない言語)ではオブジェクト・構造体のフィールドと区別できないため使わない(isCodePath)
|
|
249
|
+
*/
|
|
250
|
+
const COLON_PAIR = /^([ \t]*(?:-[ \t]+)?)([A-Za-z_][A-Za-z0-9_.-]*)([ \t]*:[ \t]+)([^\r\n]*)/gm;
|
|
251
|
+
/** YAML の真偽値・空の値 */
|
|
252
|
+
const YAML_NON_VALUE = /^(?:~|null|true|false|yes|no|on|off)$/i;
|
|
253
|
+
/** YAML の `|` / `>` の値(続く字下げの深い行が値) */
|
|
254
|
+
const YAML_BLOCK_SCALAR = /^[|>](?:[-+]?[1-9]?|[1-9][-+])$/;
|
|
255
|
+
/**
|
|
256
|
+
* 型の名前(文書に書いたコードの `password: string` / `api_key: Option<String>` / `password: varchar(255)`)。
|
|
257
|
+
* 値がこれらの名前だけ(型の引数・配列・? を含む)なら値ではない
|
|
258
|
+
*/
|
|
259
|
+
const TYPE_LIKE = /^&?(?:'[a-z]+[ \t]+)?(?:mut[ \t]+)?([A-Za-z_][\w.]*)(?:<[^<>\r\n]*>|\[[^\[\]\r\n]*\]|\([\d, ]*\))?\??$/;
|
|
260
|
+
const TYPE_NAMES = new Set([
|
|
261
|
+
"string",
|
|
262
|
+
"str",
|
|
263
|
+
"number",
|
|
264
|
+
"int",
|
|
265
|
+
"integer",
|
|
266
|
+
"long",
|
|
267
|
+
"short",
|
|
268
|
+
"float",
|
|
269
|
+
"double",
|
|
270
|
+
"decimal",
|
|
271
|
+
"bool",
|
|
272
|
+
"boolean",
|
|
273
|
+
"byte",
|
|
274
|
+
"bytes",
|
|
275
|
+
"char",
|
|
276
|
+
"any",
|
|
277
|
+
"unknown",
|
|
278
|
+
"object",
|
|
279
|
+
"text",
|
|
280
|
+
"varchar",
|
|
281
|
+
"varchar2",
|
|
282
|
+
"nvarchar",
|
|
283
|
+
"nvarchar2",
|
|
284
|
+
"uuid",
|
|
285
|
+
"date",
|
|
286
|
+
"datetime",
|
|
287
|
+
"timestamp",
|
|
288
|
+
"json",
|
|
289
|
+
"secretstr",
|
|
290
|
+
"option",
|
|
291
|
+
"optional",
|
|
292
|
+
"vec",
|
|
293
|
+
"list",
|
|
294
|
+
]);
|
|
295
|
+
/** 値が型の名前だけか(TYPE_LIKE / TYPE_NAMES) */
|
|
296
|
+
function isTypeName(value) {
|
|
297
|
+
const name = TYPE_LIKE.exec(value)?.[1];
|
|
298
|
+
return name !== undefined && TYPE_NAMES.has(name.toLowerCase());
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* 字句解析のない言語のソースのパス(.php / .rb / .rs / .kt / .swift / .vue / .c など)と、言語の分かるソース・.vb。
|
|
302
|
+
* これらでは `キー: 値`(COLON_PAIR)を読まない(`password: hashedPassword` のようなオブジェクト・構造体の
|
|
303
|
+
* フィールド・名前付き引数を伏せないように。言語の分かるソースは言語ごとの伏せ方で文字列・コメントの中だけを読む)
|
|
304
|
+
*/
|
|
305
|
+
const CODE_PATH = /\.(?:vb|bas|cls|frm|ctl|php\d?|phtml|inc|rb|rake|gemspec|rs|kt|kts|swift|scala|sc|dart|vue|svelte|astro|c|h|cc|cpp|cxx|hpp|hh|hxx|m|mm|lua|pl|pm|r|ex|exs|erl|hrl|hs|ml|mli|fs|fsx|fsi|clj|cljs|cljc|groovy|gradle|jl|nim|zig|cr|coffee|elm|ps1|psm1|psd1|cshtml|vbhtml|razor|aspx|ascx|jsp|erb|haml|slim|twig)$/i;
|
|
306
|
+
function isCodePath(path) {
|
|
307
|
+
return CODE_PATH.test(path) || sourceLanguageOf(path) !== undefined;
|
|
308
|
+
}
|
|
309
|
+
/** 行の字下げの幅(空白とタブの数) */
|
|
310
|
+
function indentWidth(line) {
|
|
311
|
+
return /^[ \t]*/.exec(line)?.[0].length ?? 0;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* 引用符で囲まない `キー: 値` の秘密系のキーの値を伏せる(COLON_PAIR)。ユーザー ID 系のキーは伏せない
|
|
315
|
+
* (`user: deploy` / k8s の `runAsUser: 1000` など、値でないものが多いため)。値でないもの: 空(入れ子)・真偽値・
|
|
316
|
+
* 差し込み(${DB_PASSWORD} / {{ x }} / <%= ... %> / @x@)・YAML の別名(*x)・タグ(!vault)・入れ物({ / [)・
|
|
317
|
+
* 型の名前・コードの続き(行末の , ; { ( [ \)・表示の文言(空白・日本語を含む値・キー名そのもの)。
|
|
318
|
+
* `|` / `>` の値は、続く字下げの深い行をまとめて 1 つの伏せ字にする
|
|
319
|
+
*/
|
|
320
|
+
function maskColonPairs(source, findings) {
|
|
321
|
+
const pattern = new RegExp(COLON_PAIR.source, COLON_PAIR.flags);
|
|
322
|
+
let out = "";
|
|
323
|
+
let last = 0;
|
|
324
|
+
for (let m = pattern.exec(source); m !== null; m = pattern.exec(source)) {
|
|
325
|
+
const lead = m[1] ?? "";
|
|
326
|
+
const key = m[2] ?? "";
|
|
327
|
+
const sep = m[3] ?? "";
|
|
328
|
+
const rest = m[4] ?? "";
|
|
329
|
+
if (kindForConfigKey(key) !== KIND_PASSWORD)
|
|
330
|
+
continue;
|
|
331
|
+
// アンカー(password: &pw 値)の後ろが値
|
|
332
|
+
const anchor = /^&[^\s]+[ \t]+/.exec(rest)?.[0] ?? "";
|
|
333
|
+
const body = rest.slice(anchor.length);
|
|
334
|
+
if (/^["']/.test(body))
|
|
335
|
+
continue;
|
|
336
|
+
const value = body.replace(/(?:^|[ \t]+)#.*$/, "").replace(/[ \t]+$/, "");
|
|
337
|
+
const valueStart = m.index + lead.length + key.length + sep.length + anchor.length;
|
|
338
|
+
if (YAML_BLOCK_SCALAR.test(value)) {
|
|
339
|
+
// 続く行のうち、キーの位置より深く字下げした行(間の空行も)が値
|
|
340
|
+
const lineEnd = m.index + m[0].length;
|
|
341
|
+
let cursor = lineEnd;
|
|
342
|
+
let first = -1;
|
|
343
|
+
let end = -1;
|
|
344
|
+
while (cursor < source.length) {
|
|
345
|
+
const next = source.indexOf("\n", cursor + 1);
|
|
346
|
+
const lineStart = cursor + 1;
|
|
347
|
+
const line = source.slice(lineStart, next < 0 ? source.length : next).replace(/\r$/, "");
|
|
348
|
+
if (line.trim() !== "") {
|
|
349
|
+
if (indentWidth(line) <= lead.length)
|
|
350
|
+
break;
|
|
351
|
+
if (first < 0)
|
|
352
|
+
first = lineStart + indentWidth(line);
|
|
353
|
+
end = lineStart + line.replace(/[ \t]+$/, "").length;
|
|
354
|
+
}
|
|
355
|
+
if (next < 0)
|
|
356
|
+
break;
|
|
357
|
+
cursor = next;
|
|
358
|
+
}
|
|
359
|
+
if (first < 0 || source.slice(first, end).includes(MASK))
|
|
360
|
+
continue;
|
|
361
|
+
findings.push({ line: lineOf(source, m.index), kind: KIND_PASSWORD });
|
|
362
|
+
out += `${source.slice(last, first)}${MASK}`;
|
|
363
|
+
last = end;
|
|
364
|
+
pattern.lastIndex = Math.max(pattern.lastIndex, end);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (value === "" ||
|
|
368
|
+
value.includes(MASK) ||
|
|
369
|
+
YAML_NON_VALUE.test(value) ||
|
|
370
|
+
/^[&*!{[(`|>]/.test(value) ||
|
|
371
|
+
// GitHub Actions の ${{ secrets.X }}・Azure Pipelines の $(X)・Maven の @x@・Symfony の %env(X)% / %x%・
|
|
372
|
+
// ERB の <%= ... %>・説明の書き方の <password>
|
|
373
|
+
/^(?:\$\{\{[^\r\n]*\}\}|\$\([\w.]+\)|@[\w.-]+@|%[\w.():-]+%|<[^<>\r\n]*>)$/.test(value) ||
|
|
374
|
+
/[,;{(\[\\]$/.test(value) ||
|
|
375
|
+
isTypeName(value) ||
|
|
376
|
+
isShellVariable(value) ||
|
|
377
|
+
!isSecretPair(key, value, true)) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
findings.push({ line: lineOf(source, m.index), kind: KIND_PASSWORD });
|
|
381
|
+
out += `${source.slice(last, valueStart)}${MASK}`;
|
|
382
|
+
last = valueStart + value.length;
|
|
383
|
+
}
|
|
384
|
+
return out + source.slice(last);
|
|
385
|
+
}
|
|
245
386
|
/**
|
|
246
387
|
* バッチファイルの set の始まり(set DB_PASSWORD= / set "DB_PASSWORD= / @set / if ... set / ... & set。字下げした行も。
|
|
247
388
|
* C の文字列の set \"K= / VB・C# の set ""K= / MSBuild の Exec などの XML の set "K= も)。値の終わりは batchValueEnd で決める
|
|
@@ -252,7 +393,7 @@ const BATCH_SET = /(?<=^|[ \t@(&|;"'>])([Ss][Ee][Tt][ \t]+)(\\"|""|"|")?([A
|
|
|
252
393
|
* net use の共有の後の引数、schtasks の /RP・/P)。パスの途中の語・別の拡張子のファイル名
|
|
253
394
|
* (/var/lib/mysql/・mysql.py・MySql.Data)は除く。MSBuild の "...\SQLCMD.EXE" と %SQLCMD% も読む
|
|
254
395
|
*/
|
|
255
|
-
const CLI_COMMAND = /(?<![\w.-])(sqlcmd|osql|isql|bcp|mysql|mysqldump|mysqladmin|mysqlimport|net[ \t]+use|schtasks)(?:\.exe)?(?=["'\s,\]%!]|&(?:quot|apos);|$)/gi;
|
|
396
|
+
const CLI_COMMAND = /(?<![\w.-])(sqlcmd|osql|isql|bcp|mysql|mysqldump|mysqladmin|mysqlimport|net[ \t]+use|schtasks|sqlplus|exp|imp|expdp|impdp|sqlldr|dgmgrl|rman)(?:\.exe)?(?=["'\s,\]%!]|&(?:quot|apos);|$)/gi;
|
|
256
397
|
/** 引数の区切りの空白(行の継続(バッチの ^ / シェルの \ の後の改行)も) */
|
|
257
398
|
const CLI_SP = String.raw `(?:[ \t]|\^\r?\n|(?<=[ \t])\\\r?\n)+`;
|
|
258
399
|
/** 引用符で囲まない値の文字(行の継続の ^ / \ は値に含めない) */
|
|
@@ -260,6 +401,15 @@ const CLI_BARE = (excluded) => String.raw `(?:[^\s"'` + "`" + String.raw `^\\${e
|
|
|
260
401
|
/** 引用符で囲んだ値("..." / '...' / MSBuild の "...") */
|
|
261
402
|
const CLI_QUOTED = String.raw `"(?:[^"\\\r\n]|\\.)*"|'[^'\r\n]*'|"(?:(?!")[^\r\n])*"`;
|
|
262
403
|
const CLI_VALUE = `${CLI_QUOTED}|${CLI_BARE("")}`;
|
|
404
|
+
/**
|
|
405
|
+
* Oracle のログオン(ユーザー/パスワード[@接続先])の前の部分: 引数の区切り(空白・VB の Process.Start("sqlplus.exe",
|
|
406
|
+
* "...") の "," )と、ログオンを囲む引用符(sqlplus "sys/pw@db as sysdba")。ユーザー名は英字で始まるもの(変数の
|
|
407
|
+
* $DB_USER / %DB_USER% / &1 と、OS 認証の / は除く)か引用符で囲んだもの
|
|
408
|
+
*/
|
|
409
|
+
const ORACLE_GAP = String.raw `["']?(?:${CLI_SP}|[ \t]*,[ \t]*)["']?`;
|
|
410
|
+
const ORACLE_USER = String.raw `(?:[A-Za-z_][\w$#.]*|"[^"\r\n]+")`;
|
|
411
|
+
/** Oracle のログオンのパスワード(引用符で囲んだものか、@ / 空白・引用符・/ の前まで) */
|
|
412
|
+
const ORACLE_PASSWORD = String.raw `"[^"\r\n]*"|[^\s"'@\/]+`;
|
|
263
413
|
/** コマンドの種類ごとの、パスワードの引数(lead = 値の前、value = 値) */
|
|
264
414
|
const CLI_ARGS = [
|
|
265
415
|
[
|
|
@@ -293,6 +443,21 @@ const CLI_ARGS = [
|
|
|
293
443
|
],
|
|
294
444
|
],
|
|
295
445
|
[/^schtasks$/i, [new RegExp(String.raw `((?<=\s)\/(?:rp|p)${CLI_SP})(?!\/)(${CLI_VALUE})`, "gi")]],
|
|
446
|
+
// Oracle のログオン(v0.19.0): sqlplus / exp / imp / expdp / impdp / sqlldr / dgmgrl の最初の引数(-S などの
|
|
447
|
+
// オプションの後)の ユーザー/パスワード[@接続先] と userid=...、rman の target / catalog / auxiliary の後
|
|
448
|
+
[
|
|
449
|
+
/^(?:sqlplus|exp|imp|expdp|impdp|sqlldr|dgmgrl)$/i,
|
|
450
|
+
[
|
|
451
|
+
new RegExp(String.raw `(^[A-Za-z]+(?:\.exe)?${ORACLE_GAP}(?:-[A-Za-z]+${ORACLE_GAP})*["']?${ORACLE_USER}\/)(${ORACLE_PASSWORD})`, "i"),
|
|
452
|
+
new RegExp(String.raw `((?<=[\s"',])userid=["']?${ORACLE_USER}\/)(${ORACLE_PASSWORD})`, "gi"),
|
|
453
|
+
],
|
|
454
|
+
],
|
|
455
|
+
[
|
|
456
|
+
/^rman$/i,
|
|
457
|
+
[
|
|
458
|
+
new RegExp(String.raw `((?<=\s)(?:target|catalog|auxiliary)(?:${CLI_SP}|=)["']?${ORACLE_USER}\/)(${ORACLE_PASSWORD})`, "gi"),
|
|
459
|
+
],
|
|
460
|
+
],
|
|
296
461
|
];
|
|
297
462
|
/** コマンド名のない引数の文字列(ProcessStartInfo.Arguments = "-S srv -U sa -P ...")の -U ユーザー -P パスワード */
|
|
298
463
|
const CLI_USER_PASSWORD = new RegExp(String.raw `((?<=[\s"'])-U[ \t]*(?:${CLI_QUOTED}|[^\s"'` + "`" + String.raw `]+)[ \t]+-P[ \t]*)(${CLI_VALUE})`, "g");
|
|
@@ -489,8 +654,19 @@ const KEY_TYPE = String.raw `[A-Za-z_$][\w$.]*(?:<[^<>\r\n]*>|\[[^\[\]\r\n]*\])*
|
|
|
489
654
|
const KEY_LITERAL = new RegExp(String.raw `((?<![A-Za-z0-9_$.])[A-Za-z_$][A-Za-z0-9_$.]*|"[^"\r\n]*"|'[^'\r\n]*')` +
|
|
490
655
|
String.raw `(\s*(?:(?<=[ \t])[Aa][Ss][ \t]+[A-Za-z_][\w.]*(?:\(\))?[ \t]*=(?!=)` +
|
|
491
656
|
String.raw `|\{[ \t]*get;[ \t]*(?:(?:(?:public|private|protected|internal)[ \t]+)*(?:set|init);[ \t]*)?\}[ \t]*=(?!=)` +
|
|
492
|
-
String.raw
|
|
657
|
+
String.raw `|=>|:=|:|=(?!=))\s*)` +
|
|
493
658
|
KEY_VALUE, "g");
|
|
659
|
+
/**
|
|
660
|
+
* 添字への代入(v0.19.0): $config['db']['password'] = '...' / os.environ["DB_PASSWORD"] = "..." / cfg["apiKey"] = '...'。
|
|
661
|
+
* 添字の文字列をキーとして KEY_LITERAL と同じく判定する
|
|
662
|
+
*/
|
|
663
|
+
const SUBSCRIPT_LITERAL = new RegExp(String.raw `(\[[ \t]*)("[^"\r\n]*"|'[^'\r\n]*')([ \t]*\][ \t]*=(?![=>])[ \t]*)` + KEY_VALUE, "g");
|
|
664
|
+
/**
|
|
665
|
+
* 秘密の名前を最初の引数に渡す関数の 2 番目の文字列(v0.19.0): define('DB_PASSWORD', '...') /
|
|
666
|
+
* env('DB_PASSWORD', '既定値') / os.environ.get("DB_PASSWORD", "既定値") / System.getProperty("db.password", "既定値")。
|
|
667
|
+
* 最初の引数はキーの形の文字列(空白を含まない)だけ
|
|
668
|
+
*/
|
|
669
|
+
const NAMED_ARG_LITERAL = new RegExp(String.raw `(\([ \t]*)("[A-Za-z_][\w.-]*"|'[A-Za-z_][\w.-]*')([ \t]*,[ \t]*)` + KEY_VALUE + String.raw `(?=[ \t]*[,)])`, "g");
|
|
494
670
|
/**
|
|
495
671
|
* 型の注釈つきのキーと文字列の値(TS / Python の password: string = "..." / password:str="...")。KEY_LITERAL の後に
|
|
496
672
|
* 別に探す(同じ式に入れると case "prod": dbPassword = "..." の dbPassword を型と読み、その代入を探し直さないため)。
|
|
@@ -522,7 +698,23 @@ const USER_KEY_WORDS = new Set(["userid", "username", "uid", "user"]);
|
|
|
522
698
|
const WEAK_KEY_WORDS = new Set(["token", "credential", "credentials"]);
|
|
523
699
|
/** 秘密ではない値: 真偽値(SavePassword = True / RequireToken = "true" などの設定)と書式の差し込みだけの値 */
|
|
524
700
|
function isNonSecretValue(value) {
|
|
525
|
-
return /^(?:true|false)$/i.test(value.trim()) ||
|
|
701
|
+
return (/^(?:true|false)$/i.test(value.trim()) ||
|
|
702
|
+
isPlaceholderOnly(value) ||
|
|
703
|
+
isValidationRules(value) ||
|
|
704
|
+
// Laravel のモデルの型変換('password' => 'hashed')
|
|
705
|
+
/^(?:hashed|encrypted)$/.test(value));
|
|
706
|
+
}
|
|
707
|
+
/** 入力の検証の規則の名前(Laravel など) */
|
|
708
|
+
const VALIDATION_RULE = /^(?:bail|required|nullable|sometimes|present|filled|confirmed|string|integer|numeric|alpha|alpha_num|alpha_dash|ascii|email|boolean|uuid|min|max|between|size|digits|digits_between|regex|not_regex|same|different|current_password|password|letters|mixed_case|numbers|symbols|uncompromised|required_with|required_if|required_unless|exclude|prohibited)(?::[^|\r\n]*)?$/;
|
|
709
|
+
/**
|
|
710
|
+
* 入力の検証の規則だけでできた値(v0.19.0。Laravel などの 'password' => 'required|string|min:8|confirmed')。秘密の値では
|
|
711
|
+
* ない。規則が 1 つだけの値は、パスワードにはまず使わない名前(required / nullable / sometimes / confirmed)だけ
|
|
712
|
+
*/
|
|
713
|
+
function isValidationRules(value) {
|
|
714
|
+
const rules = value.split("|");
|
|
715
|
+
return rules.length > 1
|
|
716
|
+
? rules.every((rule) => VALIDATION_RULE.test(rule))
|
|
717
|
+
: /^(?:required|nullable|sometimes|confirmed)$/.test(value);
|
|
526
718
|
}
|
|
527
719
|
/**
|
|
528
720
|
* 書式の差し込み(%s / {} / {0} / {1,-8:D} / {:.2f} / ${x})だけでできた値('%s:%s' など)。秘密ではないため伏せない。
|
|
@@ -721,6 +913,65 @@ function isPartlyMasked(token) {
|
|
|
721
913
|
}
|
|
722
914
|
/** PRIVATE KEY ブロック(BEGIN/END 行は残し中身をマスク) */
|
|
723
915
|
const PRIVATE_KEY_BLOCK = /(-----BEGIN [A-Z ]*PRIVATE KEY-----)[\s\S]+?(-----END [A-Z ]*PRIVATE KEY-----)/g;
|
|
916
|
+
/**
|
|
917
|
+
* SQL*Plus / RMAN のスクリプトの CONNECT 行(v0.19.0): CONNECT ユーザー/パスワード[@接続先] [AS SYSDBA] / CONN ... /
|
|
918
|
+
* CONNECT TARGET ...。行がその文だけのもの(「Connect to/from the server」のような文章を読まない)
|
|
919
|
+
*/
|
|
920
|
+
const ORACLE_CONNECT = new RegExp(String.raw `^([ \t]*conn(?:ect)?[ \t]+(?:(?:target|catalog|auxiliary)[ \t]+)?["']?${ORACLE_USER}\/)` +
|
|
921
|
+
String.raw `("[^"\r\n]*"|[^\s"'@\/;]+)` +
|
|
922
|
+
String.raw `(?=(?:@[^\s;"']+)?["']?(?:[ \t]+as[ \t]+sys\w+)?[ \t]*;?[ \t]*(?:--[^\r\n]*)?\r?$)`, "gim");
|
|
923
|
+
/**
|
|
924
|
+
* SQL のパスワードの句(v0.19.0): Oracle / MySQL の IDENTIFIED BY 値(IDENTIFIED WITH 方式 BY 値・
|
|
925
|
+
* IDENTIFIED BY VALUES 'ハッシュ' も)と、PostgreSQL の [WITH | LOGIN | USER 名 | ROLE 名] [ENCRYPTED] PASSWORD '値'。
|
|
926
|
+
* VB / Java などの文字列の中の SQL も読む(値は文字列を閉じる引用符の前まで)
|
|
927
|
+
*/
|
|
928
|
+
const SQL_IDENTIFIED_BY = /\b(IDENTIFIED(?:[ \t]+WITH[ \t]+[\w$]+)?[ \t]+BY[ \t]+(?:VALUES[ \t]+)?)('(?:[^'\r\n]|'')*'|"[^"\r\n]*"|[^\s;'",)]+)/gi;
|
|
929
|
+
/**
|
|
930
|
+
* IDENTIFIED BY の前のユーザー・ロールの名前(CREATE USER 名 / ALTER ROLE 名 / GRANT ... TO 名 / CONNECT TO 名 /
|
|
931
|
+
* MySQL の 'u'@'h')。小文字の identified by はこれが前にあるときだけ SQL とみなす(文章の「identified by a single
|
|
932
|
+
* character」を読まない)。大文字の IDENTIFIED BY は前を問わない(VB の "CREATE USER " & u & " IDENTIFIED BY ..." も)
|
|
933
|
+
*/
|
|
934
|
+
const SQL_GRANTEE_BEFORE = /\b(?:user|role|to)[ \t]+(?:if[ \t]+(?:not[ \t]+)?exists[ \t]+)?(?:"[^"\r\n]+"|'[^'\r\n]+'(?:@'[^'\r\n]*')?|`[^`\r\n]+`(?:@`[^`\r\n]*`)?|[\w$#.]+(?:@[\w%.]+)?)[ \t]+$/i;
|
|
935
|
+
const SQL_PASSWORD = /\b((?:WITH|LOGIN|USER[ \t]+[\w$."`]+|ROLE[ \t]+[\w$."`]+)(?:[ \t]+(?:LOGIN|NOLOGIN|SUPERUSER|NOSUPERUSER|CREATEDB|CREATEROLE|INHERIT|NOINHERIT|REPLICATION))*[ \t]+(?:ENCRYPTED[ \t]+)?PASSWORD[ \t]+)('(?:[^'\r\n]|'')*')/gi;
|
|
936
|
+
/**
|
|
937
|
+
* SQL のパスワードの句の値のうち伏せないもの: 変数・差し込み・バインド変数(&pw / :pw / ? / %s / {0} / ${x})・
|
|
938
|
+
* 説明の書き方(<password> / [password] / password)・コードの連結(' + pw + ' / " & pw & ")
|
|
939
|
+
*/
|
|
940
|
+
function isSqlNonSecret(value) {
|
|
941
|
+
const quote = /^['"]/.test(value) && value.length >= 2 && value.endsWith(value.charAt(0)) ? value.charAt(0) : "";
|
|
942
|
+
const inner = quote === "" ? value : value.slice(1, -1);
|
|
943
|
+
return (isCliNonSecret(value) ||
|
|
944
|
+
/^(?::[A-Za-z_]\w*|\?|&\w+\.?|@\w+)$/.test(inner) ||
|
|
945
|
+
/^(?:password|passwd|pwd|pass|new_password|newpassword)$/i.test(inner) ||
|
|
946
|
+
(quote !== "" && /["'`]/.test(inner)));
|
|
947
|
+
}
|
|
948
|
+
/** Oracle の CONNECT 行と SQL のパスワードの句の値を伏せる(VB のソースと汎用テキストの両方) */
|
|
949
|
+
function maskSqlCredentials(source, findings) {
|
|
950
|
+
let result = source.replace(ORACLE_CONNECT, (whole, lead, value, offset) => {
|
|
951
|
+
if (isCliNonSecret(value) || /^&/.test(value))
|
|
952
|
+
return whole;
|
|
953
|
+
findings.push({ line: lineOf(source, offset), kind: KIND_PASSWORD });
|
|
954
|
+
const quote = /^"/.test(value) ? '"' : "";
|
|
955
|
+
return `${lead}${quote}${MASK}${quote}`;
|
|
956
|
+
});
|
|
957
|
+
for (const pattern of [SQL_IDENTIFIED_BY, SQL_PASSWORD]) {
|
|
958
|
+
const before = result;
|
|
959
|
+
result = before.replace(pattern, (whole, lead, value, offset) => {
|
|
960
|
+
if (value.includes(MASK) || isSqlNonSecret(value))
|
|
961
|
+
return whole;
|
|
962
|
+
if (pattern === SQL_IDENTIFIED_BY && !lead.startsWith("IDENTIFIED")) {
|
|
963
|
+
// 行の頭から(長い行は直前の 300 文字)。行の頭は lastIndexOf で探す(文章に多いときに遅くならないように)
|
|
964
|
+
const lineStart = Math.max(before.lastIndexOf("\n", offset - 1) + 1, offset - 300, 0);
|
|
965
|
+
if (!SQL_GRANTEE_BEFORE.test(before.slice(lineStart, offset)))
|
|
966
|
+
return whole;
|
|
967
|
+
}
|
|
968
|
+
findings.push({ line: lineOf(before, offset), kind: KIND_PASSWORD });
|
|
969
|
+
const quote = /^['"]/.test(value) && value.length >= 2 ? value.charAt(0) : "";
|
|
970
|
+
return `${lead}${quote}${MASK}${quote}`;
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
return result;
|
|
974
|
+
}
|
|
724
975
|
/**
|
|
725
976
|
* 高エントロピー文字列の候補(英数と base64/URL-safe 記号の 20 文字以上)。
|
|
726
977
|
* 判定は looksHighEntropy で絞る
|
|
@@ -1105,7 +1356,7 @@ function maskElementText(value) {
|
|
|
1105
1356
|
return `${lead}${MASK}${value.slice(lead.length + inner.length)}`;
|
|
1106
1357
|
}
|
|
1107
1358
|
/** 非 VB ファイル(config / XML / テキスト等)のマスク */
|
|
1108
|
-
function maskGenericText(content, findings, strict) {
|
|
1359
|
+
function maskGenericText(content, findings, strict, colonPairs = true) {
|
|
1109
1360
|
// .NET の設定ファイルの appSettings / My.Settings(キー名と値が別の属性・要素にある)
|
|
1110
1361
|
let result = maskConfigAdds(content, findings, (index) => lineOf(content, index));
|
|
1111
1362
|
result = result.replace(SETTING_VALUE, (whole, open, middle, value, close, offset) => {
|
|
@@ -1192,6 +1443,10 @@ function maskGenericText(content, findings, strict) {
|
|
|
1192
1443
|
const shown = quoted ? `${quote}${MASK}${quote}` : MASK;
|
|
1193
1444
|
return `${lead}${key}${eq}${rest.slice(0, at)}${shown}${rest.slice(at + value.length)}${closing}`;
|
|
1194
1445
|
});
|
|
1446
|
+
// YAML・.properties・setup.cfg などの引用符で囲まない `キー: 値`(コードのファイルでは読まない)
|
|
1447
|
+
if (colonPairs) {
|
|
1448
|
+
result = maskColonPairs(result, findings);
|
|
1449
|
+
}
|
|
1195
1450
|
// バッチファイルの set(値の空白も値のうちなので表示の文言とはみなさない)。SQL の SET を飛ばしたときと、文字列・
|
|
1196
1451
|
// 括弧の中で値を途中で終えたときは、その後ろから続けて探す(同じ行の後ろの set も読む)
|
|
1197
1452
|
{
|
|
@@ -1307,6 +1562,19 @@ function maskGenericText(content, findings, strict) {
|
|
|
1307
1562
|
};
|
|
1308
1563
|
// キーと文字列の値("password": "..." / dbPassword = "..." / { apiKey: '...' } / password: string = "...")
|
|
1309
1564
|
result = result.replace(KEY_LITERAL, maskKeyLiteral);
|
|
1565
|
+
// 添字への代入と、秘密の名前を最初の引数に渡す関数の 2 番目の文字列(型の名前・表示の文言は除く)
|
|
1566
|
+
for (const pattern of [SUBSCRIPT_LITERAL, NAMED_ARG_LITERAL]) {
|
|
1567
|
+
result = result.replace(pattern, (whole, open, key, sep, literal, offset) => {
|
|
1568
|
+
const prefix = /^[^"']*/.exec(literal)?.[0] ?? "";
|
|
1569
|
+
const quote = literal.charAt(prefix.length);
|
|
1570
|
+
const inner = literal.slice(prefix.length + 1, -1);
|
|
1571
|
+
if (!isSecretPair(key.slice(1, -1), inner) || isTypeName(inner)) {
|
|
1572
|
+
return whole;
|
|
1573
|
+
}
|
|
1574
|
+
findings.push({ line: lineOf(result, offset), kind: KIND_PASSWORD });
|
|
1575
|
+
return `${open}${key}${sep}${prefix}${quote}${MASK}${quote}`;
|
|
1576
|
+
});
|
|
1577
|
+
}
|
|
1310
1578
|
// : の後に空白のない注釈は、token などのキーでは型が文字列のときだけ(last_synced_token:label="..." は書式指定)
|
|
1311
1579
|
result = result.replace(KEY_LITERAL_TYPED, (whole, key, sep, literal, offset) => /:[^ \t]/.test(sep) && !hasStrongSecretWord(key) && !/:(?:str|string|String|bytes|SecretStr|Optional\b)/.test(sep)
|
|
1312
1580
|
? whole
|
|
@@ -1328,11 +1596,13 @@ export function maskCredentials(content, options) {
|
|
|
1328
1596
|
const strict = options.strict ?? true;
|
|
1329
1597
|
let result = options.vbSource
|
|
1330
1598
|
? maskVbSource(content, findings, strict)
|
|
1331
|
-
: maskGenericText(content, findings, strict);
|
|
1599
|
+
: maskGenericText(content, findings, strict, options.path === undefined || !isCodePath(options.path));
|
|
1332
1600
|
if (options.vbSource) {
|
|
1333
1601
|
// VB の文字列の中のコマンド(Shell("net use ...") / Process.Start("sqlcmd.exe", "-S srv -P ..."))
|
|
1334
1602
|
result = maskCliArgs(result, findings);
|
|
1335
1603
|
}
|
|
1604
|
+
// SQL*Plus の CONNECT 行・SQL の IDENTIFIED BY / PASSWORD の句(スクリプトとコードの文字列の中)
|
|
1605
|
+
result = maskSqlCredentials(result, findings);
|
|
1336
1606
|
// ファイル種別によらない汎用シークレット形式
|
|
1337
1607
|
result = result.replace(PRIVATE_KEY_BLOCK, (whole, begin, end, offset) => {
|
|
1338
1608
|
findings.push({ line: lineOf(result, offset), kind: KIND_PRIVATE_KEY });
|
|
@@ -1479,11 +1749,11 @@ export function hasMaskToken(line) {
|
|
|
1479
1749
|
*/
|
|
1480
1750
|
function maskModes(path, stricts) {
|
|
1481
1751
|
const vbs = /\.vb$/i.test(path) ? [true, false] : [false];
|
|
1482
|
-
const modes = vbs.flatMap((vbSource) => stricts.map((strict) => ({ vbSource, strict })));
|
|
1752
|
+
const modes = vbs.flatMap((vbSource) => stricts.map((strict) => ({ vbSource, strict, path })));
|
|
1483
1753
|
// 言語の分かるソースは、言語ごとの伏せ方 (tazuna pack) と汎用テキストの伏せ方 (旧 slnmix のパック) の両方
|
|
1484
1754
|
const language = sourceLanguageOf(path);
|
|
1485
1755
|
if (language !== undefined) {
|
|
1486
|
-
modes.push(...stricts.map((strict) => ({ vbSource: false, strict, language })));
|
|
1756
|
+
modes.push(...stricts.map((strict) => ({ vbSource: false, strict, language, path })));
|
|
1487
1757
|
}
|
|
1488
1758
|
return modes;
|
|
1489
1759
|
}
|
|
@@ -1598,7 +1868,9 @@ function displaySpans(text, options) {
|
|
|
1598
1868
|
// strict のときは両方の範囲を伏せる
|
|
1599
1869
|
const stricts = (options.strict ?? true) ? [true, false] : [false];
|
|
1600
1870
|
const vbSource = options.vbSource;
|
|
1601
|
-
const modes = vbSource === undefined
|
|
1871
|
+
const modes = vbSource === undefined
|
|
1872
|
+
? maskModes(options.path, stricts)
|
|
1873
|
+
: stricts.map((strict) => ({ vbSource, strict, path: options.path }));
|
|
1602
1874
|
for (const mode of modes) {
|
|
1603
1875
|
const spans = maskedSpans(text, mode);
|
|
1604
1876
|
if (spans === null)
|
|
@@ -165,7 +165,12 @@ function buildUiSummaryEntry(node, displayPath, deps, maskEnabled, strictMask) {
|
|
|
165
165
|
// C# の Designer.cs はパックの .cs と同じく、文字列・コメントの中だけを伏せる
|
|
166
166
|
const masked = language === "vb"
|
|
167
167
|
? maskCredentials(source, { vbSource: true, strict: strictMask })
|
|
168
|
-
: maskCredentials(source, {
|
|
168
|
+
: maskCredentials(source, {
|
|
169
|
+
vbSource: false,
|
|
170
|
+
language: sourceLanguageOf(fileName),
|
|
171
|
+
strict: strictMask,
|
|
172
|
+
path: fileName,
|
|
173
|
+
});
|
|
169
174
|
source = masked.content;
|
|
170
175
|
findings = masked.findings;
|
|
171
176
|
}
|
|
@@ -387,6 +392,7 @@ export function buildRepomixOutput(title, sources, deps, options) {
|
|
|
387
392
|
vbSource: /\.vb$/i.test(displayPath),
|
|
388
393
|
language: sourceLanguageOf(displayPath),
|
|
389
394
|
strict: strictMask,
|
|
395
|
+
path: displayPath,
|
|
390
396
|
});
|
|
391
397
|
content = masked.content;
|
|
392
398
|
if (masked.findings.length > 0) {
|
|
@@ -524,6 +530,7 @@ export function buildRepomixOutput(title, sources, deps, options) {
|
|
|
524
530
|
vbSource: false,
|
|
525
531
|
language: sourceLanguageOf(file.relativePath),
|
|
526
532
|
strict: strictMask,
|
|
533
|
+
path: file.relativePath,
|
|
527
534
|
});
|
|
528
535
|
content = masked.content;
|
|
529
536
|
if (masked.findings.length > 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tazuna",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Build with AI chat, without handing over the reins: pack your codebase for the chat, then verify and apply its patches locally (zero dependencies; formerly petari and slnmix)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|