@tyhld/conductor 0.12.180 → 0.12.181
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/package.json
CHANGED
package/scripts/hooks/README.md
CHANGED
|
@@ -444,6 +444,22 @@ DENY** です。読み込み先は公式の説明と道具の実体で確かめ
|
|
|
444
444
|
書き込み先の語・包み・縦棒で別の命令へ流れ込む `echo`・閉じていない字面・展開の中の `echo` は伏せません。
|
|
445
445
|
固定する試験: `test_quoted_text_not_command.py`(便 dbf1e335 の形・展開・空振り確認つき)。
|
|
446
446
|
|
|
447
|
+
#### ★探す言葉の引用符の中の `>`・`=>` は書き出しと読まない(便 2f8029fc・えふさん決定 2026-11-10 判断⑧)
|
|
448
|
+
|
|
449
|
+
便 f96627f8(現場 ai-kana)で、名指しの1ファイルを読むだけの `git grep -n -F -e '…((r) => r.key …)…' -- <ファイル>` が、
|
|
450
|
+
探す言葉の中の `> r.key` を「秘密のファイル `r.key` への書き出し」と読まれ、`danger: redirect into secret file` で止まりました。
|
|
451
|
+
書き込み先を引用符を見ずに拾う `redirect_targets` が、引用符の中の字まで書き込み先として取り出していたためです。
|
|
452
|
+
|
|
453
|
+
| 形 | 前 | 後 |
|
|
454
|
+
| --- | --- | --- |
|
|
455
|
+
| `grep` の仲間(`egrep`・`fgrep`・`rg`・`ag`・`ack`・`ugrep`)・`git grep`(`-C <場所>`・`--no-pager` つきも)の**探す言葉**(`-e`/`--regexp` の値・無ければ旗でない最初の引数)の引用符の中の `>` | 秘密・システム領域の名前が続くと `danger` | **ただの字(通す)** |
|
|
456
|
+
| 引用符の外の本物の書き出し(`> f`・`>> f`・`2> f`・`>\| f`・`&> f`) | `danger` | **`danger`(変えない)** |
|
|
457
|
+
| 引用符が閉じていない・行に縦棒がある(`grep -o '…' f \| sh`)・展開の中・包みの中・`-f`/`--file` がある・探す言葉でない引数(パス)・探す道具でない命令(`echo "x > <秘密>"` ほか) | `danger` | **`danger`(変えない)** |
|
|
458
|
+
|
|
459
|
+
★伏せるのは**探す言葉の引用符の中の `>` の字だけ**です(`;`・`&`・`|`・改行は探す言葉でも伏せません)。上の表と同じく、
|
|
460
|
+
今の判定が当たったときだけ伏せた写しで測り直し、**写しで何も当たらないときだけ**通します。
|
|
461
|
+
固定する試験: `test_quoted_search_redirect.py`(便 f96627f8 で止まった命令の全文・止める側つき)。
|
|
462
|
+
|
|
447
463
|
### ★秘密のファイルを持ち出せた前からの穴を塞ぐ(便 9bf7e26e・えふさん決定 2026-11-02)
|
|
448
464
|
|
|
449
465
|
便 7932bd6a の報告で見つかり、CC1 が 0.12.164 で実測した穴です(どれも前から `allow`)。
|
package/scripts/hooks/policy.py
CHANGED
|
@@ -6719,6 +6719,13 @@ _SUBST_MAX_DEPTH = 4
|
|
|
6719
6719
|
# 今までどおり当たる)。★`<` `>` は伏せない=引用符の中の書き込み先に見える字は今までどおり止める
|
|
6720
6720
|
# (便 93e3c6d8 の決まり・test_quoted_devnull.py b11)。
|
|
6721
6721
|
_MASK_CHARS = frozenset(';&|\n')
|
|
6722
|
+
#: 探す道具の【探す言葉】で伏せる字=書き出しに見える `>` だけ(便 2f8029fc・えふさん決定 2026-11-10 判断⑧)。
|
|
6723
|
+
# `git grep -e '(r) => r.key' -- <ファイル>` の `> r.key` が秘密のファイルへの書き出しに読まれ、
|
|
6724
|
+
# 読むだけの検索が danger で止まった(実地 便 f96627f8)。探す言葉は道具に渡る字で、書き込み先にならない。
|
|
6725
|
+
# ★伏せるのは引用符の中のただの字の `>` だけ(引用符の外の `>` `>>` `2>` `>|` は1字も変えない・
|
|
6726
|
+
# 探す言葉の `;` `&` `|` 改行は今までどおり伏せない)。
|
|
6727
|
+
# ★縦棒で流れ込む形・展開の中・-f/--file の値・閉じていない引用符は伏せない(止める側)。
|
|
6728
|
+
_SEARCH_MASK_CHARS = frozenset('>')
|
|
6722
6729
|
#: 展開の中身で当たったときに理由へ添える印。
|
|
6723
6730
|
_SUBST_WHERE = '(inside command substitution)'
|
|
6724
6731
|
|
|
@@ -7085,8 +7092,46 @@ def _maskable_words(texts, echo_ok: bool):
|
|
|
7085
7092
|
return out - redirect
|
|
7086
7093
|
|
|
7087
7094
|
|
|
7095
|
+
def _search_pattern_words(texts, echo_ok: bool):
|
|
7096
|
+
"""1つの命令の語のうち、探す道具(grep の仲間・git grep)の【探す言葉】の語の番号を返す(便 2f8029fc)。
|
|
7097
|
+
|
|
7098
|
+
★探す言葉の見分けは pattern_arg_positions に任せる(-e/--regexp の値・無ければ最初の引数)。
|
|
7099
|
+
-f/--file があれば1つも返さない(探す言葉はファイルに在る=引数はパス)。
|
|
7100
|
+
★echo_ok=False(行のどこかに縦棒がある・展開の中身を測っている)のときは返さない
|
|
7101
|
+
=`grep -o '<命令>' f | sh` のように、探す言葉の字が別の命令に読まれる形を通さない。
|
|
7102
|
+
★書き込み先・読み込み元の語は返さない。
|
|
7103
|
+
"""
|
|
7104
|
+
if not echo_ok:
|
|
7105
|
+
return set()
|
|
7106
|
+
toks = [(tokens_of(t) or [''])[0] for t in texts]
|
|
7107
|
+
redirect = set()
|
|
7108
|
+
for p, raw in enumerate(texts):
|
|
7109
|
+
if _REDIRECT_WORD_RE.match(raw):
|
|
7110
|
+
redirect.add(p)
|
|
7111
|
+
if _REDIRECT_ONLY_RE.match(raw):
|
|
7112
|
+
redirect.add(p + 1)
|
|
7113
|
+
k = 0
|
|
7114
|
+
while k < len(toks) and _ASSIGN_RE.match(toks[k]):
|
|
7115
|
+
k += 1
|
|
7116
|
+
if k >= len(toks):
|
|
7117
|
+
return set()
|
|
7118
|
+
verb = toks[k].split('/')[-1]
|
|
7119
|
+
if verb == 'git':
|
|
7120
|
+
j = k + 1
|
|
7121
|
+
while j < len(toks) and toks[j] in ('-C', '--no-pager'):
|
|
7122
|
+
j += 2 if toks[j] == '-C' else 1
|
|
7123
|
+
if j >= len(toks) or toks[j] != 'grep':
|
|
7124
|
+
return set()
|
|
7125
|
+
first, verb = j + 1, 'grep'
|
|
7126
|
+
elif verb in _PATTERN_FIRST_VERBS:
|
|
7127
|
+
first = k + 1
|
|
7128
|
+
else:
|
|
7129
|
+
return set()
|
|
7130
|
+
return {first + p for p in pattern_arg_positions(verb, toks[first:])} - redirect
|
|
7131
|
+
|
|
7132
|
+
|
|
7088
7133
|
def _mask_quoted_text(command: str, echo_ok: bool = True) -> str:
|
|
7089
|
-
"""説明文・echo
|
|
7134
|
+
"""説明文・echo の文字・探す言葉の、引用符の中のただの字を伏せた写しを返す(伏せる所が無ければ元のまま)。"""
|
|
7090
7135
|
text = command or ''
|
|
7091
7136
|
cmds = _quoted_words(text)
|
|
7092
7137
|
if cmds is None:
|
|
@@ -7095,16 +7140,18 @@ def _mask_quoted_text(command: str, echo_ok: bool = True) -> str:
|
|
|
7095
7140
|
spans = []
|
|
7096
7141
|
for words, _piped in cmds:
|
|
7097
7142
|
texts = [text[s:e] for s, e, _r in words]
|
|
7098
|
-
|
|
7099
|
-
|
|
7143
|
+
search = _search_pattern_words(texts, echo_ok)
|
|
7144
|
+
for p in _maskable_words(texts, echo_ok) | search:
|
|
7145
|
+
chars = _SEARCH_MASK_CHARS if p in search else _MASK_CHARS
|
|
7146
|
+
spans.extend((s, e, chars) for s, e in words[p][2])
|
|
7100
7147
|
if not spans:
|
|
7101
7148
|
return text
|
|
7102
|
-
|
|
7103
|
-
for s, e in spans:
|
|
7149
|
+
out = list(text)
|
|
7150
|
+
for s, e, chars in spans:
|
|
7104
7151
|
for x in range(s, e):
|
|
7105
|
-
if
|
|
7106
|
-
|
|
7107
|
-
return ''.join(
|
|
7152
|
+
if out[x] in chars:
|
|
7153
|
+
out[x] = ' '
|
|
7154
|
+
return ''.join(out)
|
|
7108
7155
|
|
|
7109
7156
|
|
|
7110
7157
|
def _subst_danger(command: str, cwd=None, outside_grep_tree=True, depth: int = 0):
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""引用符の中の検索の言葉にある `>`・`=>` を、書き出しと読まない検査(便 2f8029fc・えふさん決定 2026-11-10 判断⑧)。
|
|
3
|
+
|
|
4
|
+
実行: python3 scripts/hooks/test_quoted_search_redirect.py
|
|
5
|
+
1件でも期待と違えば exit 1。
|
|
6
|
+
|
|
7
|
+
【なぜ要るか(実地 便 f96627f8・現場 ai-kana)】
|
|
8
|
+
名指しの1ファイルを読むだけの git grep が、探す言葉の中の `(r) => r.key` を
|
|
9
|
+
「秘密のファイル r.key への書き出し」と読まれ、danger で止まった。書き込み先を引用符を見ずに拾う
|
|
10
|
+
redirect_targets が、引用符の中の `> r.key` を書き込み先として取り出したため。
|
|
11
|
+
|
|
12
|
+
【ここで固定すること】
|
|
13
|
+
(a) 止めない側 … 前便で止まった命令の全文・grep/git grep の引用符の中の探す言葉の `>` `=>`
|
|
14
|
+
(b) 止める側 … 引用符の外の本物の書き出し(> >> 2> >|)・引用符が閉じていない形・
|
|
15
|
+
流れ込む先がある形・探す言葉でない引数・探す道具でない命令・名指しの秘密のファイル
|
|
16
|
+
|
|
17
|
+
★この台本は秘密の名前を素の字で置かない(組み立てて使う)。職人の命令の字面に出さないため。
|
|
18
|
+
"""
|
|
19
|
+
import os
|
|
20
|
+
import sys
|
|
21
|
+
|
|
22
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
23
|
+
|
|
24
|
+
import policy # noqa: E402
|
|
25
|
+
|
|
26
|
+
failures = []
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def check(label, got, want):
|
|
30
|
+
ok = got == want
|
|
31
|
+
if not ok:
|
|
32
|
+
failures.append(f'{label}: got={got!r} want={want!r}')
|
|
33
|
+
print(f'{"OK " if ok else "NG "} {label:58} {str(got)[:46]}')
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
CWD = '/tmp/claude-1000'
|
|
37
|
+
KEY = 'r.' + 'key'
|
|
38
|
+
ENV = '.' + 'env'
|
|
39
|
+
ETC = '/et' + 'c/'
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def decide(cmd):
|
|
43
|
+
return policy.decide_bash(cmd, CWD)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def kind_of(reason):
|
|
47
|
+
return reason.split(':', 1)[0]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# ── 前便で止まった命令の全文(秘密に見える語だけを組み立て形にした・ほかは1文字も変えていない)──
|
|
51
|
+
REAL = ("git grep -n -F -e 'humanChecksForViewer(unread.humanChecks, { userId: currentUserId, isAdmin })'"
|
|
52
|
+
" -e \"['landed', TOP_WORDS.landedIcon, TOP_WORDS.landed, todayResults.landed]\""
|
|
53
|
+
" -e 'myChecks?.headline?.rows.find((r) => " + KEY + " === myLaneKey)?.count'"
|
|
54
|
+
" -e 'myTurnItems.slice(0, HUMAN_CHECK_EFU_LIMIT)' -- src/app/conductor/board.tsx")
|
|
55
|
+
|
|
56
|
+
# ═════════════════════════════════════════════════════════════════════════════
|
|
57
|
+
# (a) 止めない側
|
|
58
|
+
# ═════════════════════════════════════════════════════════════════════════════
|
|
59
|
+
print('── (a) 止めない側(allow) ' + '─' * 40)
|
|
60
|
+
ALLOW = [
|
|
61
|
+
('a01 前便で止まった命令の全文', REAL),
|
|
62
|
+
('a02 git grep -e の単引用符の中の =>', "git grep -n -e '(r) => " + KEY + "' -- src"),
|
|
63
|
+
('a03 git grep -e の二重引用符の中の =>', 'git grep -n -e "(r) => ' + KEY + '" -- src'),
|
|
64
|
+
('a04 git grep の最初の引数(-e なし)', "git grep -n '(r) => " + KEY + "' -- src"),
|
|
65
|
+
('a05 grep -e の引用符の中の >', "grep -n -e 'a > " + ENV + "' src/a.ts"),
|
|
66
|
+
('a06 grep の最初の引数の >>', "grep -n 'a >> " + ENV + "' src/a.ts"),
|
|
67
|
+
('a07 grep の 2> を含む探す言葉', "grep -n 'x 2> " + ENV + "' src/a.ts"),
|
|
68
|
+
('a08 rg の引用符の中の =>', "rg -n '(r) => " + KEY + "' src/a.ts"),
|
|
69
|
+
('a09 grep --regexp= の値の =>', "grep -n --regexp='(r) => " + KEY + "' src/a.ts"),
|
|
70
|
+
('a10 git -C <場所> grep', "git -C /tmp/claude-1000/w grep -n -e '(r) => " + KEY + "' -- src"),
|
|
71
|
+
('a11 引用符の中の探す言葉+外の捨て先', "git grep -n -e '(r) => " + KEY + "' -- src 2>/dev/null"),
|
|
72
|
+
]
|
|
73
|
+
for label, cmd in ALLOW:
|
|
74
|
+
r = decide(cmd)
|
|
75
|
+
check(label, (r['decision'], r['reason'][:60]), ('allow', 'no gate, no danger'))
|
|
76
|
+
|
|
77
|
+
# ═════════════════════════════════════════════════════════════════════════════
|
|
78
|
+
# (b) 止める側(danger のまま)
|
|
79
|
+
# ═════════════════════════════════════════════════════════════════════════════
|
|
80
|
+
print('── (b) 止める側(danger) ' + '─' * 41)
|
|
81
|
+
DANGER = [
|
|
82
|
+
('b01 引用符の外の > ' + 'r.key', 'echo x > ' + KEY),
|
|
83
|
+
('b02 引用符の外の >> .env', 'echo x >> ' + ENV),
|
|
84
|
+
('b03 引用符の外の 2> 秘密のファイル', 'ls 2> ' + KEY),
|
|
85
|
+
('b04 引用符の外の >|', 'echo x >| ' + KEY),
|
|
86
|
+
('b05 探す言葉の後ろの本物の書き出し', "git grep -n -e '(r) => x' -- src > " + KEY),
|
|
87
|
+
('b06 探す言葉の後ろの本物の >>', "grep -n 'a => b' src/a.ts >> " + ENV),
|
|
88
|
+
('b07 探す言葉の後ろの本物の 2>', "grep -n 'a => b' src/a.ts 2> " + ENV),
|
|
89
|
+
('b08 前便の全文+本物の書き出し', REAL + ' > ' + KEY),
|
|
90
|
+
('b09 引用符が閉じていない', "git grep -n -e '(r) => " + KEY + " -- src"),
|
|
91
|
+
('b10 二重引用符が閉じていない', 'grep -n "a > ' + ENV + ' src/a.ts'),
|
|
92
|
+
('b11 流れ込む先がある(grep -o | sh)', "grep -o 'cat x > " + ENV + "' src/a.ts | sh"),
|
|
93
|
+
('b12 探す道具でない命令(echo)の引用符の中', 'echo "x > ' + KEY + '"'),
|
|
94
|
+
('b13 echo の引用符の中の /etc への書き込み', 'echo "see >' + ETC + 'hosts"'),
|
|
95
|
+
('b14 包みの中の本物の書き出し', 'bash -c "grep -n x src > ' + ENV + '"'),
|
|
96
|
+
('b15 名指しの秘密のファイルを探す', "grep -n 'a => b' " + ENV),
|
|
97
|
+
('b16 -f の値(探す言葉のファイル)は伏せない', "grep -f '" + ENV + "' src/a.ts"),
|
|
98
|
+
('b17 コマンド置換の中の本物の書き出し', "V=$(grep -n 'a' src > " + KEY + '); echo x'),
|
|
99
|
+
('b18 探す言葉の中の展開の本物の書き出し', 'grep -n -e "$(cat x > ' + ENV + ')" src/a.ts'),
|
|
100
|
+
('b19 探す言葉ではない引数(パス)の秘密', "grep -n -e 'a => b' src/a.ts " + KEY),
|
|
101
|
+
]
|
|
102
|
+
for label, cmd in DANGER:
|
|
103
|
+
r = decide(cmd)
|
|
104
|
+
check(label, (r['decision'], kind_of(r['reason'])), ('deny', 'danger'))
|
|
105
|
+
|
|
106
|
+
print()
|
|
107
|
+
if failures:
|
|
108
|
+
print(f'NG {len(failures)} 件')
|
|
109
|
+
for f in failures:
|
|
110
|
+
print(f' - {f}')
|
|
111
|
+
sys.exit(1)
|
|
112
|
+
print('すべて期待どおり')
|