@tyhld/conductor 0.12.121 → 0.12.122
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/policy.py
CHANGED
|
@@ -1525,11 +1525,24 @@ _KNOWN_TOOLS = frozenset({
|
|
|
1525
1525
|
'vercel', 'supabase', 'wrangler', 'prisma', 'drizzle-kit', 'fly', 'flyctl', 'heroku',
|
|
1526
1526
|
'netlify', 'gh', 'psql', 'dropdb', 'claude',
|
|
1527
1527
|
})
|
|
1528
|
+
#: git の全体オプション(前置きの旗)のうち、値を【次の語】で受け取る物。
|
|
1529
|
+
# ★ここが「git の前置きの旗」の唯一の正本。読み飛ばす処理(_git_subcommand・_git_cwd)も、
|
|
1530
|
+
# 道具の語の並び(_tool_words)も、この1つの集合を使う=同じ一覧を2つ持たない。
|
|
1531
|
+
# ★「=」で値を付ける形(--git-dir=…)は1語で済むので、ここには要らない。
|
|
1532
|
+
_GIT_GLOBAL_VALUE_FLAGS = frozenset({
|
|
1533
|
+
'-C', '-c', '--git-dir', '--work-tree', '--namespace', '--super-prefix',
|
|
1534
|
+
})
|
|
1535
|
+
|
|
1528
1536
|
# 値を1つ取る旗(語の並びから値ごと外す)。
|
|
1537
|
+
# ★git の前置きの旗(上の正本)も混ぜる。混ぜないと `git --git-dir <場所> commit -n` のように
|
|
1538
|
+
# 旗を挟んだだけで部分命令が読めなくなり、検査の省略の判定が外れる(便 65cd34ad の実測)。
|
|
1539
|
+
# ★supabase / prisma の全体の旗も同じ理由で足す(`supabase --workdir <場所> db push` が
|
|
1540
|
+
# 本番 DB の直接変更の判定から外れていた=同じ原因・便 65cd34ad の実測)。
|
|
1529
1541
|
_VALUE_FLAGS = frozenset({
|
|
1530
1542
|
'--scope', '-S', '--token', '-t', '--cwd', '--project-ref', '--app', '-a', '--config',
|
|
1531
1543
|
'-c', '-C', '--account-id', '--site', '--env', '-e', '--repo', '-R', '--schema',
|
|
1532
|
-
|
|
1544
|
+
'--workdir', '--dns-resolver', '--network-id', '--telemetry-information',
|
|
1545
|
+
}) | _GIT_GLOBAL_VALUE_FLAGS
|
|
1533
1546
|
|
|
1534
1547
|
# 前置き(npm / pnpm / yarn / npx)の、値を1つ取る旗(`--filter <部品>` など)。
|
|
1535
1548
|
_RUNNER_VALUE_FLAGS = frozenset({
|
|
@@ -1654,23 +1667,14 @@ def _main_push_danger(tokens, cwd):
|
|
|
1654
1667
|
start = [t.split('/')[-1] for t in tokens].index('git')
|
|
1655
1668
|
except ValueError:
|
|
1656
1669
|
return None
|
|
1657
|
-
# git の前置きの旗(-C
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
if any(c in p for c in '$`') or where is _UNKNOWN_DIR:
|
|
1665
|
-
where = _UNKNOWN_DIR
|
|
1666
|
-
else:
|
|
1667
|
-
p = os.path.expanduser(p)
|
|
1668
|
-
where = p if os.path.isabs(p) else os.path.join(where or os.getcwd(), p)
|
|
1669
|
-
elif flag == '-c' and args:
|
|
1670
|
-
args.pop(0)
|
|
1671
|
-
if not args or args[0] != 'push':
|
|
1670
|
+
# git の前置きの旗(-C 場所・-c 設定・--git-dir 場所 …)を読み飛ばして部分命令を取り出す。
|
|
1671
|
+
# ★旗の一覧と読み飛ばし方は _git_subcommand / _git_cwd の1か所に寄せてある
|
|
1672
|
+
# (以前はここだけ -C と -c しか読まず、`git --git-dir <場所> push origin main` が
|
|
1673
|
+
# 素通りしていた=便 65cd34ad の実測)。
|
|
1674
|
+
where = _git_cwd(tokens[start + 1:], cwd)
|
|
1675
|
+
sub, push_args = _git_subcommand(tokens[start + 1:])
|
|
1676
|
+
if sub != 'push':
|
|
1672
1677
|
return None
|
|
1673
|
-
push_args = args[1:]
|
|
1674
1678
|
positional = []
|
|
1675
1679
|
it = iter(push_args)
|
|
1676
1680
|
for t in it:
|
|
@@ -1732,10 +1736,8 @@ def _main_push_danger(tokens, cwd):
|
|
|
1732
1736
|
# ★いまの字面の判定(_danger_patterns)は残す。どちらかに当たれば止める=止まる形は1つも減らない。
|
|
1733
1737
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
1734
1738
|
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
'-C', '-c', '--git-dir', '--work-tree', '--namespace', '--super-prefix',
|
|
1738
|
-
})
|
|
1739
|
+
# ★git の全体オプション(前置きの旗)の一覧は _GIT_GLOBAL_VALUE_FLAGS が正本(上の方で定義)。
|
|
1740
|
+
# 道具の語の並び(_tool_words)もそれを混ぜて使う=同じ一覧を2つ持たない。
|
|
1739
1741
|
|
|
1740
1742
|
#: push の旗のうち、値を【次の語】で受け取る物(値が `-f` でも旗と読み違えないため)。
|
|
1741
1743
|
_PUSH_VALUE_FLAGS = frozenset({
|
|
@@ -1760,6 +1762,79 @@ def _git_subcommand(args):
|
|
|
1760
1762
|
return rest[0], rest[1:]
|
|
1761
1763
|
|
|
1762
1764
|
|
|
1765
|
+
def _git_cwd(args, cwd):
|
|
1766
|
+
"""git の前置きの旗を読んだ後の作業場所(`-C 場所` を反映)。
|
|
1767
|
+
|
|
1768
|
+
★旗の読み飛ばし方は _git_subcommand と同じ(一覧も _GIT_GLOBAL_VALUE_FLAGS の1つだけ)。
|
|
1769
|
+
★場所が変数で決まるときは _UNKNOWN_DIR(=確かめられない)を返す。
|
|
1770
|
+
"""
|
|
1771
|
+
where = cwd
|
|
1772
|
+
rest = list(args)
|
|
1773
|
+
while rest and rest[0].startswith('-') and rest[0] != '--':
|
|
1774
|
+
flag = rest.pop(0)
|
|
1775
|
+
if '=' in flag:
|
|
1776
|
+
continue
|
|
1777
|
+
if flag == '-C' and rest:
|
|
1778
|
+
p = rest.pop(0)
|
|
1779
|
+
if any(c in p for c in '$`') or where is _UNKNOWN_DIR:
|
|
1780
|
+
where = _UNKNOWN_DIR
|
|
1781
|
+
else:
|
|
1782
|
+
p = os.path.expanduser(p)
|
|
1783
|
+
where = p if os.path.isabs(p) else os.path.join(where or os.getcwd(), p)
|
|
1784
|
+
elif flag in _GIT_GLOBAL_VALUE_FLAGS and rest:
|
|
1785
|
+
rest.pop(0)
|
|
1786
|
+
return where
|
|
1787
|
+
|
|
1788
|
+
|
|
1789
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
1790
|
+
# git の危険な部分命令を【語(トークン)】で見る(DENY・便 65cd34ad)
|
|
1791
|
+
#
|
|
1792
|
+
# 【なぜ要るか(実地 便 5157164e・b29110f3)】
|
|
1793
|
+
# 危険の判定(_danger_patterns)は「git のすぐ後ろに部分命令が来る字面」だけを見ていたので、
|
|
1794
|
+
# 前置きの旗を1つ挟むだけで外れていた(実測で allow だった形):
|
|
1795
|
+
# ・git -C <場所> reset --hard / git -c <設定> reset --hard
|
|
1796
|
+
# ・git --work-tree <場所> reset --hard / git --namespace <名> reset --hard
|
|
1797
|
+
# ・git -C <場所> clean -fd / git -c <設定> clean -fdx
|
|
1798
|
+
# ・git -C <場所> credential fill / git -C <場所> credential-store get
|
|
1799
|
+
# しかも番人自身が「cd は1回だけ・以後は絶対パスか git -C を使う」と案内する(鉄則2)ので、
|
|
1800
|
+
# 職人はこの形に辿り着きやすい。実際 utatane の2便は `cd <写し> && …` を番人に止められた
|
|
1801
|
+
# 直後に `git -C <写し> …` へ書き換えており、禁止の reset --hard がそのまま通った。
|
|
1802
|
+
#
|
|
1803
|
+
# 【どう見るか】強い上書きの push(便 e619bd86)と同じ作りを使い回す。
|
|
1804
|
+
# ① _git_subcommand で git の全体オプションを読み飛ばして部分命令を取り出す。
|
|
1805
|
+
# ② 部分命令ごとに、危険の印を【位置を問わずに】探す。
|
|
1806
|
+
# ★理由の文は _danger_patterns と同じ字面を返す(番人の言い方を増やさない)。
|
|
1807
|
+
# ★つなぎ(; && || |)・入れ子($( ) ・` `)・包み(env・sudo・nohup・command・bash -c)・
|
|
1808
|
+
# 変数の展開には、_bypass_scan に相乗りすることで同じ判定が届く(番人のいつもの流儀)。
|
|
1809
|
+
# ★いまの字面の判定(_danger_patterns)は残す。どちらかに当たれば止める=止まる形は1つも減らない。
|
|
1810
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
1811
|
+
|
|
1812
|
+
def _git_clean_forced_dirs(rest) -> bool:
|
|
1813
|
+
"""`git clean` の後ろの語が「強制(-f/--force)」と「フォルダごと(-d)」の両方か。"""
|
|
1814
|
+
short = ''.join(a[1:] for a in rest if a.startswith('-') and not a.startswith('--'))
|
|
1815
|
+
long_names = {a.split('=', 1)[0] for a in rest if a.startswith('--')}
|
|
1816
|
+
return ('f' in short or '--force' in long_names) and 'd' in short
|
|
1817
|
+
|
|
1818
|
+
|
|
1819
|
+
def _git_token_danger(tokens):
|
|
1820
|
+
"""語の並びで見る git の危険な部分命令。危険なら理由を返す(_danger_patterns と同じ字面)。"""
|
|
1821
|
+
for i, t in enumerate(tokens):
|
|
1822
|
+
if _word_head(t) != 'git':
|
|
1823
|
+
continue
|
|
1824
|
+
sub, rest = _git_subcommand(tokens[i + 1:])
|
|
1825
|
+
if sub is None:
|
|
1826
|
+
continue
|
|
1827
|
+
sub = _word_head(sub)
|
|
1828
|
+
if sub == 'reset' and any(a.split('=', 1)[0] == '--hard' for a in rest):
|
|
1829
|
+
return 'git reset --hard'
|
|
1830
|
+
if sub == 'clean' and _git_clean_forced_dirs(rest):
|
|
1831
|
+
return 'git clean -fd'
|
|
1832
|
+
if (sub == 'credential' or sub.startswith('credential-')) \
|
|
1833
|
+
and rest[:1] and rest[0] in ('fill', 'get'):
|
|
1834
|
+
return 'git credential fill (合言葉の表示)'
|
|
1835
|
+
return None
|
|
1836
|
+
|
|
1837
|
+
|
|
1763
1838
|
def _push_force_mark(push_args):
|
|
1764
1839
|
"""push の後ろの語に、強い上書きの印が在れば その語 を返す(位置は問わない)。"""
|
|
1765
1840
|
i = 0
|
|
@@ -2192,10 +2267,56 @@ def _screen_launch_danger(tokens):
|
|
|
2192
2267
|
return None
|
|
2193
2268
|
|
|
2194
2269
|
|
|
2270
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
2271
|
+
# 道具+部分命令の形で止める危険を【語の並び】でも見る(DENY・便 65cd34ad)
|
|
2272
|
+
#
|
|
2273
|
+
# 【なぜ要るか(実測)】危険の判定(_danger_patterns)は全文の字面を見るので、道具と部分命令の
|
|
2274
|
+
# あいだに前置きの旗が1つ入るだけで外れていた(実測で allow だった形):
|
|
2275
|
+
# ・supabase --workdir <場所> db reset / supabase --workdir <場所> projects api-keys
|
|
2276
|
+
# ・vercel --cwd <場所> env pull / vercel --scope <組> env pull / vercel --token <値> env pull
|
|
2277
|
+
# ・gh -R <リポ> secret set <名> / gh --repo <リポ> secret set <名>
|
|
2278
|
+
# ・npm --prefix <場所> config get _authToken
|
|
2279
|
+
# =git の前置きの旗(_git_token_danger)と同じ原因なので、同じ形で塞ぐ。
|
|
2280
|
+
# 【どう見るか】実際に動く道具の語の並び(_tool_words=前置き・包み・値を取る旗を外した形)の
|
|
2281
|
+
# 先頭から当てる。★理由の文は _danger_patterns と同じ字面を返す(番人の言い方を増やさない)。
|
|
2282
|
+
# ★_danger_patterns の字面の判定は残す。どちらかに当たれば止める=止まる形は1つも減らない。
|
|
2283
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
2284
|
+
|
|
2285
|
+
#: (語の並びの先頭, 理由) の一覧。★理由は _danger_patterns と同じ字面にそろえる。
|
|
2286
|
+
_TOOL_DANGER_WORDS = (
|
|
2287
|
+
(('supabase', 'db', 'reset'), 'supabase db reset'),
|
|
2288
|
+
(('supabase', 'projects', 'api-keys'), 'supabase projects api-keys (鍵の表示)'),
|
|
2289
|
+
(('vercel', 'env', 'pull'), 'vercel env pull (本番の環境設定の取り寄せ)'),
|
|
2290
|
+
(('gh', 'auth', 'token'), 'gh auth token (合言葉の表示)'),
|
|
2291
|
+
(('gh', 'auth', 'git-credential', 'get'), 'gh auth git-credential get (合言葉の表示)'),
|
|
2292
|
+
(('gh', 'secret'), 'gh secret'),
|
|
2293
|
+
)
|
|
2294
|
+
|
|
2295
|
+
|
|
2296
|
+
def _tool_words_danger(words, tokens):
|
|
2297
|
+
"""道具の語の並びで見る危険。危険なら理由を返す(_danger_patterns と同じ字面)。"""
|
|
2298
|
+
for head, reason in _TOOL_DANGER_WORDS:
|
|
2299
|
+
if tuple(words[:len(head)]) == head:
|
|
2300
|
+
return reason
|
|
2301
|
+
if words[:2] == ['gh', 'auth'] and words[2:3] == ['status'] \
|
|
2302
|
+
and any(t == '--show-token' or (t.startswith('-') and not t.startswith('--')
|
|
2303
|
+
and 't' in t[1:]) for t in tokens):
|
|
2304
|
+
return 'gh auth status --show-token (合言葉の表示)'
|
|
2305
|
+
if words[:2] == ['npm', 'config'] and words[2:3] and words[2] in ('get', 'list', 'ls') \
|
|
2306
|
+
and any('_auth' in t.lower() for t in tokens):
|
|
2307
|
+
return 'npm config get _authToken (合言葉の表示)'
|
|
2308
|
+
return None
|
|
2309
|
+
|
|
2310
|
+
|
|
2195
2311
|
def _bypass_segment_danger(seg, tokens, cwd, command):
|
|
2196
2312
|
"""1セグメントの抜け道(main 直 push 以外)。"""
|
|
2197
2313
|
# ★強い上書きの push は、道具の語が読めなくても(包みの中でも)語の並びで見る(便 e619bd86)。
|
|
2198
2314
|
hit = _force_push_token_danger(tokens)
|
|
2315
|
+
if hit:
|
|
2316
|
+
return hit
|
|
2317
|
+
# ★git の危険な部分命令(reset --hard・clean -fd・credential)も、前置きの旗を飛ばして
|
|
2318
|
+
# 語の並びで見る(便 65cd34ad)。
|
|
2319
|
+
hit = _git_token_danger(tokens)
|
|
2199
2320
|
if hit:
|
|
2200
2321
|
return hit
|
|
2201
2322
|
# ★安全の決まりを省いた子の職人の起こし方も、同じく語の並びで見る(便 4b9e6e8b)。
|
|
@@ -2209,6 +2330,10 @@ def _bypass_segment_danger(seg, tokens, cwd, command):
|
|
|
2209
2330
|
words = _tool_words(tokens)
|
|
2210
2331
|
if not words:
|
|
2211
2332
|
return None
|
|
2333
|
+
# ★道具+部分命令の形の危険も、前置きの旗で外れないよう語の並びで見る(便 65cd34ad)。
|
|
2334
|
+
hit = _tool_words_danger(words, tokens)
|
|
2335
|
+
if hit:
|
|
2336
|
+
return hit
|
|
2212
2337
|
seg_low = seg.lower()
|
|
2213
2338
|
hit = _gh_api_danger(words, tokens, seg_low) or _http_github_danger(words, tokens, seg_low)
|
|
2214
2339
|
if hit:
|
|
@@ -4368,16 +4493,15 @@ def _disc_cd(cmds, toks):
|
|
|
4368
4493
|
|
|
4369
4494
|
|
|
4370
4495
|
def _disc_git_add(words):
|
|
4496
|
+
# ★git の前置きの旗は _git_subcommand で飛ばす(以前はここで -C と -c だけを読んでいたので
|
|
4497
|
+
# `git --git-dir <場所> add -A` が外れていた=便 65cd34ad の実測)。
|
|
4371
4498
|
if not words or words[0].split('/')[-1] != 'git':
|
|
4372
4499
|
return None
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
# git の全体の旗(-C 場所・-c 設定 は値を1つ取る)。
|
|
4376
|
-
i += 2 if words[i] in ('-C', '-c') else 1
|
|
4377
|
-
if i >= len(words) or words[i] != 'add':
|
|
4500
|
+
sub, rest = _git_subcommand(words[1:])
|
|
4501
|
+
if sub != 'add':
|
|
4378
4502
|
return None
|
|
4379
4503
|
after_dd = False
|
|
4380
|
-
for a in
|
|
4504
|
+
for a in rest:
|
|
4381
4505
|
if not after_dd and a == '--':
|
|
4382
4506
|
after_dd = True
|
|
4383
4507
|
continue
|
|
@@ -4406,14 +4530,13 @@ def _disc_git_commit_all(words):
|
|
|
4406
4530
|
手元の記録に入った(ai-kana の2便が続けて踏んだ)。`git add -A` と同じ「まとめて入れる」形なので、
|
|
4407
4531
|
同じ扱いで止める(止める物を足すだけ)。
|
|
4408
4532
|
"""
|
|
4533
|
+
# ★git の前置きの旗は _git_subcommand で飛ばす(以前はここで -C と -c だけを読んでいたので
|
|
4534
|
+
# `git --work-tree <場所> commit -a -m x` が外れていた=便 65cd34ad の実測)。
|
|
4409
4535
|
if not words or words[0].split('/')[-1] != 'git':
|
|
4410
4536
|
return None
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
i += 2 if words[i] in ('-C', '-c') else 1
|
|
4414
|
-
if i >= len(words) or words[i] != 'commit':
|
|
4537
|
+
sub, rest = _git_subcommand(words[1:])
|
|
4538
|
+
if sub != 'commit':
|
|
4415
4539
|
return None
|
|
4416
|
-
rest = words[i + 1:]
|
|
4417
4540
|
k = 0
|
|
4418
4541
|
while k < len(rest):
|
|
4419
4542
|
a = rest[k]
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""git の前置きの旗(-C 場所・-c 設定 など)を挟んだ危険な命令の試験(便 65cd34ad)。
|
|
3
|
+
|
|
4
|
+
実行: python3 scripts/hooks/test_git_prefix_flags.py
|
|
5
|
+
1件でも期待と違えば exit 1。
|
|
6
|
+
|
|
7
|
+
【なぜ要るか(実地 便 5157164e・b29110f3)】
|
|
8
|
+
危険の判定(_danger_patterns)は「git のすぐ後ろに部分命令が来る字面」だけを見ていたので、
|
|
9
|
+
前置きの旗を1つ挟むだけで外れていた。しかも番人自身が「cd は1回だけ・以後は絶対パスか
|
|
10
|
+
git -C を使う」と案内する(鉄則2)ので、職人はこの形に辿り着きやすい。
|
|
11
|
+
実際 utatane の2便は `cd <写し> && …` を番人に止められた直後に `git -C <写し> …` へ書き換え、
|
|
12
|
+
便で禁止されている戻しの命令がそのまま通った(職人の自己申告で発覚)。
|
|
13
|
+
|
|
14
|
+
【ここで固定すること】
|
|
15
|
+
(1) 実測で素通りだった形が止まる(★語で見る判定だけが止める=足した判定が効いている証拠)
|
|
16
|
+
(2) つないだ行・入れ子・包み・変数の展開にも判定が届く
|
|
17
|
+
(3) ★止めてはいけない普通の作業(git -C 場所 status・log・diff・fetch・checkout・switch・
|
|
18
|
+
add・commit・push(force なし)ほか)は止めない
|
|
19
|
+
(4) ★いまの字面の判定は1つも弱めていない(元から止まっていた形はそのまま止まる)
|
|
20
|
+
(5) git 以外の道具でも、同じ原因(前置きの旗)で外れていた形が止まる
|
|
21
|
+
(6) 前置きの旗の一覧は1か所だけ(同じ一覧を2つ持たない)
|
|
22
|
+
|
|
23
|
+
★見本の危険語は部品から組み立てる(番人の見本に危険語をそのまま書かない)。
|
|
24
|
+
"""
|
|
25
|
+
import os
|
|
26
|
+
import sys
|
|
27
|
+
|
|
28
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
29
|
+
|
|
30
|
+
import policy # noqa: E402
|
|
31
|
+
|
|
32
|
+
failures = []
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def check(label, got, want):
|
|
36
|
+
ok = got == want
|
|
37
|
+
if not ok:
|
|
38
|
+
failures.append(f'{label}: got={got!r} want={want!r}')
|
|
39
|
+
print(f'{"OK " if ok else "NG "} {label:72} {str(got)[:32]}')
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# ── 部品(危険語を直接書かない) ──
|
|
43
|
+
RESET = 're' + 'set'
|
|
44
|
+
HARD = '--ha' + 'rd'
|
|
45
|
+
CLEAN = 'cle' + 'an'
|
|
46
|
+
FD = '-' + 'fd'
|
|
47
|
+
CRED = 'creden' + 'tial'
|
|
48
|
+
WORK = '/tmp/claude-1000' # 判定に使う作業場所(実物のリポを指さない)
|
|
49
|
+
REL = 'node_modules/.tmp-karaburi-65cd34ad' # 便 b29110f3 が実際に使った相対の置き場
|
|
50
|
+
|
|
51
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
52
|
+
# (1) 実測で素通りだった形(CC1 の再現と、この便での測り直し)
|
|
53
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
54
|
+
LEAKED = [
|
|
55
|
+
f'git -C {WORK}/x {RESET} {HARD} origin/main',
|
|
56
|
+
f'git -C {REL} {RESET} {HARD} HEAD',
|
|
57
|
+
f'git -c core.pager=cat {RESET} {HARD}',
|
|
58
|
+
f'git --work-tree {WORK}/x {RESET} {HARD} HEAD',
|
|
59
|
+
f'git --namespace probe {RESET} {HARD} HEAD',
|
|
60
|
+
f'git -C {WORK}/x -c core.pager=cat {RESET} {HARD} --quiet abc',
|
|
61
|
+
f'git -C {WORK}/x {CLEAN} {FD}',
|
|
62
|
+
f'git -c core.pager=cat {CLEAN} {FD}x',
|
|
63
|
+
f'git -C {WORK}/x {CRED} fill',
|
|
64
|
+
f'git -C {WORK}/x {CRED}-store get',
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
print('\n=== (1) 実測で素通りだった形が止まる ===')
|
|
68
|
+
for cmd in LEAKED:
|
|
69
|
+
r = policy.decide_bash(cmd, cwd=WORK)
|
|
70
|
+
check(f'deny {cmd[:62]}', r['decision'], policy.DENY)
|
|
71
|
+
|
|
72
|
+
print('\n=== (1b) ★この形は【語で見る判定】が止めている(足した判定が効いている証拠) ===')
|
|
73
|
+
for cmd in LEAKED:
|
|
74
|
+
got = policy._git_token_danger(policy.tokens_of(cmd))
|
|
75
|
+
check(f'語で見る判定が当たる {cmd[:52]}', bool(got), True)
|
|
76
|
+
|
|
77
|
+
print('\n=== (1c) 旗の読み飛ばしで外れていた「まとめて記録に入れる形」も止まる ===')
|
|
78
|
+
for cmd in [
|
|
79
|
+
f'git --git-dir {WORK}/x/.git add -A',
|
|
80
|
+
f'git --work-tree {WORK}/x add --all',
|
|
81
|
+
f'git --work-tree {WORK}/x commit -a -m x',
|
|
82
|
+
f'git --git-dir {WORK}/x/.git commit --all -m x',
|
|
83
|
+
]:
|
|
84
|
+
r = policy.decide_bash(cmd, cwd=WORK)
|
|
85
|
+
check(f'deny {cmd[:62]}', r['decision'], policy.DENY)
|
|
86
|
+
|
|
87
|
+
print('\n=== (1d) 旗の読み飛ばしで外れていた「保護ブランチへの直 push」も止まる ===')
|
|
88
|
+
for cmd in [
|
|
89
|
+
f'git --git-dir {WORK}/x/.git push origin main',
|
|
90
|
+
f'git --work-tree {WORK}/x push origin main',
|
|
91
|
+
]:
|
|
92
|
+
r = policy.decide_bash(cmd, cwd=WORK)
|
|
93
|
+
check(f'deny {cmd[:62]}', r['decision'], policy.DENY)
|
|
94
|
+
|
|
95
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
96
|
+
# (2) つなぎ・入れ子・包み・変数の展開にも届く
|
|
97
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
98
|
+
BASE = f'git -C {WORK}/x {RESET} {HARD} HEAD'
|
|
99
|
+
print('\n=== (2) つなぎ・入れ子・包み・変数の展開にも判定が届く ===')
|
|
100
|
+
for cmd in [
|
|
101
|
+
f'env X=1 {BASE}',
|
|
102
|
+
f'nohup {BASE}',
|
|
103
|
+
f'command {BASE}',
|
|
104
|
+
f'sudo {BASE}',
|
|
105
|
+
f'time {BASE}',
|
|
106
|
+
f'echo ok; {BASE}',
|
|
107
|
+
f'echo ok && {BASE}',
|
|
108
|
+
f'echo ok | {BASE}',
|
|
109
|
+
f'echo ok\n{BASE}',
|
|
110
|
+
f'echo $({BASE})',
|
|
111
|
+
f'`{BASE}`',
|
|
112
|
+
f'bash -c "{BASE}"',
|
|
113
|
+
f'sh -c "{BASE}"',
|
|
114
|
+
f'D={WORK}/x; git -C "$D" {RESET} {HARD} HEAD',
|
|
115
|
+
f'xargs {BASE}',
|
|
116
|
+
]:
|
|
117
|
+
r = policy.decide_bash(cmd, cwd=WORK)
|
|
118
|
+
check(f'deny {cmd[:62]!r}', r['decision'], policy.DENY)
|
|
119
|
+
|
|
120
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
121
|
+
# (3) ★止めてはいけない普通の作業は止めない
|
|
122
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
123
|
+
ALLOWED_SHAPES = [
|
|
124
|
+
f'git -C {WORK}/x status --porcelain',
|
|
125
|
+
f'git -C {WORK}/x log --oneline -3',
|
|
126
|
+
f'git -C {WORK}/x diff -- src docs',
|
|
127
|
+
f'git -C {WORK}/x fetch origin',
|
|
128
|
+
f'git -C {WORK}/x checkout -- src',
|
|
129
|
+
f'git -C {WORK}/x checkout probe',
|
|
130
|
+
f'git -C {WORK}/x switch -c feat/probe --no-track origin/main',
|
|
131
|
+
f'git -C {WORK}/x add src/a.ts',
|
|
132
|
+
f'git -C {WORK}/x commit -m x',
|
|
133
|
+
f'git -C {WORK}/x push origin feat/probe',
|
|
134
|
+
f'git -C {WORK}/x stash list',
|
|
135
|
+
f'git -C {WORK}/x branch --no-track feat/probe origin/main',
|
|
136
|
+
f'git -C {WORK}/x rev-parse --abbrev-ref HEAD',
|
|
137
|
+
f'git -C {WORK}/x merge-base --is-ancestor abc origin/main',
|
|
138
|
+
# 危険な印の付かない同じ部分命令(戻し方が違う・空振りの掃除・読むだけ)
|
|
139
|
+
f'git -C {WORK}/x {RESET} --soft HEAD~1',
|
|
140
|
+
f'git -C {WORK}/x {RESET} --mixed HEAD',
|
|
141
|
+
f'git -C {WORK}/x {RESET} -- src/a.ts',
|
|
142
|
+
f'git -C {WORK}/x {CLEAN} -n',
|
|
143
|
+
f'git -C {WORK}/x {CLEAN} -d --dry-run',
|
|
144
|
+
f'git -C {WORK}/x {CRED} approve',
|
|
145
|
+
# 探す言葉として書いた形(調べる作業を止めない)
|
|
146
|
+
f"git grep -n '{RESET} {HARD}' -- skills",
|
|
147
|
+
f"git grep -n '{CLEAN} {FD}' -- skills docs",
|
|
148
|
+
]
|
|
149
|
+
|
|
150
|
+
print('\n=== (3) 止めてはいけない形は止めない ===')
|
|
151
|
+
for cmd in ALLOWED_SHAPES:
|
|
152
|
+
r = policy.decide_bash(cmd, cwd=WORK)
|
|
153
|
+
check(f'not deny {cmd[:58]}', r['decision'] != policy.DENY, True)
|
|
154
|
+
|
|
155
|
+
print('\n=== (3b) 語で見る判定も、止めてはいけない形には当たらない ===')
|
|
156
|
+
for cmd in ALLOWED_SHAPES:
|
|
157
|
+
got = policy._git_token_danger(policy.tokens_of(cmd))
|
|
158
|
+
check(f'当たらない {cmd[:58]}', got, None)
|
|
159
|
+
|
|
160
|
+
# ★探す言葉の中に git の危険語を書いた形(`grep -rn 'git <戻しの命令>' docs`)は、
|
|
161
|
+
# この便の【前から】字面の判定で deny になる(便 915694ac で免じたのは消す命令だけ)。
|
|
162
|
+
# この便は字面の判定を1文字も変えていないので、その振る舞いもそのまま残る=ここで固定する。
|
|
163
|
+
# ★語で見る判定は、探す言葉には当たらない(=この便が新しく止めた物ではないことの証拠)。
|
|
164
|
+
print('\n=== (3c) 探す言葉の中の危険語は、この便の前からの振る舞いのまま ===')
|
|
165
|
+
for cmd in [
|
|
166
|
+
f"grep -rn 'git {RESET} {HARD}' skills docs",
|
|
167
|
+
f"grep -rn 'git {CLEAN} {FD}' skills docs",
|
|
168
|
+
]:
|
|
169
|
+
check(f'今までどおり deny {cmd[:52]}',
|
|
170
|
+
policy.decide_bash(cmd, cwd=WORK)['decision'], policy.DENY)
|
|
171
|
+
check(f'語で見る判定は当たらない {cmd[:46]}',
|
|
172
|
+
policy._git_token_danger(policy.tokens_of(cmd)), None)
|
|
173
|
+
|
|
174
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
175
|
+
# (4) ★いまの字面の判定を弱めていない(元から止まっていた形はそのまま)
|
|
176
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
177
|
+
print('\n=== (4) 字面の判定はそのまま残っている(二層で止める) ===')
|
|
178
|
+
for cmd in [
|
|
179
|
+
f'git {RESET} {HARD} origin/main',
|
|
180
|
+
f'git {CLEAN} {FD}',
|
|
181
|
+
f'git {CRED} fill',
|
|
182
|
+
]:
|
|
183
|
+
check(f'字面の判定が当たる {cmd[:52]}',
|
|
184
|
+
bool(policy._danger_patterns(cmd.lower())), True)
|
|
185
|
+
|
|
186
|
+
print('\n=== (4b) 元から止まっていた形は今までどおり止まる ===')
|
|
187
|
+
for cmd in [
|
|
188
|
+
f'git {RESET} {HARD} HEAD',
|
|
189
|
+
f'cd {WORK}/x && git {RESET} {HARD} abc',
|
|
190
|
+
f'git --git-dir={WORK}/x/.git {RESET} {HARD}',
|
|
191
|
+
f'git {CLEAN} {FD}x',
|
|
192
|
+
f'git -C {WORK}/x push --force origin probe',
|
|
193
|
+
f'git -C {WORK}/x push origin main',
|
|
194
|
+
f'git -C {WORK}/x add -A',
|
|
195
|
+
f'git -C {WORK}/x commit -am x',
|
|
196
|
+
]:
|
|
197
|
+
r = policy.decide_bash(cmd, cwd=WORK)
|
|
198
|
+
check(f'deny {cmd[:62]}', r['decision'], policy.DENY)
|
|
199
|
+
|
|
200
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
201
|
+
# (5) git 以外の道具でも、同じ原因(前置きの旗)で外れていた形
|
|
202
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
203
|
+
print('\n=== (5) ほかの道具の前置きの旗でも外れない ===')
|
|
204
|
+
for cmd in [
|
|
205
|
+
f'supabase --workdir {WORK}/x db push',
|
|
206
|
+
f'supabase --dns-resolver https db push',
|
|
207
|
+
f'supabase --network-id probe db push',
|
|
208
|
+
f'supabase --workdir {WORK}/x db {RESET}',
|
|
209
|
+
f'supabase --workdir {WORK}/x projects api-keys',
|
|
210
|
+
f'prisma --telemetry-information probe db push',
|
|
211
|
+
f'vercel --cwd {WORK}/x env pull',
|
|
212
|
+
'vercel --scope probe env pull',
|
|
213
|
+
'vercel --token probe env pull',
|
|
214
|
+
'gh -R tyhld/conductor secret set X',
|
|
215
|
+
'gh --repo tyhld/conductor secret set X',
|
|
216
|
+
f'npm --prefix {WORK}/x config get _authToken',
|
|
217
|
+
]:
|
|
218
|
+
r = policy.decide_bash(cmd, cwd=WORK)
|
|
219
|
+
check(f'deny {cmd[:62]}', r['decision'], policy.DENY)
|
|
220
|
+
|
|
221
|
+
print('\n=== (5b) 前置きの旗が付いても関門は外れない ===')
|
|
222
|
+
for cmd in [
|
|
223
|
+
f'supabase --workdir {WORK}/x functions deploy probe',
|
|
224
|
+
f'wrangler --cwd {WORK}/x deploy',
|
|
225
|
+
f'npm --prefix {WORK}/x publish',
|
|
226
|
+
]:
|
|
227
|
+
r = policy.decide_bash(cmd, cwd=WORK)
|
|
228
|
+
check(f'gate {cmd[:62]}', r['decision'], policy.GATE)
|
|
229
|
+
|
|
230
|
+
print('\n=== (5c) 読むだけの普通の作業は今までどおり通る ===')
|
|
231
|
+
for cmd in [
|
|
232
|
+
f'supabase --workdir {WORK}/x status',
|
|
233
|
+
f'vercel --cwd {WORK}/x ls',
|
|
234
|
+
'gh -R tyhld/conductor pr checks 1',
|
|
235
|
+
f'npm --prefix {WORK}/x ls',
|
|
236
|
+
]:
|
|
237
|
+
r = policy.decide_bash(cmd, cwd=WORK)
|
|
238
|
+
check(f'not deny {cmd[:58]}', r['decision'] != policy.DENY, True)
|
|
239
|
+
|
|
240
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
241
|
+
# (6) 前置きの旗の一覧は1か所だけ(同じ一覧を2つ持たない)
|
|
242
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
243
|
+
print('\n=== (6) 前置きの旗の一覧は1つの正本から使い回す ===')
|
|
244
|
+
check('git の前置きの旗の正本が在る',
|
|
245
|
+
sorted(policy._GIT_GLOBAL_VALUE_FLAGS),
|
|
246
|
+
sorted({'-C', '-c', '--git-dir', '--work-tree', '--namespace', '--super-prefix'}))
|
|
247
|
+
check('道具の語の並びも同じ正本を混ぜて使う',
|
|
248
|
+
policy._GIT_GLOBAL_VALUE_FLAGS <= policy._VALUE_FLAGS, True)
|
|
249
|
+
check('部分命令の取り出しも正本で旗を飛ばす',
|
|
250
|
+
policy._git_subcommand(['--work-tree', f'{WORK}/x', RESET, HARD])[0], RESET)
|
|
251
|
+
check('作業場所の読み取りも正本で旗を飛ばす',
|
|
252
|
+
policy._git_cwd(['--namespace', 'probe', '-C', f'{WORK}/x'], None), f'{WORK}/x')
|
|
253
|
+
|
|
254
|
+
print()
|
|
255
|
+
if failures:
|
|
256
|
+
print(f'FAIL {len(failures)} 件')
|
|
257
|
+
for f in failures:
|
|
258
|
+
print(f' - {f}')
|
|
259
|
+
sys.exit(1)
|
|
260
|
+
print('ALL PASS')
|
|
@@ -271,6 +271,17 @@ DENY_CASES = [
|
|
|
271
271
|
'psql -c "DROP TABLE users"',
|
|
272
272
|
'gh secret set X',
|
|
273
273
|
'supabase db reset',
|
|
274
|
+
# ★git の前置きの旗を挟んだ形(便 65cd34ad・実測で allow だった穴)。
|
|
275
|
+
'git -C /tmp/claude-1000/x reset --hard origin/main',
|
|
276
|
+
'git -c core.pager=cat reset --hard HEAD',
|
|
277
|
+
'git --work-tree /tmp/claude-1000/x reset --hard HEAD',
|
|
278
|
+
'git -C /tmp/claude-1000/x clean -fd',
|
|
279
|
+
'git -C /tmp/claude-1000/x credential fill',
|
|
280
|
+
# ★ほかの道具でも前置きの旗で外れていた形(同じ原因・便 65cd34ad)。
|
|
281
|
+
'supabase --workdir /tmp/claude-1000/x db reset',
|
|
282
|
+
'vercel --cwd /tmp/claude-1000/x env pull',
|
|
283
|
+
'gh -R tyhld/conductor secret set X',
|
|
284
|
+
'npm --prefix /tmp/claude-1000/x config get _authToken',
|
|
274
285
|
]
|
|
275
286
|
|
|
276
287
|
print('\n=== (b) 危険(秘密の持ち出し・破壊)は deny ===')
|