tazuna 0.19.0 → 0.20.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 +521 -11
- package/package.json +1 -1
package/dist/core/mask.js
CHANGED
|
@@ -390,10 +390,11 @@ function maskColonPairs(source, findings) {
|
|
|
390
390
|
const BATCH_SET = /(?<=^|[ \t@(&|;"'>])([Ss][Ee][Tt][ \t]+)(\\"|""|"|")?([A-Za-z0-9_.-]+)(=)/gm;
|
|
391
391
|
/**
|
|
392
392
|
* パスワードを引数で渡すコマンドの名前(sqlcmd / osql / isql / bcp の -P、mysql 系の -p... / --password=、
|
|
393
|
-
* net use の共有の後の引数、schtasks の /RP・/P
|
|
393
|
+
* net use の共有の後の引数、schtasks の /RP・/P。v0.20.0 から curl の -u ユーザー:パスワード・PowerShell の
|
|
394
|
+
* Invoke-Sqlcmd の -Password・sqlcmd の /P も)。パスの途中の語・別の拡張子のファイル名
|
|
394
395
|
* (/var/lib/mysql/・mysql.py・MySql.Data)は除く。MSBuild の "...\SQLCMD.EXE" と %SQLCMD% も読む
|
|
395
396
|
*/
|
|
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;
|
|
397
|
+
const CLI_COMMAND = /(?<![\w.-])(sqlcmd|osql|isql|bcp|mysql|mysqldump|mysqladmin|mysqlimport|net(?:\.exe)?[ \t]+use|schtasks|sqlplus|exp|imp|expdp|impdp|sqlldr|dgmgrl|rman|curl|invoke-sqlcmd)(?:\.exe)?(?=["'\s,\]%!]|&(?:quot|apos);|$)/gi;
|
|
397
398
|
/** 引数の区切りの空白(行の継続(バッチの ^ / シェルの \ の後の改行)も) */
|
|
398
399
|
const CLI_SP = String.raw `(?:[ \t]|\^\r?\n|(?<=[ \t])\\\r?\n)+`;
|
|
399
400
|
/** 引用符で囲まない値の文字(行の継続の ^ / \ は値に含めない) */
|
|
@@ -422,6 +423,8 @@ const CLI_ARGS = [
|
|
|
422
423
|
/((?<=[\s'\[,])-P'[ \t]*,[ \t]*')([^'\r\n]*)/g,
|
|
423
424
|
new RegExp(String.raw `((?<=[\s;])-P)(${CLI_QUOTED})`, "g"),
|
|
424
425
|
new RegExp(String.raw `((?<=[\s"';])-P)(${CLI_BARE(",\\]")})`, "g"),
|
|
426
|
+
// Windows の / の形(sqlcmd /U sa /P value。v0.20.0)
|
|
427
|
+
new RegExp(String.raw `((?<=[\s"'])\/P${CLI_SP})(${CLI_VALUE})`, "g"),
|
|
425
428
|
],
|
|
426
429
|
],
|
|
427
430
|
[
|
|
@@ -434,10 +437,10 @@ const CLI_ARGS = [
|
|
|
434
437
|
// mysqladmin password 新しいパスワード
|
|
435
438
|
[/^mysqladmin$/i, [new RegExp(String.raw `((?<=\s)password${CLI_SP})(${CLI_VALUE})`, "g")]],
|
|
436
439
|
[
|
|
437
|
-
/^net[ \t]+use$/i,
|
|
440
|
+
/^net(?:\.exe)?[ \t]+use$/i,
|
|
438
441
|
[
|
|
439
|
-
// net use [Z: | *] \\srv\share [/user:x ...] パスワード
|
|
440
|
-
new RegExp(String.raw `(^net[ \t]+use(?:${CLI_SP}(?:[A-Za-z]:|\*))?${CLI_SP}(?:"\\\\[^"\r\n]*"|"\\\\(?:(?!")[^\r\n])*"|\\\\[^\s"` +
|
|
442
|
+
// net use [Z: | *] \\srv\share [/user:x ...] パスワード(net.exe use も)
|
|
443
|
+
new RegExp(String.raw `(^net(?:\.exe)?[ \t]+use(?:${CLI_SP}(?:[A-Za-z]:|\*))?${CLI_SP}(?:"\\\\[^"\r\n]*"|"\\\\(?:(?!")[^\r\n])*"|\\\\[^\s"` +
|
|
441
444
|
"`" +
|
|
442
445
|
String.raw `]+)(?:${CLI_SP}\/[A-Za-z]+(?::(?:"[^"\r\n]*"|[^\s"]*))?)*${CLI_SP})(?![\/*])(${CLI_VALUE})`, "i"),
|
|
443
446
|
],
|
|
@@ -458,6 +461,13 @@ const CLI_ARGS = [
|
|
|
458
461
|
new RegExp(String.raw `((?<=\s)(?:target|catalog|auxiliary)(?:${CLI_SP}|=)["']?${ORACLE_USER}\/)(${ORACLE_PASSWORD})`, "gi"),
|
|
459
462
|
],
|
|
460
463
|
],
|
|
464
|
+
// curl の -u / --user / --proxy-user / -U の ユーザー:パスワード(v0.20.0。パスワードの無い -u user は除く)
|
|
465
|
+
[
|
|
466
|
+
/^curl$/i,
|
|
467
|
+
[new RegExp(String.raw `((?<=[\s"'])(?:-u|-U|--user|--proxy-user)(?:${CLI_SP}|=)?["']?[^\s:"']*:)([^\s"']+)`, "g")],
|
|
468
|
+
],
|
|
469
|
+
// PowerShell の Invoke-Sqlcmd -Password 値(v0.20.0。$ で始まる変数・式は除く)
|
|
470
|
+
[/^invoke-sqlcmd$/i, [new RegExp(String.raw `((?<=\s)-Password(?:${CLI_SP}|:)(?![$(@]))(${CLI_VALUE})`, "gi")]],
|
|
461
471
|
];
|
|
462
472
|
/** コマンド名のない引数の文字列(ProcessStartInfo.Arguments = "-S srv -U sa -P ...")の -U ユーザー -P パスワード */
|
|
463
473
|
const CLI_USER_PASSWORD = new RegExp(String.raw `((?<=[\s"'])-U[ \t]*(?:${CLI_QUOTED}|[^\s"'` + "`" + String.raw `]+)[ \t]+-P[ \t]*)(${CLI_VALUE})`, "g");
|
|
@@ -556,7 +566,7 @@ function maskCliArgs(source, findings) {
|
|
|
556
566
|
}
|
|
557
567
|
for (const [kind, at] of firsts) {
|
|
558
568
|
const tail = segment.slice(at);
|
|
559
|
-
if (kind === 0 && !/(?<=[\s"'\[,])-U(?!-)/.test(tail)) {
|
|
569
|
+
if (kind === 0 && !/(?<=[\s"'\[,])-U(?!-)|(?<=[\s"'])\/U(?=[ \t])/.test(tail)) {
|
|
560
570
|
continue;
|
|
561
571
|
}
|
|
562
572
|
for (const pattern of CLI_ARGS[kind]?.[1] ?? []) {
|
|
@@ -619,6 +629,77 @@ function maskCliArgs(source, findings) {
|
|
|
619
629
|
}
|
|
620
630
|
return out + source.slice(last);
|
|
621
631
|
}
|
|
632
|
+
/** PowerShell の ConvertTo-SecureString(v0.20.0) */
|
|
633
|
+
const SECURE_STRING = /(?<![\w-])ConvertTo-SecureString(?![\w-])/gi;
|
|
634
|
+
/** その引数(-名前[:値] / 文字列 / 引用符で囲まない語 / 閉じ括弧) */
|
|
635
|
+
const PS_TOKEN = /(-[A-Za-z]+)(?::(\S+))?|("(?:[^"`\r\n]|`.)*"|'(?:[^'\r\n]|'')*'|[^\s"'()]+)|(\))/g;
|
|
636
|
+
/** パイプで渡す文字列("..." | ConvertTo-SecureString -AsPlainText) */
|
|
637
|
+
const SECURE_STRING_PIPED = /("(?:[^"`\r\n]|`.)*"|'(?:[^'\r\n]|'')*')([ \t]*\|[ \t]*)(?=ConvertTo-SecureString\b)/gi;
|
|
638
|
+
/**
|
|
639
|
+
* PowerShell の ConvertTo-SecureString -AsPlainText の平文(-String の値か最初の位置の引数、パイプで渡す前の文字列)を
|
|
640
|
+
* 伏せる。-AsPlainText の無いもの(暗号化した文字列を戻す使い方)と、変数・式($pw / $(...) / (Read-Host))は伏せない
|
|
641
|
+
*/
|
|
642
|
+
function maskSecureStrings(source, findings) {
|
|
643
|
+
const spans = [];
|
|
644
|
+
const add = (value, at) => {
|
|
645
|
+
const quote = /^["']/.test(value) && value.length >= 2 ? value.charAt(0) : "";
|
|
646
|
+
const inner = quote === "" ? value : value.slice(1, -1);
|
|
647
|
+
// 引用符で囲まない英字だけの語は説明の文章(ConvertTo-SecureString with -AsPlainText ...)のことが多いので除く
|
|
648
|
+
if (inner.trim() === "" || inner === MASK || /^[$(@]/.test(inner) || isCliNonSecret(value) || (quote === "" && /^[A-Za-z]+$/.test(inner)))
|
|
649
|
+
return;
|
|
650
|
+
spans.push({ start: at + quote.length, end: at + quote.length + inner.length });
|
|
651
|
+
};
|
|
652
|
+
for (const m of source.matchAll(SECURE_STRING)) {
|
|
653
|
+
const from = (m.index ?? 0) + m[0].length;
|
|
654
|
+
const end = cliCommandEnd(source, from);
|
|
655
|
+
const args = source.slice(from, end);
|
|
656
|
+
if (!/(?<![\w-])-AsPlainText(?![\w-])/i.test(args))
|
|
657
|
+
continue;
|
|
658
|
+
let skip = false;
|
|
659
|
+
for (const t of args.matchAll(PS_TOKEN)) {
|
|
660
|
+
const at = from + (t.index ?? 0);
|
|
661
|
+
if (t[4] !== undefined)
|
|
662
|
+
break;
|
|
663
|
+
if (t[1] !== undefined) {
|
|
664
|
+
const name = t[1].toLowerCase();
|
|
665
|
+
if (name === "-string") {
|
|
666
|
+
if (t[2] !== undefined) {
|
|
667
|
+
add(t[2], at + t[1].length + 1);
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
else if (name === "-key" || name === "-securekey") {
|
|
672
|
+
skip = t[2] === undefined;
|
|
673
|
+
}
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
if (skip) {
|
|
677
|
+
skip = false;
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
// -String の値か、最初の位置の引数
|
|
681
|
+
add(t[3] ?? "", at);
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
for (const m of source.matchAll(SECURE_STRING_PIPED)) {
|
|
686
|
+
const after = source.slice((m.index ?? 0) + m[0].length, cliCommandEnd(source, (m.index ?? 0) + m[0].length));
|
|
687
|
+
if (/(?<![\w-])-AsPlainText(?![\w-])/i.test(after))
|
|
688
|
+
add(m[1] ?? "", m.index ?? 0);
|
|
689
|
+
}
|
|
690
|
+
if (spans.length === 0)
|
|
691
|
+
return source;
|
|
692
|
+
let out = "";
|
|
693
|
+
let last = 0;
|
|
694
|
+
for (const span of spans.sort((x, y) => x.start - y.start)) {
|
|
695
|
+
if (span.start < last)
|
|
696
|
+
continue;
|
|
697
|
+
findings.push({ line: lineOf(source, span.start), kind: KIND_PASSWORD });
|
|
698
|
+
out += source.slice(last, span.start) + MASK;
|
|
699
|
+
last = span.end;
|
|
700
|
+
}
|
|
701
|
+
return out + source.slice(last);
|
|
702
|
+
}
|
|
622
703
|
/**
|
|
623
704
|
* SQL の SET col=... の値がバインド変数(`:LOGIN_PASSWORD` / `@p1` / `$1` / `?` / `%s`)か。名前が列名と同じもの、
|
|
624
705
|
* 後ろに , / WHERE が続くもの、前の行に UPDATE があるものだけ(バッチの set ADMIN_PASSWORD=@admin は値として伏せる)
|
|
@@ -640,8 +721,13 @@ function isBindMarkerFor(key, after, before) {
|
|
|
640
721
|
}
|
|
641
722
|
/** コマンドの引数の環境変数(docker run -e DB_PASSWORD=... / --env "DB_PASSWORD=...") */
|
|
642
723
|
const SHELL_ENV_ARG = /(?<=[ \t])((?:-e|--env)(?:[ \t]+|=))("(?:[^"\\\r\n]|\\.)*"|"[^"\r\n]*"|'[^'\r\n]*'|[A-Za-z_][A-Za-z0-9_]*=(?:"(?:[^"\\\r\n]|\\.)*"|"[^"\r\n]*"|'[^'\r\n]*'|(?:\\[^\r\n]|[^\s"'\\])*))/g;
|
|
643
|
-
/**
|
|
644
|
-
|
|
724
|
+
/**
|
|
725
|
+
* キーの値の文字列(C# の @"..." / $"..." / $@"..."、Python の u"..." / r'...' / f"..." / b"..." なども)。
|
|
726
|
+
* JS のテンプレート文字列・Go の生の文字列(`...`)は差し込み(${...})のない 1 行のものだけ(v0.20.0)
|
|
727
|
+
*/
|
|
728
|
+
const KEY_VALUE = String.raw `((?:\$?@|@\$)"(?:[^"\r\n]|"")*"|(?:\$|[rRuUbBfF]{1,2})?"(?:[^"\\\r\n]|\\.)*"|(?:[rRuUbBfF]{1,2})?'(?:[^'\\\r\n]|\\.)*'|` + "`" + String.raw `(?:[^` + "`" + String.raw `\\\r\n$]|\\.|\$(?!\{))*` + "`" + ")";
|
|
729
|
+
/** KEY_VALUE の文字列の前の接頭辞(@ / $ / r / u / b / f)。引用符は含まない */
|
|
730
|
+
const LITERAL_PREFIX = /^[^"'`]*/;
|
|
645
731
|
/** 型の注釈の型(string / Optional[str] / Map<K, V> / string | null) */
|
|
646
732
|
const KEY_TYPE = String.raw `[A-Za-z_$][\w$.]*(?:<[^<>\r\n]*>|\[[^\[\]\r\n]*\])*\??`;
|
|
647
733
|
/**
|
|
@@ -676,6 +762,381 @@ const NAMED_ARG_LITERAL = new RegExp(String.raw `(\([ \t]*)("[A-Za-z_][\w.-]*"|'
|
|
|
676
762
|
const KEY_LITERAL_TYPED = new RegExp(String.raw `((?<![A-Za-z0-9_$.])[A-Za-z_$][A-Za-z0-9_$.]*)` +
|
|
677
763
|
String.raw `(\s*:[ \t]*${KEY_TYPE}(?:[ \t]*\|[ \t]*${KEY_TYPE})*[ \t]*=(?!=)\s*)` +
|
|
678
764
|
KEY_VALUE, "g");
|
|
765
|
+
// ---------------------------------------------------------------------------
|
|
766
|
+
// コードの形 (v0.20.0)。VB は maskVbSource が代入・比較・秘密の名前の関数の引数を読む。ほかの言語にも同じ形を
|
|
767
|
+
// 汎用テキストの規則として足す (言語の分かるソースは maskLanguageSource が文字列の中の部分だけを残す)
|
|
768
|
+
// ---------------------------------------------------------------------------
|
|
769
|
+
/**
|
|
770
|
+
* 秘密の名前のメソッドに文字列を 1 つだけ渡す呼び出し(setter・builder: ds.setPassword("...") / .password("...") /
|
|
771
|
+
* SetPassword("...") / withPassword("...") / user.set_password("...") / setApiKey("..."))。名前の判定は secretSetterKey
|
|
772
|
+
*/
|
|
773
|
+
const SECRET_SETTER = new RegExp(String.raw `((?<![A-Za-z0-9_$])([A-Za-z_$][A-Za-z0-9_$]*)[ \t]*\([ \t]*)` + KEY_VALUE + String.raw `(?=[ \t]*\))`, "g");
|
|
774
|
+
/** setter の名前の前の動詞(React のフックの use... は名前を受け取ることが多いので入れない) */
|
|
775
|
+
const SETTER_VERBS = new Set(["set", "with"]);
|
|
776
|
+
/**
|
|
777
|
+
* setter・builder の名前から値のキーを返す(秘密系でなければ undefined)。set / with の後に秘密系の名前が続くもの
|
|
778
|
+
* (setPassword / withApiKey / set_db_password)と、名前そのものが秘密系の語のもの(password / apiKey / secret / token)
|
|
779
|
+
* だけ。validatePassword / hashPassword / getPassword のような動作の名前と、テストの t.pass("...") は除く
|
|
780
|
+
*/
|
|
781
|
+
function secretSetterKey(callee) {
|
|
782
|
+
const words = keyWords(callee);
|
|
783
|
+
const first = words[0] ?? "";
|
|
784
|
+
if (SETTER_VERBS.has(first) && words.length >= 2) {
|
|
785
|
+
const key = words.slice(1).join("_");
|
|
786
|
+
return kindForConfigKey(key) === KIND_PASSWORD ? key : undefined;
|
|
787
|
+
}
|
|
788
|
+
const whole = words.join("");
|
|
789
|
+
const named = words.length === 1 ? whole !== "pass" && SECRET_KEY_WORDS.has(whole) : words.length === 2 && SECRET_KEY_WORDS.has(whole);
|
|
790
|
+
return named ? callee : undefined;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* 既定値の演算子の後の文字列(環境変数が無いときの既定値: process.env.DB_PASSWORD || "..." / ?? "..." /
|
|
794
|
+
* Python の os.getenv("DB_PASSWORD") or "..." / Kotlin・PHP の ?: "...")。演算子の前の値か代入の先の名前で判定する
|
|
795
|
+
* (defaultValueKeys)。?: は前に空白のあるものだけ(TS の省略可能なプロパティ password?: "a" | "b" を除く)
|
|
796
|
+
*/
|
|
797
|
+
const DEFAULT_LITERAL = new RegExp(String.raw `(\|\||\?\?|(?<=[ \t])\?:|(?<![\w$.])or(?![\w$]))([ \t]*)` + KEY_VALUE, "g");
|
|
798
|
+
/** 既定値の式の代入の先・プロパティのキー(password = / const password: string = / password := / password: / 'password' =>) */
|
|
799
|
+
const DEFAULT_TARGET = /(?:^|[^\w$.])([A-Za-z_$][\w$.]*|"[^"\r\n]*"|'[^'\r\n]*')[ \t]*(?:(?::[ \t]*[\w$.<>\[\]|? ]{1,80})?[ \t]*:?=(?!=)|:(?!:)|=>)[ \t]*(?:await[ \t]+)?$/;
|
|
800
|
+
/** close の位置の閉じ括弧に対応する開き括弧の位置(文字列の中の括弧は数えない)。無ければ -1 */
|
|
801
|
+
function openingBracket(text, close) {
|
|
802
|
+
let depth = 0;
|
|
803
|
+
for (let i = close; i >= 0; i--) {
|
|
804
|
+
const ch = text.charAt(i);
|
|
805
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
806
|
+
// 文字列の始まりの引用符まで戻る(\ の後の引用符は文字列の中)
|
|
807
|
+
let j = i - 1;
|
|
808
|
+
while (j >= 0 && !(text.charAt(j) === ch && text.charAt(j - 1) !== "\\"))
|
|
809
|
+
j -= 1;
|
|
810
|
+
if (j < 0)
|
|
811
|
+
return -1;
|
|
812
|
+
i = j;
|
|
813
|
+
}
|
|
814
|
+
else if (ch === ")" || ch === "]") {
|
|
815
|
+
depth += 1;
|
|
816
|
+
}
|
|
817
|
+
else if (ch === "(" || ch === "[") {
|
|
818
|
+
depth -= 1;
|
|
819
|
+
if (depth === 0)
|
|
820
|
+
return i;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
return -1;
|
|
824
|
+
}
|
|
825
|
+
/** text の end の前で終わる値(識別子・メンバーの参照・呼び出し・添字の並び。os.getenv("X") / process.env.X)の始まり */
|
|
826
|
+
function operandStart(text, end) {
|
|
827
|
+
let i = end;
|
|
828
|
+
// TS の非 null 表明(process.env.X!)
|
|
829
|
+
if (text.charAt(i - 1) === "!")
|
|
830
|
+
i -= 1;
|
|
831
|
+
for (;;) {
|
|
832
|
+
const ch = text.charAt(i - 1);
|
|
833
|
+
if (ch === ")" || ch === "]") {
|
|
834
|
+
const open = openingBracket(text, i - 1);
|
|
835
|
+
if (open < 0)
|
|
836
|
+
break;
|
|
837
|
+
i = open;
|
|
838
|
+
}
|
|
839
|
+
else if (/[\w$]/.test(ch)) {
|
|
840
|
+
while (i > 0 && /[\w$]/.test(text.charAt(i - 1)))
|
|
841
|
+
i -= 1;
|
|
842
|
+
}
|
|
843
|
+
else {
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
// メンバーの参照(. / ?. / :: / ->)が前にあれば続けて読む
|
|
847
|
+
const access = /(?:\?\.|\.|::|->)$/.exec(text.slice(Math.max(0, i - 2), i));
|
|
848
|
+
if (access !== null && /[\w$)\]]/.test(text.charAt(i - access[0].length - 1))) {
|
|
849
|
+
i -= access[0].length;
|
|
850
|
+
continue;
|
|
851
|
+
}
|
|
852
|
+
// 呼び出し・添字の括弧の前の名前(getenv(...) / ENV[...])
|
|
853
|
+
if ((text.charAt(i) === "(" || text.charAt(i) === "[") && /[\w$)\]]/.test(text.charAt(i - 1)))
|
|
854
|
+
continue;
|
|
855
|
+
break;
|
|
856
|
+
}
|
|
857
|
+
return i;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* 値の式から、値のキーの候補を返す: 最後の名前(process.env.DB_PASSWORD / config.password)か、最後の括弧の中の
|
|
861
|
+
* キーの形の文字列(getenv("DB_PASSWORD") / ENV["DB_PASSWORD"] / config.get("db.password"))と呼び出しの名前(getPassword())
|
|
862
|
+
*/
|
|
863
|
+
function operandKeys(operand) {
|
|
864
|
+
const text = operand.replace(/!$/, "");
|
|
865
|
+
const last = /([A-Za-z_$][\w$]*)$/.exec(text);
|
|
866
|
+
if (last !== null)
|
|
867
|
+
return [last[1] ?? ""];
|
|
868
|
+
if (!/[)\]]$/.test(text))
|
|
869
|
+
return [];
|
|
870
|
+
const open = openingBracket(text, text.length - 1);
|
|
871
|
+
if (open < 0)
|
|
872
|
+
return [];
|
|
873
|
+
const keys = [...text.slice(open + 1, -1).matchAll(/["']([A-Za-z_][\w.:-]*)["']/g)].map((m) => m[1] ?? "");
|
|
874
|
+
const callee = /([A-Za-z_$][\w$]*)$/.exec(text.slice(0, open));
|
|
875
|
+
if (callee !== null)
|
|
876
|
+
keys.push(callee[1] ?? "");
|
|
877
|
+
return keys;
|
|
878
|
+
}
|
|
879
|
+
/** 既定値の演算子の前の値(続けて書いた演算子の前の値も)と代入の先から、値のキーの候補を集める */
|
|
880
|
+
function defaultValueKeys(line) {
|
|
881
|
+
const keys = [];
|
|
882
|
+
let end = line.length;
|
|
883
|
+
for (let guard = 0; guard < 8; guard++) {
|
|
884
|
+
while (end > 0 && /[ \t]/.test(line.charAt(end - 1)))
|
|
885
|
+
end -= 1;
|
|
886
|
+
const start = operandStart(line, end);
|
|
887
|
+
if (start === end)
|
|
888
|
+
break;
|
|
889
|
+
keys.push(...operandKeys(line.slice(start, end)));
|
|
890
|
+
end = start;
|
|
891
|
+
while (end > 0 && /[ \t]/.test(line.charAt(end - 1)))
|
|
892
|
+
end -= 1;
|
|
893
|
+
const op = /(?:\|\||\?\?|\?:|(?<![\w$.])or)$/.exec(line.slice(Math.max(0, end - 3), end));
|
|
894
|
+
if (op === null || (op[0] === "or" && /[\w$.]/.test(line.charAt(end - 3))))
|
|
895
|
+
break;
|
|
896
|
+
end -= op[0].length;
|
|
897
|
+
}
|
|
898
|
+
const target = DEFAULT_TARGET.exec(line.slice(0, end));
|
|
899
|
+
if (target !== null)
|
|
900
|
+
keys.push((target[1] ?? "").replace(/^["']|["']$/g, ""));
|
|
901
|
+
return keys;
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* 秘密の名前の値と文字列の比較(txtPassword.Text == "..." / password === '...' / "..." != pwd /
|
|
905
|
+
* password.equals("...") / "...".equals(password))。名前の後ろの .Text / .value / .getText() は除いて判定する(compareKey)
|
|
906
|
+
*/
|
|
907
|
+
const COMPARE_CHAIN = String.raw `[A-Za-z_$][\w$]*(?:(?:\?\.|\.)[A-Za-z_$][\w$]*(?:\(\))?)*`;
|
|
908
|
+
const COMPARE_LITERAL = new RegExp(String.raw `((?<![\w$.])(${COMPARE_CHAIN})[ \t]*(?:===?|!==?)[ \t]*)` + KEY_VALUE, "g");
|
|
909
|
+
const COMPARE_LITERAL_LEFT = new RegExp(KEY_VALUE + String.raw `([ \t]*(?:===?|!==?)[ \t]*(${COMPARE_CHAIN}))(?![\w$(.])`, "g");
|
|
910
|
+
const EQUALS_LITERAL = new RegExp(String.raw `((?<![\w$.])(${COMPARE_CHAIN})\.(?:equals|Equals|equalsIgnoreCase|contentEquals)\([ \t]*)` + KEY_VALUE + String.raw `(?=[ \t]*\))`, "g");
|
|
911
|
+
const EQUALS_LITERAL_LEFT = new RegExp(KEY_VALUE + String.raw `(\.(?:equals|Equals|equalsIgnoreCase)\([ \t]*(${COMPARE_CHAIN})[ \t]*\))`, "g");
|
|
912
|
+
/** 比べる値の名前(画面の部品の .Text / .value / .getText() などは除く) */
|
|
913
|
+
function compareKey(chain) {
|
|
914
|
+
const segments = chain.split(/\?\.|\./).map((segment) => segment.replace(/\(\)$/, ""));
|
|
915
|
+
while (segments.length > 1 && /^(?:text|value|gettext|getvalue|tostring|trim|strip)$/i.test(segments[segments.length - 1] ?? "")) {
|
|
916
|
+
segments.pop();
|
|
917
|
+
}
|
|
918
|
+
return segments.join(".");
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* パスワードを位置で渡す定番の関数(v0.20.0): [名前(修飾を含めた末尾)、引数の数からパスワードの引数の位置(0 始まり)]
|
|
922
|
+
*/
|
|
923
|
+
const POSITIONAL_SECRET_CALLS = [
|
|
924
|
+
// .NET: new NetworkCredential("user", "pw"[, "domain"]) / MailKit の client.Authenticate("user", "pw")
|
|
925
|
+
[/(?:^|\.)NetworkCredential$/, (n) => (n === 2 || n === 3 ? 1 : undefined)],
|
|
926
|
+
[/\.Authenticate(?:Async)?$/, (n) => (n === 2 ? 1 : undefined)],
|
|
927
|
+
// Java: DriverManager.getConnection(url, "user", "pw") / DataSource の getConnection("user", "pw") /
|
|
928
|
+
// JavaMail の new PasswordAuthentication("user", "pw".toCharArray()) / Spring Security・HttpClient の
|
|
929
|
+
// new UsernamePasswordAuthenticationToken("user", "pw") / new UsernamePasswordCredentials("user", "pw") /
|
|
930
|
+
// OkHttp の Credentials.basic("user", "pw")
|
|
931
|
+
[/(?:^|\.)getConnection$/, (n) => (n === 3 ? 2 : n === 2 ? 1 : undefined)],
|
|
932
|
+
[/(?:^|\.)PasswordAuthentication$/, (n) => (n === 2 ? 1 : undefined)],
|
|
933
|
+
[/(?:^|\.)UsernamePassword(?:AuthenticationToken|Credentials)$/, (n) => (n === 2 || n === 3 ? 1 : undefined)],
|
|
934
|
+
[/(?:^|\.)Credentials\.basic$/, (n) => (n === 2 || n === 3 ? 1 : undefined)],
|
|
935
|
+
// PHP: mysqli_connect("host", "user", "pw", "db") / new mysqli(...) / mysql_connect(...) / new PDO($dsn, "user", "pw")
|
|
936
|
+
[/^(?:mysqli_connect|mysql_connect|mysqli|PDO)$/, (n) => (n >= 3 ? 2 : undefined)],
|
|
937
|
+
// Python: MySQLdb.connect("host", "user", "pw", "db") / pymysql.connect(...)。Node: new Sequelize("db", "user", "pw", {...})
|
|
938
|
+
[/(?:^|\.)(?:MySQLdb|pymysql)\.connect$/, (n) => (n >= 3 ? 2 : undefined)],
|
|
939
|
+
[/(?:^|\.)Sequelize$/, (n) => (n === 3 || n === 4 ? 2 : undefined)],
|
|
940
|
+
];
|
|
941
|
+
const POSITIONAL_CALL_NAME = /(?<![\w$])(NetworkCredential|Authenticate(?:Async)?|getConnection|PasswordAuthentication|UsernamePassword(?:AuthenticationToken|Credentials)|basic|mysqli_connect|mysql_connect|mysqli|PDO|connect|Sequelize)[ \t]*\(/g;
|
|
942
|
+
/** 引数が文字列だけ(Java の "...".toCharArray() も)か */
|
|
943
|
+
const ARG_LITERAL = new RegExp(String.raw `^\s*` + KEY_VALUE + String.raw `(?:[ \t]*\.[ \t]*(?:toCharArray|ToCharArray)\(\))?\s*$`);
|
|
944
|
+
/** open の位置の開き括弧からの引数の範囲(閉じ括弧が見つからなければ undefined) */
|
|
945
|
+
function callArguments(source, open) {
|
|
946
|
+
const args = [];
|
|
947
|
+
const limit = Math.min(source.length, open + 2000);
|
|
948
|
+
let depth = 0;
|
|
949
|
+
let argStart = open + 1;
|
|
950
|
+
for (let i = open + 1; i < limit; i++) {
|
|
951
|
+
const ch = source.charAt(i);
|
|
952
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
953
|
+
// C# の逐語的文字列(@"...")は "" が引用符、ほかは \ の後の文字が文字列の中
|
|
954
|
+
const verbatim = ch === '"' && source.charAt(i - 1) === "@";
|
|
955
|
+
let j = i + 1;
|
|
956
|
+
for (; j < limit; j++) {
|
|
957
|
+
const c = source.charAt(j);
|
|
958
|
+
if ((c === "\n" || c === "\r") && ch !== "`")
|
|
959
|
+
return undefined;
|
|
960
|
+
if (c === "\\" && !verbatim) {
|
|
961
|
+
j += 1;
|
|
962
|
+
}
|
|
963
|
+
else if (c === ch) {
|
|
964
|
+
if (verbatim && source.charAt(j + 1) === ch) {
|
|
965
|
+
j += 1;
|
|
966
|
+
}
|
|
967
|
+
else {
|
|
968
|
+
break;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
i = j;
|
|
973
|
+
}
|
|
974
|
+
else if (ch === "(" || ch === "[" || ch === "{") {
|
|
975
|
+
depth += 1;
|
|
976
|
+
}
|
|
977
|
+
else if (ch === ")" || ch === "]" || ch === "}") {
|
|
978
|
+
if (depth === 0) {
|
|
979
|
+
if (ch !== ")")
|
|
980
|
+
return undefined;
|
|
981
|
+
args.push({ start: argStart, end: i });
|
|
982
|
+
return args.length === 1 && source.slice(argStart, i).trim() === "" ? [] : args;
|
|
983
|
+
}
|
|
984
|
+
depth -= 1;
|
|
985
|
+
}
|
|
986
|
+
else if (ch === "," && depth === 0) {
|
|
987
|
+
args.push({ start: argStart, end: i });
|
|
988
|
+
argStart = i + 1;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return undefined;
|
|
992
|
+
}
|
|
993
|
+
/** パスワードを位置で渡す定番の関数の、その位置の文字列を伏せる */
|
|
994
|
+
function maskPositionalCalls(source, findings) {
|
|
995
|
+
const spans = [];
|
|
996
|
+
for (const m of source.matchAll(POSITIONAL_CALL_NAME)) {
|
|
997
|
+
const at = m.index ?? 0;
|
|
998
|
+
const qualifier = /(?:[A-Za-z_$][\w$]*\.)*$/.exec(source.slice(Math.max(0, at - 120), at))?.[0] ?? "";
|
|
999
|
+
const name = `${qualifier}${m[1] ?? ""}`;
|
|
1000
|
+
const entry = POSITIONAL_SECRET_CALLS.find(([pattern]) => pattern.test(name));
|
|
1001
|
+
if (entry === undefined)
|
|
1002
|
+
continue;
|
|
1003
|
+
const args = callArguments(source, at + m[0].length - 1);
|
|
1004
|
+
const index = args === undefined ? undefined : entry[1](args.length);
|
|
1005
|
+
const arg = index === undefined ? undefined : args?.[index];
|
|
1006
|
+
if (arg === undefined)
|
|
1007
|
+
continue;
|
|
1008
|
+
const text = source.slice(arg.start, arg.end);
|
|
1009
|
+
const literal = ARG_LITERAL.exec(text);
|
|
1010
|
+
if (literal === null)
|
|
1011
|
+
continue;
|
|
1012
|
+
const value = literal[1] ?? "";
|
|
1013
|
+
const prefix = LITERAL_PREFIX.exec(value)?.[0] ?? "";
|
|
1014
|
+
const inner = value.slice(prefix.length + 1, -1);
|
|
1015
|
+
if (inner.trim() === "" || inner === MASK || isNonSecretValue(inner) || isCliNonSecret(inner))
|
|
1016
|
+
continue;
|
|
1017
|
+
const start = arg.start + text.indexOf(value) + prefix.length + 1;
|
|
1018
|
+
spans.push({ start, end: start + inner.length });
|
|
1019
|
+
}
|
|
1020
|
+
if (spans.length === 0)
|
|
1021
|
+
return source;
|
|
1022
|
+
let out = "";
|
|
1023
|
+
let last = 0;
|
|
1024
|
+
for (const span of spans.sort((x, y) => x.start - y.start)) {
|
|
1025
|
+
if (span.start < last)
|
|
1026
|
+
continue;
|
|
1027
|
+
findings.push({ line: lineOf(source, span.start), kind: KIND_PASSWORD });
|
|
1028
|
+
out += source.slice(last, span.start) + MASK;
|
|
1029
|
+
last = span.end;
|
|
1030
|
+
}
|
|
1031
|
+
return out + source.slice(last);
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* 括弧を省いた呼び出しの文字列だけの文(Gradle の credentials { password '...' } / username "..." の行)。
|
|
1035
|
+
* 行の頭(前に { で開いたブロックの名前があってもよい)の名前と文字列だけのもの
|
|
1036
|
+
*/
|
|
1037
|
+
const COMMAND_CALL_LITERAL = new RegExp(String.raw `(^[ \t]*(?:[A-Za-z_][\w.]*[ \t]*\{[ \t]*)*)([A-Za-z_]\w*)([ \t]+)` + KEY_VALUE + String.raw `(?=[ \t]*(?:[;}]|\/\/|\r?$))`, "gm");
|
|
1038
|
+
/**
|
|
1039
|
+
* 名前と値を属性に書く要素(Java の <param name="password" value="..."/>・Spring の <property name="password" value="..."/> /
|
|
1040
|
+
* <entry key="password" value="..."/> / <constructor-arg name="password" value="..."/>)。.NET の <add key value> は CONFIG_ADD
|
|
1041
|
+
*/
|
|
1042
|
+
const NAMED_VALUE_TAG = new RegExp(`<(?:param|property|parameter|entry|constructor-arg|arg)\\b${TAG_BODY}>`, "gi");
|
|
1043
|
+
const NAMED_VALUE_ATTR = /(?<![\w-])(name|key|value)(\s*=\s*)("[^"]*"|'[^']*')/gi;
|
|
1044
|
+
/**
|
|
1045
|
+
* 設定の既定値の属性(C# の Settings.Designer.cs の [DefaultSettingValueAttribute("...")] と、汎用テキストとして伏せる
|
|
1046
|
+
* .vb の <DefaultSettingValueAttribute("...")>)。名前は続くプロパティで決める(VB のソースは maskVbSource が読む)
|
|
1047
|
+
*/
|
|
1048
|
+
const DEFAULT_SETTING_LITERAL = new RegExp(String.raw `(DefaultSettingValue(?:Attribute)?[ \t]*\([ \t]*)` + KEY_VALUE + String.raw `(?=[ \t]*\)[ \t]*[\]>])`, "g");
|
|
1049
|
+
const DEFAULT_SETTING_TARGET = /^[ \t]*\)[ \t]*[\]>][\s\S]{0,400}?(?:\bProperty[ \t]+\[?([A-Za-z_]\w*)|[\w.<>?]+[ \t]+([A-Za-z_]\w*)[ \t]*(?:\r?\n[ \t]*)?\{)/;
|
|
1050
|
+
/** KEY_VALUE の文字列の接頭辞・引用符・中身 */
|
|
1051
|
+
function literalParts(literal) {
|
|
1052
|
+
const prefix = LITERAL_PREFIX.exec(literal)?.[0] ?? "";
|
|
1053
|
+
return { prefix, quote: literal.charAt(prefix.length), inner: literal.slice(prefix.length + 1, -1) };
|
|
1054
|
+
}
|
|
1055
|
+
/** 文字列の中身を伏せた形(接頭辞と引用符は残す) */
|
|
1056
|
+
function maskedLiteral(literal) {
|
|
1057
|
+
const { prefix, quote } = literalParts(literal);
|
|
1058
|
+
return `${prefix}${quote}${MASK}${quote}`;
|
|
1059
|
+
}
|
|
1060
|
+
/** コードの形の値を伏せる(setter・builder、既定値、比較、位置で渡す定番の関数、括弧を省いた呼び出し、名前と値の属性、設定の既定値) */
|
|
1061
|
+
function maskCodeShapes(source, findings) {
|
|
1062
|
+
let result = source;
|
|
1063
|
+
const secret = (key, inner) => isSecretPair(key, inner) && !isTypeName(inner);
|
|
1064
|
+
result = result.replace(SECRET_SETTER, (whole, lead, callee, literal, offset) => {
|
|
1065
|
+
const key = secretSetterKey(callee);
|
|
1066
|
+
if (key === undefined || !secret(key, literalParts(literal).inner))
|
|
1067
|
+
return whole;
|
|
1068
|
+
findings.push({ line: lineOf(result, offset), kind: KIND_PASSWORD });
|
|
1069
|
+
return `${lead}${maskedLiteral(literal)}`;
|
|
1070
|
+
});
|
|
1071
|
+
{
|
|
1072
|
+
const before = result;
|
|
1073
|
+
result = before.replace(DEFAULT_LITERAL, (whole, op, gap, literal, offset) => {
|
|
1074
|
+
const { inner } = literalParts(literal);
|
|
1075
|
+
if (inner === "" || inner === MASK)
|
|
1076
|
+
return whole;
|
|
1077
|
+
// 行の頭から(長い行は直前の 300 文字。1 行の大きいファイルで行の頭まで探し直さないよう、先に切り出す)
|
|
1078
|
+
const near = before.slice(Math.max(0, offset - 300), offset);
|
|
1079
|
+
if (!defaultValueKeys(near.slice(near.lastIndexOf("\n") + 1)).some((key) => secret(key, inner)))
|
|
1080
|
+
return whole;
|
|
1081
|
+
findings.push({ line: lineOf(before, offset), kind: KIND_PASSWORD });
|
|
1082
|
+
return `${op}${gap}${maskedLiteral(literal)}`;
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
for (const pattern of [COMPARE_LITERAL, EQUALS_LITERAL]) {
|
|
1086
|
+
result = result.replace(pattern, (whole, lead, chain, literal, offset) => {
|
|
1087
|
+
if (!secret(compareKey(chain), literalParts(literal).inner))
|
|
1088
|
+
return whole;
|
|
1089
|
+
findings.push({ line: lineOf(result, offset), kind: KIND_PASSWORD });
|
|
1090
|
+
return `${lead}${maskedLiteral(literal)}`;
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
for (const pattern of [COMPARE_LITERAL_LEFT, EQUALS_LITERAL_LEFT]) {
|
|
1094
|
+
result = result.replace(pattern, (whole, literal, tail, chain, offset) => {
|
|
1095
|
+
if (!secret(compareKey(chain), literalParts(literal).inner))
|
|
1096
|
+
return whole;
|
|
1097
|
+
findings.push({ line: lineOf(result, offset), kind: KIND_PASSWORD });
|
|
1098
|
+
return `${maskedLiteral(literal)}${tail}`;
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
result = maskPositionalCalls(result, findings);
|
|
1102
|
+
result = result.replace(COMMAND_CALL_LITERAL, (whole, lead, key, gap, literal, offset) => {
|
|
1103
|
+
if (!secret(key, literalParts(literal).inner))
|
|
1104
|
+
return whole;
|
|
1105
|
+
findings.push({ line: lineOf(result, offset), kind: KIND_PASSWORD });
|
|
1106
|
+
return `${lead}${key}${gap}${maskedLiteral(literal)}`;
|
|
1107
|
+
});
|
|
1108
|
+
result = result.replace(NAMED_VALUE_TAG, (tag, offset) => {
|
|
1109
|
+
let key;
|
|
1110
|
+
let value;
|
|
1111
|
+
for (const attr of tag.matchAll(NAMED_VALUE_ATTR)) {
|
|
1112
|
+
const inner = (attr[3] ?? "").slice(1, -1);
|
|
1113
|
+
if (attr[1]?.toLowerCase() === "value")
|
|
1114
|
+
value ??= inner.trim();
|
|
1115
|
+
else
|
|
1116
|
+
key ??= inner;
|
|
1117
|
+
}
|
|
1118
|
+
// 設定の値なので token / credentials のキーも値によらず伏せる(appSettings と同じ)
|
|
1119
|
+
if (key === undefined || value === undefined || kindForConfigKey(key) !== KIND_PASSWORD)
|
|
1120
|
+
return tag;
|
|
1121
|
+
if (value === "" || value === MASK || isNonSecretValue(value))
|
|
1122
|
+
return tag;
|
|
1123
|
+
findings.push({ line: lineOf(result, offset), kind: KIND_PASSWORD });
|
|
1124
|
+
return tag.replace(NAMED_VALUE_ATTR, (attr, name, eq, quoted) => name.toLowerCase() === "value" ? `${name}${eq}${quoted.charAt(0)}${MASK}${quoted.charAt(0)}` : attr);
|
|
1125
|
+
});
|
|
1126
|
+
{
|
|
1127
|
+
const before = result;
|
|
1128
|
+
result = before.replace(DEFAULT_SETTING_LITERAL, (whole, lead, literal, offset) => {
|
|
1129
|
+
const { inner } = literalParts(literal);
|
|
1130
|
+
const target = DEFAULT_SETTING_TARGET.exec(before.slice(offset + whole.length, offset + whole.length + 500));
|
|
1131
|
+
const kind = target === null ? undefined : kindForConfigKey(target[1] ?? target[2] ?? "");
|
|
1132
|
+
if (kind === undefined || inner.trim() === "" || inner === MASK || isNonSecretValue(inner))
|
|
1133
|
+
return whole;
|
|
1134
|
+
findings.push({ line: lineOf(before, offset), kind });
|
|
1135
|
+
return `${lead}${maskedLiteral(literal)}`;
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
return result;
|
|
1139
|
+
}
|
|
679
1140
|
/** 設定のキー名の最後の語(と最後の 2 語を続けたもの)がこれらなら秘密系 / ユーザー ID 系 */
|
|
680
1141
|
const SECRET_KEY_WORDS = new Set([
|
|
681
1142
|
"password",
|
|
@@ -1131,6 +1592,47 @@ function callArgKind(tail) {
|
|
|
1131
1592
|
}
|
|
1132
1593
|
return undefined;
|
|
1133
1594
|
}
|
|
1595
|
+
/**
|
|
1596
|
+
* VB の呼び出しの引数の位置で決まる種別(v0.20.0)。tail は文字列の直前までのコード、after は文字列の後ろ。
|
|
1597
|
+
* - If(式, "既定値") の既定値: 式の中の名前・キーの形の文字列か、If の結果の代入の先が秘密系なら
|
|
1598
|
+
* (If(Environment.GetEnvironmentVariable("DB_PASSWORD"), "...") / Dim password = If(x, "..."))。3 つの引数の If は除く
|
|
1599
|
+
* - パスワードを位置で渡す定番の関数(client.Authenticate("user", "pw") / AuthenticateAsync)の 2 番目の引数
|
|
1600
|
+
*/
|
|
1601
|
+
function vbCallPositionKind(tail, after) {
|
|
1602
|
+
const line = tail.slice(tail.lastIndexOf("\n") + 1);
|
|
1603
|
+
// 文字列の中の括弧・カンマを数えないよう、同じ長さの _ に替える
|
|
1604
|
+
const plain = line.replace(/"(?:[^"\r\n]|"")*"/g, (s) => `"${"_".repeat(s.length - 2)}"`);
|
|
1605
|
+
let depth = 0;
|
|
1606
|
+
let commas = 0;
|
|
1607
|
+
let firstComma = -1;
|
|
1608
|
+
for (let i = plain.length - 1; i >= 0; i--) {
|
|
1609
|
+
const ch = plain.charAt(i);
|
|
1610
|
+
if (ch === ")") {
|
|
1611
|
+
depth += 1;
|
|
1612
|
+
}
|
|
1613
|
+
else if (ch === "(") {
|
|
1614
|
+
if (depth > 0) {
|
|
1615
|
+
depth -= 1;
|
|
1616
|
+
continue;
|
|
1617
|
+
}
|
|
1618
|
+
const found = /((?:[A-Za-z_]\w*\.)*[A-Za-z_]\w*)\s*$/.exec(plain.slice(0, i));
|
|
1619
|
+
const callee = found?.[1] ?? "";
|
|
1620
|
+
if (/^if$/i.test(callee) && commas === 1 && /^\s*\)/.test(after)) {
|
|
1621
|
+
const keys = [
|
|
1622
|
+
...[...line.slice(i + 1, firstComma).matchAll(/"([A-Za-z_][\w.:-]*)"|([A-Za-z_]\w*)\s*(?:\(\s*\))?\s*$/g)].map((m) => m[1] ?? m[2] ?? ""),
|
|
1623
|
+
ASSIGNMENT_TAIL.exec(line.slice(0, found?.index ?? i))?.[1] ?? "",
|
|
1624
|
+
];
|
|
1625
|
+
return keys.some((key) => kindForIdentifier(key) === KIND_PASSWORD) ? KIND_PASSWORD : undefined;
|
|
1626
|
+
}
|
|
1627
|
+
return /\.authenticate(?:async)?$/i.test(callee) && commas === 1 ? KIND_PASSWORD : undefined;
|
|
1628
|
+
}
|
|
1629
|
+
else if (ch === "," && depth === 0) {
|
|
1630
|
+
commas += 1;
|
|
1631
|
+
firstComma = i;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
return undefined;
|
|
1635
|
+
}
|
|
1134
1636
|
/** コメント内のマスク(コメントアウトされた認証情報コードも対象にする) */
|
|
1135
1637
|
function maskCommentText(comment, findings, line, strict) {
|
|
1136
1638
|
let result = comment.replace(COMMENT_ASSIGN, (whole, identifier, assign, _value, close) => {
|
|
@@ -1223,6 +1725,10 @@ function maskVbSource(content, findings, strict) {
|
|
|
1223
1725
|
? kindForIdentifier(namedArg[1] ?? "")
|
|
1224
1726
|
: callArgKind(tail);
|
|
1225
1727
|
}
|
|
1728
|
+
// If(環境変数, "既定値") の既定値と、パスワードを位置で渡す定番の関数(client.Authenticate("user", "pw"))
|
|
1729
|
+
if (kind === undefined) {
|
|
1730
|
+
kind = vbCallPositionKind(tail, content.slice(j + 1, j + 80));
|
|
1731
|
+
}
|
|
1226
1732
|
// My.Settings の既定値(続くプロパティの名前で決める)
|
|
1227
1733
|
if (kind === undefined && DEFAULT_SETTING_CALLEE.test(tail)) {
|
|
1228
1734
|
const property = DEFAULT_SETTING_PROPERTY.exec(content.slice(j + 1, j + 400));
|
|
@@ -1500,8 +2006,10 @@ function maskGenericText(content, findings, strict, colonPairs = true) {
|
|
|
1500
2006
|
findings.push({ line: lineOf(result, offset), kind: kindForConfigKey(key) ?? KIND_PASSWORD });
|
|
1501
2007
|
return `${flag}${quote}${key}=${shown}${quote}`;
|
|
1502
2008
|
});
|
|
1503
|
-
// パスワードを引数で渡すコマンド(sqlcmd -P ... / mysql -p... / net use \\srv\share ... / schtasks /RP ...)
|
|
2009
|
+
// パスワードを引数で渡すコマンド(sqlcmd -P ... / mysql -p... / net use \\srv\share ... / schtasks /RP ... / curl -u ...)
|
|
1504
2010
|
result = maskCliArgs(result, findings);
|
|
2011
|
+
// PowerShell の ConvertTo-SecureString "..." -AsPlainText
|
|
2012
|
+
result = maskSecureStrings(result, findings);
|
|
1505
2013
|
// XML 属性形式(値が引用符で囲まれるため接続文字列パターンでは拾えない)
|
|
1506
2014
|
for (const regex of [ATTR_SECRET, ATTR_SECRET_SINGLE]) {
|
|
1507
2015
|
result = result.replace(regex, (whole, key, eq, value, closeQuote, offset) => {
|
|
@@ -1552,7 +2060,7 @@ function maskGenericText(content, findings, strict, colonPairs = true) {
|
|
|
1552
2060
|
return whole;
|
|
1553
2061
|
}
|
|
1554
2062
|
}
|
|
1555
|
-
const prefix =
|
|
2063
|
+
const prefix = LITERAL_PREFIX.exec(literal)?.[0] ?? "";
|
|
1556
2064
|
const quote = literal.charAt(prefix.length);
|
|
1557
2065
|
if (!isSecretPair(name, literal.slice(prefix.length + 1, -1))) {
|
|
1558
2066
|
return whole;
|
|
@@ -1565,7 +2073,7 @@ function maskGenericText(content, findings, strict, colonPairs = true) {
|
|
|
1565
2073
|
// 添字への代入と、秘密の名前を最初の引数に渡す関数の 2 番目の文字列(型の名前・表示の文言は除く)
|
|
1566
2074
|
for (const pattern of [SUBSCRIPT_LITERAL, NAMED_ARG_LITERAL]) {
|
|
1567
2075
|
result = result.replace(pattern, (whole, open, key, sep, literal, offset) => {
|
|
1568
|
-
const prefix =
|
|
2076
|
+
const prefix = LITERAL_PREFIX.exec(literal)?.[0] ?? "";
|
|
1569
2077
|
const quote = literal.charAt(prefix.length);
|
|
1570
2078
|
const inner = literal.slice(prefix.length + 1, -1);
|
|
1571
2079
|
if (!isSecretPair(key.slice(1, -1), inner) || isTypeName(inner)) {
|
|
@@ -1579,6 +2087,8 @@ function maskGenericText(content, findings, strict, colonPairs = true) {
|
|
|
1579
2087
|
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)
|
|
1580
2088
|
? whole
|
|
1581
2089
|
: maskKeyLiteral(whole, key, sep, literal, offset));
|
|
2090
|
+
// コードの形(v0.20.0。setter・builder・既定値・比較・位置で渡す定番の関数・Gradle・<param>・設定の既定値)
|
|
2091
|
+
result = maskCodeShapes(result, findings);
|
|
1582
2092
|
result = maskConnstrText(result, findings, (index) => lineOf(result, index));
|
|
1583
2093
|
if (strict) {
|
|
1584
2094
|
result = maskEntropyText(result, findings, (index) => lineOf(result, index));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tazuna",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.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",
|