@routinecrew/routinecode 2.31.58 → 2.31.61
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/bin/cli.sh +35 -1
- package/bin/prompt-vault.js +1 -1
- package/bin/rc-login.js +23 -32
- package/bin/rc-team.js +592 -0
- package/bin/setup.js +1 -1
- package/hooks/hooks-config.json +9 -0
- package/hooks/lib/block_message.py +21 -19
- package/hooks/lib/i18n.py +10 -10
- package/hooks/lib/rm_guard.py +276 -0
- package/hooks/lib/secret_filter.py +155 -10
- package/hooks/pre-account-guard.sh +1 -1
- package/hooks/pre-agent-spawn.mjs +1 -1
- package/hooks/pre-askuser-guard.sh +3 -0
- package/hooks/pre-bash-guard.sh +18 -59
- package/hooks/pre-credit-guard.sh +3 -3
- package/hooks/pre-grep-guard.sh +7 -0
- package/hooks/pre-planmode-guard.sh +32 -0
- package/hooks/pre-read-guard.sh +8 -0
- package/hooks/session-start.sh +88 -10
- package/hooks/tests/cd-bypass.test.py +11 -1
- package/hooks/tests/design09-client.test.py +10 -0
- package/hooks/tests/dev-mode.test.py +6 -3
- package/hooks/tests/in-project-relax.test.py +14 -6
- package/hooks/tests/rm-guard.test.py +108 -0
- package/hooks/tests/secret-guard-bypass.test.sh +107 -0
- package/hooks/tests/secret-guard.test.sh +60 -12
- package/hooks/tests/secret-premask.test.py +13 -0
- package/hooks/user-prompt-submit.sh +7 -7
- package/mcp-db-manager/dist/analyzers/duplicate-detector.js +1 -1
- package/mcp-db-manager/dist/core/model-parser.js +1 -1
- package/mcp-db-manager/dist/core/schema-reader.js +1 -1
- package/mcp-db-manager/dist/executors/migration-executor.js +1 -1
- package/mcp-db-manager/dist/generators/migration-generator.js +1 -1
- package/mcp-db-manager/dist/index.js +1 -1
- package/mcp-db-manager/dist/validators/schema-validator.js +1 -1
- package/mcp-dev-tester/dist/analyzers/auth-diagnoser.js +1 -1
- package/mcp-dev-tester/dist/analyzers/backend-analyzer.js +1 -1
- package/mcp-dev-tester/dist/analyzers/endpoint-diagnoser.js +1 -1
- package/mcp-dev-tester/dist/analyzers/frontend-analyzer.js +1 -1
- package/mcp-dev-tester/dist/analyzers/runtime-diagnoser.js +1 -1
- package/mcp-dev-tester/dist/analyzers/type-comparator.js +1 -1
- package/mcp-dev-tester/dist/analyzers/validation-diagnoser.js +1 -1
- package/mcp-dev-tester/dist/attestation.js +1 -1
- package/mcp-dev-tester/dist/browser/playwright-manager.js +1 -1
- package/mcp-dev-tester/dist/browser/ui-tester.js +1 -1
- package/mcp-dev-tester/dist/config/project-config.js +1 -1
- package/mcp-dev-tester/dist/index.js +1 -1
- package/mcp-dev-tester/dist/testers/api-tester.js +1 -1
- package/mcp-doc-fetcher/dist/index.js +1 -1
- package/mcp-html-renderer/dist/index.js +1 -1
- package/mcp-html-renderer/dist/preview.js +1 -1
- package/mcp-html-renderer/dist/template-engine.js +1 -1
- package/mcp-intelligence/dist/concept-catalog.js +1 -1
- package/mcp-intelligence/dist/concept-server-proxy.js +1 -1
- package/mcp-intelligence/dist/config-auth.js +1 -1
- package/mcp-intelligence/dist/contracts.generated.js +1 -1
- package/mcp-intelligence/dist/domain-templates.js +1 -1
- package/mcp-intelligence/dist/grounding.js +1 -1
- package/mcp-intelligence/dist/handlers.js +1 -1
- package/mcp-intelligence/dist/index.js +1 -1
- package/mcp-intelligence/dist/intelligence-file.js +1 -1
- package/mcp-intelligence/dist/knowledge-critic.js +1 -1
- package/mcp-intelligence/dist/knowledge-handlers.js +1 -1
- package/mcp-intelligence/dist/mention-extractor.js +1 -1
- package/mcp-intelligence/dist/provenance.js +1 -1
- package/mcp-intelligence/dist/semantic-embedder.js +1 -1
- package/mcp-log-watcher/dist/config-auth.js +1 -1
- package/mcp-log-watcher/dist/file-watcher.js +1 -1
- package/mcp-log-watcher/dist/index.js +1 -1
- package/mcp-log-watcher/dist/known-solutions.js +1 -1
- package/mcp-log-watcher/dist/log-store.js +1 -1
- package/mcp-log-watcher/dist/websocket-server.js +1 -1
- package/mcp-plan-manager/dist/__tests__/plan-parser.test.js +1 -1
- package/mcp-plan-manager/dist/file-ops.js +1 -1
- package/mcp-plan-manager/dist/index.js +1 -1
- package/mcp-plan-manager/dist/plan-parser.js +1 -1
- package/mcp-project-context/dist/git-ops.js +1 -1
- package/mcp-project-context/dist/index.js +1 -1
- package/mcp-project-context/dist/project-analysis.js +1 -1
- package/mcp-routinecode/dist/agent-tracker.js +1 -1
- package/mcp-routinecode/dist/attestation.js +1 -1
- package/mcp-routinecode/dist/blast-radius.js +1 -1
- package/mcp-routinecode/dist/changeset.js +1 -1
- package/mcp-routinecode/dist/config-auth.js +1 -1
- package/mcp-routinecode/dist/contracts.generated.js +1 -1
- package/mcp-routinecode/dist/coverage.js +1 -1
- package/mcp-routinecode/dist/explorer-advisor.js +1 -1
- package/mcp-routinecode/dist/failure-tracker.js +1 -1
- package/mcp-routinecode/dist/file-lock-registry.js +1 -1
- package/mcp-routinecode/dist/file-risk-scorer.js +1 -1
- package/mcp-routinecode/dist/index.js +1 -1
- package/mcp-routinecode/dist/known-solutions.js +1 -1
- package/mcp-routinecode/dist/ledger-miner.js +1 -1
- package/mcp-routinecode/dist/observed-draft.js +1 -1
- package/mcp-routinecode/dist/pattern-matcher.js +1 -1
- package/mcp-routinecode/dist/route-match.js +1 -1
- package/mcp-routinecode/dist/routines.js +1 -1
- package/mcp-routinecode/dist/rule-engine.js +1 -1
- package/mcp-routinecode/dist/rule-promoter.js +1 -1
- package/mcp-routinecode/dist/telemetry-analyzer.js +1 -1
- package/mcp-routinecode/dist/test-runner.js +1 -1
- package/mcp-routinecode/dist/verification.js +0 -0
- package/mcp-routinecode/dist/viral-loop.d.ts +68 -0
- package/mcp-routinecode/dist/viral-loop.js +1 -1
- package/package.json +1 -1
- package/plugin/agents/analyzer.md.sealed +1 -1
- package/plugin/agents/crawler.md.sealed +1 -1
- package/plugin/agents/explorer.md.sealed +1 -1
- package/plugin/agents/implementor.md.sealed +1 -1
- package/plugin/agents/looker.md.sealed +1 -1
- package/plugin/agents/planner.md.sealed +1 -1
- package/plugin/agents/recorder.md.sealed +1 -1
- package/plugin/agents/reviewer.md.sealed +1 -1
- package/plugin/agents/verifier.md.sealed +1 -1
- package/plugin/commands/analyze.md.sealed +1 -1
- package/plugin/commands/plan.md.sealed +1 -1
- package/plugin/commands/rc.md.sealed +1 -1
- package/plugin/commands/receipt.md.sealed +1 -1
- package/plugin/commands/recharge.md.sealed +1 -0
- package/plugin/commands/routines.md.sealed +1 -1
- package/plugin/commands/share.md.sealed +1 -1
- package/plugin/routinecode-prompt.md.sealed +1 -1
package/hooks/session-start.sh
CHANGED
|
@@ -182,6 +182,17 @@ except:
|
|
|
182
182
|
fi
|
|
183
183
|
|
|
184
184
|
# --- 2. 자동 업데이트 체크 (동기, 세션 시작 시 즉시 반영) ---
|
|
185
|
+
# npm 전역 재설치는 세션·프로세스 그룹에서 분리해 실행하고 끝날 때까지 기다린다.
|
|
186
|
+
# npm 은 도중에 죽으면 구버전을 .routinecode-XXXX 로 치워 둔 채 끝나 `routinecode: command not found` 가 된다
|
|
187
|
+
# (실측: 2.31.58→2.31.60 설치를 0.6s 이후 TERM/KILL 하면 bin·패키지 모두 소실). 창 닫힘·훅 종료로
|
|
188
|
+
# 이 훅이 죽어도 분리된 npm 은 끝까지 설치를 마친다.
|
|
189
|
+
_rc_npm_detached() {
|
|
190
|
+
python3 - "$@" <<'PYEOF'
|
|
191
|
+
import subprocess, sys
|
|
192
|
+
p = subprocess.Popen(sys.argv[1:], start_new_session=True, stdin=subprocess.DEVNULL)
|
|
193
|
+
sys.exit(p.wait())
|
|
194
|
+
PYEOF
|
|
195
|
+
}
|
|
185
196
|
UPDATE_LOCK="$RC_RUNDIR/routinecode-updating.lock"
|
|
186
197
|
|
|
187
198
|
# Stale lock detection: if lock file is older than 10 minutes, remove it
|
|
@@ -280,7 +291,7 @@ except: print('')
|
|
|
280
291
|
rm -f "$UPDATE_LOCK"
|
|
281
292
|
elif [ -w "$GLOBAL_DIR" ]; then
|
|
282
293
|
# 권한 있음 (macOS homebrew, nvm, volta 등)
|
|
283
|
-
if npm install -g "@routinecrew/routinecode@${LATEST_VERSION}" --@routinecrew:registry=https://registry.npmjs.org > "$UPDATE_LOG" 2>&1 || npm install -g "@routinecrew/routinecode@${LATEST_VERSION}" --@routinecrew:registry=https://registry.npmjs.org --cache "$(mktemp -d)" >> "$UPDATE_LOG" 2>&1; then
|
|
294
|
+
if _rc_npm_detached npm install -g "@routinecrew/routinecode@${LATEST_VERSION}" --@routinecrew:registry=https://registry.npmjs.org > "$UPDATE_LOG" 2>&1 || _rc_npm_detached npm install -g "@routinecrew/routinecode@${LATEST_VERSION}" --@routinecrew:registry=https://registry.npmjs.org --cache "$(mktemp -d)" >> "$UPDATE_LOG" 2>&1; then
|
|
284
295
|
UPDATE_OK=true
|
|
285
296
|
# 신버전 setup 재실행(비대화) — 플러그인 마켓플레이스/훅 경로 재등록.
|
|
286
297
|
# 이것 없이는 settings.json 의 플러그인 미등록 결함이 자동업데이트로 치유되지 않는다.
|
|
@@ -295,7 +306,7 @@ except: print('')
|
|
|
295
306
|
# root로 변경하여 같은 디렉토리의 claude 바이너리 권한을 깨뜨림
|
|
296
307
|
USER_PREFIX="$HOME/.routinecode/global"
|
|
297
308
|
mkdir -p "$USER_PREFIX"
|
|
298
|
-
if npm install -g "@routinecrew/routinecode@${LATEST_VERSION}" --@routinecrew:registry=https://registry.npmjs.org --prefix="$USER_PREFIX" > "$UPDATE_LOG" 2>&1 || npm install -g "@routinecrew/routinecode@${LATEST_VERSION}" --@routinecrew:registry=https://registry.npmjs.org --prefix="$USER_PREFIX" --cache "$(mktemp -d)" >> "$UPDATE_LOG" 2>&1; then
|
|
309
|
+
if _rc_npm_detached npm install -g "@routinecrew/routinecode@${LATEST_VERSION}" --@routinecrew:registry=https://registry.npmjs.org --prefix="$USER_PREFIX" > "$UPDATE_LOG" 2>&1 || _rc_npm_detached npm install -g "@routinecrew/routinecode@${LATEST_VERSION}" --@routinecrew:registry=https://registry.npmjs.org --prefix="$USER_PREFIX" --cache "$(mktemp -d)" >> "$UPDATE_LOG" 2>&1; then
|
|
299
310
|
# 사용자 bin에 심볼릭 링크 생성
|
|
300
311
|
USER_BIN="$HOME/.local/bin"
|
|
301
312
|
mkdir -p "$USER_BIN"
|
|
@@ -592,14 +603,43 @@ try:
|
|
|
592
603
|
|
|
593
604
|
url = f'{server_url}/api/v1/provision'
|
|
594
605
|
|
|
595
|
-
|
|
596
|
-
|
|
606
|
+
# 팀 귀속(docs/30 §3.5): 이전 config 의 teamTenantId 로 재발급해야 자가치유가 팀 사용자를
|
|
607
|
+
# 개인으로 되돌리지 않는다. 개인 사용자(teamTenantId 없음)는 기존과 동일하게 빈 본문.
|
|
608
|
+
team_tid = None
|
|
609
|
+
team_name = None
|
|
610
|
+
try:
|
|
611
|
+
_pc = json.load(open(config_path))
|
|
612
|
+
_t = _pc.get('teamTenantId')
|
|
613
|
+
if isinstance(_t, int) and _t > 0:
|
|
614
|
+
team_tid, team_name = _t, _pc.get('teamName')
|
|
615
|
+
except Exception:
|
|
616
|
+
pass
|
|
617
|
+
|
|
618
|
+
def _provision_once(tok, tid):
|
|
619
|
+
req = urllib.request.Request(url, data=json.dumps({'tenantId': tid} if tid else {}).encode(), method='POST', headers={
|
|
597
620
|
'Authorization': f'Bearer {tok}',
|
|
598
621
|
'Content-Type': 'application/json',
|
|
599
622
|
})
|
|
600
623
|
resp = urllib.request.urlopen(req, timeout=5)
|
|
601
624
|
return json.loads(resp.read().decode())
|
|
602
625
|
|
|
626
|
+
def _provision(tok):
|
|
627
|
+
global team_tid
|
|
628
|
+
if not team_tid:
|
|
629
|
+
return _provision_once(tok, None)
|
|
630
|
+
try:
|
|
631
|
+
return _provision_once(tok, team_tid)
|
|
632
|
+
except urllib.error.HTTPError as te:
|
|
633
|
+
# 팀에서 빠진 경우(403 TEAM_TENANT_FORBIDDEN)만 개인으로 재발급. 토큰 만료 403 은 그대로 위로.
|
|
634
|
+
try:
|
|
635
|
+
code = json.loads(te.read().decode() or '{}').get('code')
|
|
636
|
+
except Exception:
|
|
637
|
+
code = None
|
|
638
|
+
if te.code == 403 and code == 'TEAM_TENANT_FORBIDDEN':
|
|
639
|
+
team_tid = None
|
|
640
|
+
return _provision_once(tok, None)
|
|
641
|
+
raise
|
|
642
|
+
|
|
603
643
|
def _save_creds():
|
|
604
644
|
import tempfile as _tf
|
|
605
645
|
cd = os.path.dirname(creds_path)
|
|
@@ -717,6 +757,11 @@ try:
|
|
|
717
757
|
# 기존에 사용자가 지정한 authUrl 은 보존(있으면).
|
|
718
758
|
if prior.get('authUrl'):
|
|
719
759
|
config['authUrl'] = prior['authUrl']
|
|
760
|
+
# 팀 귀속 보존: 팀으로 재발급이 실제 적용됐을 때만(teamApplied!=False) 팀 필드를 유지.
|
|
761
|
+
if team_tid and result.get('teamApplied') is not False:
|
|
762
|
+
config['teamTenantId'] = result.get('issuedTenantId') or team_tid
|
|
763
|
+
if team_name:
|
|
764
|
+
config['teamName'] = team_name
|
|
720
765
|
# 무효화 잔재는 새 config 에 절대 싣지 않는다(명시).
|
|
721
766
|
config.pop('apiKeyInvalidReason', None)
|
|
722
767
|
config.pop('apiKeyInvalidatedAt', None)
|
|
@@ -1452,10 +1497,43 @@ except: print('')
|
|
|
1452
1497
|
fi
|
|
1453
1498
|
fi
|
|
1454
1499
|
|
|
1455
|
-
# ---
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1500
|
+
# --- 권한 확인창 노출 감지: 프로젝트/관리 설정이 RoutineCode 의 bypass·sandbox off 를 덮어쓰면
|
|
1501
|
+
# Claude Code 확인창이 일반 명령마다 뜬다(사용자 설정보다 우선). 원인을 1줄로 알린다.
|
|
1502
|
+
PERM_WARN=$(python3 - "$PWD" <<'PYEOF' 2>/dev/null
|
|
1503
|
+
import json, os, sys
|
|
1504
|
+
cwd = sys.argv[1]
|
|
1505
|
+
srcs = [os.path.join(cwd, '.claude', 'settings.json'), os.path.join(cwd, '.claude', 'settings.local.json'),
|
|
1506
|
+
'/Library/Application Support/ClaudeCode/managed-settings.json', '/etc/claude-code/managed-settings.json']
|
|
1507
|
+
hits = []
|
|
1508
|
+
for p in srcs:
|
|
1509
|
+
try:
|
|
1510
|
+
d = json.load(open(p))
|
|
1511
|
+
except Exception:
|
|
1512
|
+
continue
|
|
1513
|
+
perm = d.get('permissions') or {}
|
|
1514
|
+
name = p.replace(cwd + '/', '')
|
|
1515
|
+
mode = perm.get('defaultMode')
|
|
1516
|
+
if mode and mode != 'bypassPermissions':
|
|
1517
|
+
hits.append(f'{name}: defaultMode={mode}')
|
|
1518
|
+
if perm.get('ask'):
|
|
1519
|
+
hits.append(f'{name}: permissions.ask {len(perm["ask"])}건')
|
|
1520
|
+
if perm.get('disableBypassPermissionsMode') == 'disable':
|
|
1521
|
+
hits.append(f'{name}: disableBypassPermissionsMode')
|
|
1522
|
+
if (d.get('sandbox') or {}).get('enabled'):
|
|
1523
|
+
hits.append(f'{name}: sandbox.enabled')
|
|
1524
|
+
if hits:
|
|
1525
|
+
print('⚠ 권한 확인창이 뜰 수 있음 — ' + '; '.join(hits) + ' (이 설정이 RoutineCode 자동실행 설정보다 우선)')
|
|
1526
|
+
PYEOF
|
|
1527
|
+
)
|
|
1528
|
+
if [ -n "$PERM_WARN" ]; then
|
|
1529
|
+
MESSAGES="${MESSAGES:+$MESSAGES | }${PERM_WARN}"
|
|
1461
1530
|
fi
|
|
1531
|
+
|
|
1532
|
+
# --- Output ---
|
|
1533
|
+
# JSON 은 반드시 직렬화기로 만든다 — 메시지에 줄바꿈·역슬래시가 섞이면 손으로 만든 JSON 이 깨져
|
|
1534
|
+
# Claude Code 가 "hook output opens a JSON payload that never completed" 로 거부한다.
|
|
1535
|
+
RC_HOOK_MESSAGES="$MESSAGES" python3 -c '
|
|
1536
|
+
import json, os
|
|
1537
|
+
m = os.environ.get("RC_HOOK_MESSAGES", "").strip()
|
|
1538
|
+
print(json.dumps({"continue": True, "systemMessage": "[HOOK] " + m} if m else {"continue": True}, ensure_ascii=False))
|
|
1539
|
+
' 2>/dev/null || echo '{"continue":true}'
|
|
@@ -11,6 +11,8 @@ check_path 재검사. dev-source 는 check_path 가 면제하므로 개발 마
|
|
|
11
11
|
import os, sys, importlib
|
|
12
12
|
REPO = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
|
13
13
|
sys.path.insert(0, os.path.join(REPO, "hooks", "lib"))
|
|
14
|
+
# 셸 환경과 무관하게 판정(개발자 셸의 ROUTINECODE_DEV=1 은 설치본 CORE 도 완화한다)
|
|
15
|
+
os.environ.pop("ROUTINECODE_DEV", None)
|
|
14
16
|
import secret_filter as sf; importlib.reload(sf)
|
|
15
17
|
pol = sf.load_policy()
|
|
16
18
|
|
|
@@ -19,7 +21,15 @@ def bc(c):
|
|
|
19
21
|
|
|
20
22
|
RC = "routine" + "code"
|
|
21
23
|
PROMPT = RC + "-prompt.md"
|
|
22
|
-
|
|
24
|
+
# 합성 설치본(engine/.sources 없음 → dev 아님). CORE 는 실물 패키지(package.json name)만 보호하므로
|
|
25
|
+
# (6cd3898) 이름만 routinecode 인 가상 경로가 아니라 package.json 을 가진 픽스처를 쓴다.
|
|
26
|
+
import tempfile, shutil, atexit
|
|
27
|
+
_FIX = tempfile.mkdtemp()
|
|
28
|
+
atexit.register(shutil.rmtree, _FIX, True)
|
|
29
|
+
INST = os.path.join(os.path.realpath(_FIX), RC)
|
|
30
|
+
for _d in ("plugin", "hooks/lib"):
|
|
31
|
+
os.makedirs(os.path.join(INST, _d))
|
|
32
|
+
open(os.path.join(INST, "package.json"), "w").write('{"name":"@routinecrew/' + RC + '"}\n')
|
|
23
33
|
DEV = REPO # 실제 full-source 체크아웃
|
|
24
34
|
|
|
25
35
|
CASES = [
|
|
@@ -81,9 +81,19 @@ def fresh_home(config=None, credit_state=None, flags=None):
|
|
|
81
81
|
return home
|
|
82
82
|
|
|
83
83
|
|
|
84
|
+
# 차단(BLOCK) 케이스는 hook 이 재충전 페이지를 브라우저로 연다(하루 1회 표시 파일은 가짜 HOME 마다 새로 없음).
|
|
85
|
+
# 테스트가 실제 Mac 브라우저를 띄우지 않도록 open/xdg-open 을 무동작 스텁으로 가린다.
|
|
86
|
+
_NO_BROWSER = tempfile.mkdtemp(prefix="rc-nobrowser-")
|
|
87
|
+
for _b in ("open", "xdg-open"):
|
|
88
|
+
with open(os.path.join(_NO_BROWSER, _b), "w") as _f:
|
|
89
|
+
_f.write("#!/bin/sh\nexit 0\n")
|
|
90
|
+
os.chmod(os.path.join(_NO_BROWSER, _b), 0o755)
|
|
91
|
+
|
|
92
|
+
|
|
84
93
|
def base_env(home, server_url=None, extra=None):
|
|
85
94
|
env = dict(os.environ)
|
|
86
95
|
env["HOME"] = home
|
|
96
|
+
env["PATH"] = _NO_BROWSER + ":" + env.get("PATH", "")
|
|
87
97
|
env["ROUTINECODE_SERVER_URL"] = server_url or f"http://127.0.0.1:{PORT}"
|
|
88
98
|
for k in ("ROUTINECODE_TELEMETRY", "ROUTINECODE_CREDIT_BYPASS", "ROUTINECODE_CREDIT_GATE"):
|
|
89
99
|
env.pop(k, None)
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
routinecode 소스 개발자는 CORE 소스보호(복제방지)에서 면제되어야 하되,
|
|
5
5
|
런타임 config(~/.routinecode/*.json)·시크릿(.env 등)·설치본은 계속 보호되어야 한다.
|
|
6
6
|
|
|
7
|
+
.env 등 일반 시크릿 파일은 하드블록하지 않고 값만 스크럽한다(c799d41 scrub-only).
|
|
8
|
+
런타임 config 는 명시 dev 모드(env=1 ∧ 가드가 full-source 체크아웃)에서만 참조를 허용한다(6cd3898).
|
|
9
|
+
|
|
7
10
|
완화 조건(둘 중 하나):
|
|
8
11
|
- ROUTINECODE_DEV=1 (명시 opt-in), 또는
|
|
9
12
|
- 타깃 경로가 실제 full-source 체크아웃(engine/ + .sources|mcp-*/src) 안일 때.
|
|
@@ -41,13 +44,13 @@ check("zeroconf: dev 소스 hook cat 허용", bc("cat " + hook) is False)
|
|
|
41
44
|
check("zeroconf: 설치본 hook Read 차단", cp(installed) is True)
|
|
42
45
|
check("zeroconf: 설치본 hook cat 차단", bc("cat " + installed) is True)
|
|
43
46
|
check("zeroconf: 홈 config Read 차단", cp(home_cfg) is True)
|
|
44
|
-
check("zeroconf: .env
|
|
47
|
+
check("zeroconf: .env 는 차단 대신 값 스크럽", cp(env_secret) is False)
|
|
45
48
|
|
|
46
49
|
# ── 명시 opt-in(ROUTINECODE_DEV=1): 소스보호만 완화, config/시크릿 유지 ──
|
|
47
50
|
os.environ["ROUTINECODE_DEV"] = "1"
|
|
48
51
|
check("env=1: 설치본 hook Read 허용", cp(installed) is False)
|
|
49
|
-
check("env=1: 홈 config
|
|
50
|
-
check("env=1: .env
|
|
52
|
+
check("env=1(dev 체크아웃): 홈 config 참조 허용", cp(home_cfg) is False)
|
|
53
|
+
check("env=1: .env 는 차단 대신 값 스크럽", cp(env_secret) is False)
|
|
51
54
|
red, matches = sf.redact("token=rcw-" + "a" * 40)
|
|
52
55
|
check("env=1: 시크릿 redaction 유지", "REDACTED" in red and len(matches) >= 1)
|
|
53
56
|
os.environ.pop("ROUTINECODE_DEV", None)
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
검증:
|
|
5
5
|
1. 프로젝트 repo 안의 시크릿 파일(.env, banned_paths 매칭)은 하드블록되지 않는다.
|
|
6
|
-
2. 프로젝트 밖(홈 dotfile, 타 repo)의 시크릿
|
|
7
|
-
3. CORE(~/.routinecode/*.json)는 프로젝트 안에 있어도
|
|
6
|
+
2. 프로젝트 밖(홈 dotfile, 타 repo)의 시크릿 파일도 하드블록하지 않고 값을 스크럽한다(c799d41 scrub-only).
|
|
7
|
+
3. CORE(~/.routinecode/*.json)는 프로젝트 안에 있어도 하드블록된다(dev 모드 아님).
|
|
8
8
|
4. in-repo 파일의 실제 값은 redact_path_values 로 스크럽된다(비표준 라벨 포함).
|
|
9
9
|
5. in-repo config 를 참조하는 bash 배포 명령은 통과한다.
|
|
10
10
|
6. 프로젝트 루트가 '/'나 홈 그 자체면 relax 비활성(과광역 방지).
|
|
@@ -13,6 +13,8 @@ import os, json, tempfile, shutil, importlib.util, pathlib, sys
|
|
|
13
13
|
|
|
14
14
|
LIB = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "lib")
|
|
15
15
|
spec = importlib.util.spec_from_file_location("secret_filter", os.path.join(LIB, "secret_filter.py"))
|
|
16
|
+
# 비-dev 사용자 기준 판정 — 개발자 셸의 ROUTINECODE_DEV=1 은 런타임 config CORE 를 의도적으로 완화한다.
|
|
17
|
+
os.environ.pop("ROUTINECODE_DEV", None)
|
|
16
18
|
sf = importlib.util.module_from_spec(spec); spec.loader.exec_module(sf)
|
|
17
19
|
|
|
18
20
|
PASS = FAIL = 0
|
|
@@ -49,10 +51,16 @@ check("in-proj .env not hard-blocked", sf.check_path(os.path.join(proj, ".env"),
|
|
|
49
51
|
check("in-proj tenant-banned config not hard-blocked",
|
|
50
52
|
sf.check_path(os.path.join(proj, "infra", "cfg", "servers.md"), polBan)[0] is False)
|
|
51
53
|
|
|
52
|
-
# 2. 프로젝트 밖 →
|
|
53
|
-
|
|
54
|
-
check("out-of-proj
|
|
55
|
-
|
|
54
|
+
# 2. 프로젝트 밖 → 하드블록 대신 값 스크럽(scrub-only)
|
|
55
|
+
oenv = os.path.join(other, ".env")
|
|
56
|
+
check("out-of-proj other .env not hard-blocked", sf.check_path(oenv, polDefault)[0] is False)
|
|
57
|
+
oout, ohits = sf.redact_path_values(open(oenv).read(), oenv, polDefault)
|
|
58
|
+
check("out-of-proj other .env value scrubbed", ohits >= 1 and PW not in oout)
|
|
59
|
+
check("out-of-proj ~/.ssh/id_rsa not hard-blocked",
|
|
60
|
+
sf.check_path(os.path.join(os.path.expanduser("~"), ".ssh", "id_rsa"), polDefault)[0] is False)
|
|
61
|
+
PEM_BODY = "b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW" * 3
|
|
62
|
+
pem_out, pem_m = sf.redact("-----BEGIN OPENSSH PRIVATE KEY-----\n%s\n-----END OPENSSH PRIVATE KEY-----\n" % PEM_BODY)
|
|
63
|
+
check("private key body scrubbed", len(pem_m) >= 1 and PEM_BODY not in pem_out)
|
|
56
64
|
|
|
57
65
|
# 3. CORE (in-project 여도) → 차단
|
|
58
66
|
check("in-proj CORE ~/.routinecode/*.json still blocked",
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""rm_guard 회귀 테스트 — Claude Code 2.1.301 헤드리스 실측표 고정.
|
|
2
|
+
|
|
3
|
+
PROMPTED: 순수 하네스(bypass)에서 '위험 삭제' 확인창이 뜬 형태 → 반드시 deny/rewrite/block.
|
|
4
|
+
CLEAN : 확인창이 안 뜬 형태 → 손대지 않음(None). 재작성(rewrite)은 무해하므로 허용 목록 별도.
|
|
5
|
+
실행: python3 hooks/tests/rm-guard.test.py
|
|
6
|
+
"""
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'lib'))
|
|
11
|
+
import rm_guard as rg # noqa: E402
|
|
12
|
+
|
|
13
|
+
WS = '/private/tmp/rclab-unit/ws'
|
|
14
|
+
|
|
15
|
+
PROMPTED = [ # (id, command, expected action)
|
|
16
|
+
('L03', 'rm -rf ./*', 'deny'),
|
|
17
|
+
('L04', 'rm -rf *', 'deny'),
|
|
18
|
+
('L06', 'cd build && rm -rf ./*', 'deny'),
|
|
19
|
+
('L08', 'rm -rf .', 'deny'),
|
|
20
|
+
('L10', f'rm -rf {WS}', 'deny'),
|
|
21
|
+
('L12', 'rm -rf ../ws/build/*', 'deny'),
|
|
22
|
+
('L13', 'rm -rf build/*/*', 'deny'),
|
|
23
|
+
('V05', 'rm -rf $RCLABX/lib', 'rewrite'),
|
|
24
|
+
('V07', 'rm -f $RCLABX/*.rclabnx', 'rewrite'),
|
|
25
|
+
('V09', 'rm -rf $RCLABX/$RCLABF/rclab-nx', 'rewrite'),
|
|
26
|
+
('V11', 'R=$(pwd); rm -rf $R', 'deny'),
|
|
27
|
+
('V14', 'for f in a b; do rm -rf $RCLABX/$f; done', 'rewrite'),
|
|
28
|
+
('S06', 'sh -c \'rm -rf "$RCLABX"/*.rclabnx\'', 'rewrite'),
|
|
29
|
+
('S08', "sh -c $'rm -rf rclab-nx\\necho x'", 'deny'),
|
|
30
|
+
('S24', f'S={WS}/build; H=/var/tmp/rclab-check\ncd {WS} && rm -f ${{S:?}}/*.tgz\ncolima ssh -- sudo sh -c "rm -rf $H; mkdir -p ${{H:?}}/a"', 'deny'),
|
|
31
|
+
('N02', 'H=/var/tmp/rclab-check\ncd build && rm -f a.png\ncolima ssh -- sudo sh -c "rm -rf $H"', 'deny'),
|
|
32
|
+
('C18', 'cd build && rm -rf *', 'deny'),
|
|
33
|
+
('C19', 'cd build && rm -rf sub/*', 'deny'),
|
|
34
|
+
('D02', 'R=$(pwd); rm -rf $R/*', 'deny'),
|
|
35
|
+
('D06', f'rm -rf {WS}/*', 'deny'),
|
|
36
|
+
('D07', 'rm -rf ../ws', 'deny'),
|
|
37
|
+
('D08', 'rm -rf build dist .', 'deny'),
|
|
38
|
+
('S09', 'sudo -n sh -c "rm -rf $RCLABX/lib" 2>/dev/null; echo done', 'deny'),
|
|
39
|
+
('S09g', 'sh -c "rm -rf ${RCLABX:?}/tmp"', 'deny'),
|
|
40
|
+
('X01', 'sh -c "rm -rf $RCLABX/$RCLABF/rclab-nx"', 'deny'),
|
|
41
|
+
('X03', 'bash -c "cd build && rm -rf *"', 'deny'),
|
|
42
|
+
('X04', 'sh -c "rm -rf ./*"', 'deny'),
|
|
43
|
+
('X06', '(cd build && rm -rf *)', 'deny'),
|
|
44
|
+
('X07', '{ cd build; rm -rf ./*; }', 'deny'),
|
|
45
|
+
('X08', 'cd build || exit; rm -rf *', 'deny'),
|
|
46
|
+
('X09', 'pushd build && rm -rf * && popd', 'deny'),
|
|
47
|
+
('X10', 'rm -rf -- *', 'deny'),
|
|
48
|
+
('X12', 'rm -rf $(ls -d build)', 'deny'),
|
|
49
|
+
('X23', 'cd build && rm -rf ../dist/*', 'deny'),
|
|
50
|
+
('X24', 'rm -rf ./build/../*', 'deny'),
|
|
51
|
+
('T2', 'rm -rf /x/p\nfor d in 0.1; do\n bash -c "echo x" & pid=$!\n python3 -c "import time;time.sleep($d)"\ndone', 'deny'),
|
|
52
|
+
('Q', 'S=/x/k; rm -rf ${S:?}/p\nFN=$(sed -n p f)\nfor s in TERM; do\n bash -c "$FN"$\'\\n\'"f ${S:?}/p" & pid=$!\n wait $pid\ndone', 'deny'),
|
|
53
|
+
('SHOT', 'S=/x/scratch; H=/var/tmp/llm-auth-cli-check\ncd /x/pkg && rm -f ${S:?}/*.tgz && npm pack --pack-destination $S >/dev/null\n'
|
|
54
|
+
'colima ssh -- sudo sh -c "rm -rf $H; mkdir -p ${H:?}/claude-auth ${H:?}/vendor && chown 1000:1000 ${H:?}/claude-auth"\n'
|
|
55
|
+
'colima ssh -- sudo sh -c "stat -c \'%u:%g %a\' ${H:?}/claude-auth/tokens.json; rm -rf $H"', 'deny'),
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
CLEAN = [ # 확인창 없음 → None
|
|
59
|
+
'rm -rf build', f'rm -rf {WS}/build', 'rm -f *.log', 'cd build && rm -f *.png', 'rm -rf ~/rclab-nx/*',
|
|
60
|
+
'rm -rf */node_modules', 'rm -rf build/*', 'cd build; rm -rf sub', 'rmdir -p a/node_modules',
|
|
61
|
+
'rm -rf ${RCLABX:?}/rclab-nx/*', 'rm -rf "$(pwd)"/build', 'rm -rf $(pwd)/rclab-nx/*',
|
|
62
|
+
f'rm -rf "$(dirname {WS})/ws/dist"', f'sh -c "rm -rf {WS}/build"', 'bash -c \'rm -rf "$0"/x\' /p',
|
|
63
|
+
f'eval "rm -rf {WS}/dist"', "find build -name '*.png' | xargs rm -f", "find build -name '*.png' -delete",
|
|
64
|
+
'colima ssh -- sudo rm -rf /var/tmp/rclab-nx', 'cd .. && rm -rf ws', 'rm -rf ./build ./dist',
|
|
65
|
+
'rm -rf ../rclab-nx-sibling', 'cd build && sh -c "rm -rf sub"', 'cd build && rm -rf /abs/dist/*',
|
|
66
|
+
'H=/v/t; cd build; sh -c "rm -rf ${H:?}"', 'git rm --cached a.txt', "grep -rn 'rm -rf' hooks/",
|
|
67
|
+
'docker run --rm alpine true', "find . -maxdepth 1 -name 'x.log' -exec rm -f {} +", 'ls | xargs rm -rf',
|
|
68
|
+
'rm -rf {build,dist}', 'git clean -fdx -e keep', 'sh -c "rm -rf $RCLABX/rclab-nx/*; echo x"', 'rm -rf ${X:?}/lib', 'sh -c "rm -rf ${X:?}/rclab-nx/*"',
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
BLOCK = ['rm -rf /', 'rm -rf ~', 'rm -rf $HOME', 'rm -rf /usr/local/lib', 'sudo rm -rf /etc/x', 'rm -rf ~/.ssh']
|
|
72
|
+
|
|
73
|
+
HEREDOC = ("cat > /tmp/x.tsv <<'EOF'\nV07\trm -f $RCLABX/*.png\nrm -rf $D/*\nEOF\nrm -rf $SCR/$f",
|
|
74
|
+
"cat > /tmp/x.tsv <<'EOF'\nV07\trm -f $RCLABX/*.png\nrm -rf $D/*\nEOF\nrm -rf ${SCR:?}/$f")
|
|
75
|
+
|
|
76
|
+
ok = fail = 0
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def check(name, cond, detail=''):
|
|
80
|
+
global ok, fail
|
|
81
|
+
if cond:
|
|
82
|
+
ok += 1
|
|
83
|
+
print(f' \033[32m✓\033[0m {name}')
|
|
84
|
+
else:
|
|
85
|
+
fail += 1
|
|
86
|
+
print(f' \033[31m✗\033[0m {name} {detail}')
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
for cid, cmd, want in PROMPTED:
|
|
90
|
+
r = rg.analyze(cmd, WS)
|
|
91
|
+
got = list(r)[0] if r else 'none'
|
|
92
|
+
check(f'PROMPTED {cid} → {want}', got == want, f'(got {got}: {r})')
|
|
93
|
+
if got == 'rewrite':
|
|
94
|
+
again = rg.analyze(r['rewrite'], WS)
|
|
95
|
+
check(f'PROMPTED {cid} rewrite is stable', again is None, f'(re-analyze → {again})')
|
|
96
|
+
for cmd in CLEAN:
|
|
97
|
+
r = rg.analyze(cmd, WS)
|
|
98
|
+
check(f'CLEAN {cmd[:50]!r}', r is None or 'rewrite' in r, f'(got {r})')
|
|
99
|
+
for cmd in BLOCK:
|
|
100
|
+
r = rg.analyze(cmd, WS)
|
|
101
|
+
check(f'BLOCK {cmd!r}', bool(r) and 'block' in r, f'(got {r})')
|
|
102
|
+
r = rg.analyze(HEREDOC[0], WS)
|
|
103
|
+
check('heredoc body is never rewritten', bool(r) and r.get('rewrite') == HEREDOC[1], f'(got {r})')
|
|
104
|
+
check('deny reasons carry [RoutineCode] + example', all(
|
|
105
|
+
rg.deny_reason(k).startswith('[RoutineCode]') for k in rg.REASONS))
|
|
106
|
+
|
|
107
|
+
print(f'\n{ok}/{ok + fail} passed')
|
|
108
|
+
sys.exit(1 if fail else 0)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# secret-guard 우회 접근 방어 테스트 (2026-10-16)
|
|
3
|
+
#
|
|
4
|
+
# 보호 파일 값이 "경로를 숨긴 접근"으로도 모델 출력에 실리지 않는지 검증한다.
|
|
5
|
+
# - Bash: 따옴표 조각 경로 · 변수 경로 · 글롭 · 디렉토리 · 인라인 인터프리터 · base64 인코딩
|
|
6
|
+
# - Read/Grep: Bash 로 만든 사본 파일
|
|
7
|
+
# - 회귀: 무관한 명령은 감싸지 않고, 차단(block)은 새로 생기지 않는다(scrub-only 경계)
|
|
8
|
+
#
|
|
9
|
+
# 실행: bash hooks/tests/secret-guard-bypass.test.sh
|
|
10
|
+
|
|
11
|
+
set -u
|
|
12
|
+
HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
13
|
+
LIB_DIR="$HOOK_DIR/lib"
|
|
14
|
+
PASS=0; FAIL=0
|
|
15
|
+
ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS+1)); }
|
|
16
|
+
ng() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL+1)); }
|
|
17
|
+
|
|
18
|
+
W=$(mktemp -d "${TMPDIR:-/tmp}/rc-bypass.XXXXXX")
|
|
19
|
+
trap 'rm -rf "${W:?}"' EXIT
|
|
20
|
+
mkdir -p "$W/vault"
|
|
21
|
+
SECRET="sk-ant-oat01-$(LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom | head -c 90)AA"
|
|
22
|
+
OTHER="npm_$(LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom | head -c 36)"
|
|
23
|
+
CFG="$W/vault/my.cfg"
|
|
24
|
+
printf 'notes\nclaude setup-token = %s\nNPM = %s\n' "$SECRET" "$OTHER" > "$CFG"
|
|
25
|
+
chmod 600 "$CFG"
|
|
26
|
+
POL="$W/policy.json"
|
|
27
|
+
printf '{"mode":"warn","redact_only_paths":["%s"]}' "$CFG" > "$POL"
|
|
28
|
+
export ROUTINECODE_SECRET_POLICY_PATH="$POL"
|
|
29
|
+
|
|
30
|
+
targets() { # stdout: "<탐지 파일 수> <강제 래핑 여부>"
|
|
31
|
+
printf '%s' "$1" | python3 -c "
|
|
32
|
+
import sys; sys.path.insert(0, '$LIB_DIR')
|
|
33
|
+
import secret_filter as sf
|
|
34
|
+
f, force = sf.bash_secret_targets(sys.stdin.read())
|
|
35
|
+
print(len(f), force)"
|
|
36
|
+
}
|
|
37
|
+
expect_targets() { local got; got=$(targets "$2"); [ "$got" = "$3" ] && ok "$1 → $got" || ng "$1 — 기대 [$3] 실제 [$got]"; }
|
|
38
|
+
|
|
39
|
+
echo ""
|
|
40
|
+
echo "=== bash_secret_targets: 우회 경로 해석 ==="
|
|
41
|
+
expect_targets "리터럴 경로" "cat $CFG" "1 False"
|
|
42
|
+
expect_targets "따옴표 조각 경로" "cat \"$W/vault/my.\"\"cfg\"" "1 True"
|
|
43
|
+
expect_targets "변수 대입 경로" "C=$W/vault/my.cfg; awk '{print}' \"\$C\"" "1 False"
|
|
44
|
+
expect_targets "변수 조립 경로" "D=$W/vault; F=my.cfg; tail -1 \"\$D/\$F\"" "1 False"
|
|
45
|
+
expect_targets "글롭" "head -2 $W/vault/my.c*" "1 False"
|
|
46
|
+
expect_targets "디렉토리 재귀 grep" "grep -r token $W" "1 False"
|
|
47
|
+
expect_targets "python -c 인라인" "python3 -c \"print(open('x'+'y').read())\"" "0 True"
|
|
48
|
+
expect_targets "node -e 인라인" "node -e \"console.log(1)\"" "0 True"
|
|
49
|
+
expect_targets "python heredoc" "python3 - <<'EOF'
|
|
50
|
+
print(1)
|
|
51
|
+
EOF" "0 True"
|
|
52
|
+
expect_targets "eval" "eval \"cat x\"" "0 True"
|
|
53
|
+
expect_targets "base64 디코딩" "echo eA== | base64 -d" "0 True"
|
|
54
|
+
expect_targets "find -exec" "find /tmp -name x -exec cat {} \\;" "0 True"
|
|
55
|
+
expect_targets "회귀: 무관 명령" "ls -la /tmp && echo \"a\" \"b\"" "0 False"
|
|
56
|
+
expect_targets "회귀: git" "git status --short" "0 False"
|
|
57
|
+
expect_targets "알려진 한계: 백그라운드 &" "python3 -c \"print(1)\" &" "0 False"
|
|
58
|
+
|
|
59
|
+
echo ""
|
|
60
|
+
echo "=== pre-bash-guard 실행: 출력에서 값이 가려지는가 ==="
|
|
61
|
+
run_guarded() { # 훅이 재작성한 명령(없으면 원본)을 실행해 출력
|
|
62
|
+
local cmd="$1" input out newcmd
|
|
63
|
+
input=$(python3 -c "import json,sys; print(json.dumps({'tool_name':'Bash','tool_input':{'command':sys.argv[1]},'session_id':'t'}))" "$cmd")
|
|
64
|
+
out=$(printf '%s' "$input" | "$HOOK_DIR/pre-bash-guard.sh" 2>/dev/null)
|
|
65
|
+
if printf '%s' "$out" | grep -q '"decision": *"block"'; then echo "__BLOCKED__"; return; fi
|
|
66
|
+
newcmd=$(printf '%s' "$out" | python3 -c "
|
|
67
|
+
import sys,json
|
|
68
|
+
try:
|
|
69
|
+
d=json.loads(sys.stdin.read() or '{}'); print(d.get('hookSpecificOutput',{}).get('updatedInput',{}).get('command',''))
|
|
70
|
+
except Exception: print('')")
|
|
71
|
+
[ -n "$newcmd" ] || newcmd="$cmd"
|
|
72
|
+
bash -c "$newcmd" 2>&1
|
|
73
|
+
}
|
|
74
|
+
expect_masked() {
|
|
75
|
+
local name="$1" cmd="$2" out
|
|
76
|
+
out=$(run_guarded "$cmd")
|
|
77
|
+
if [ "$out" = "__BLOCKED__" ]; then ng "$name — 차단됨(scrub-only 경계 위반)"; return; fi
|
|
78
|
+
if printf '%s' "$out" | grep -qF -e "$SECRET" -e "$OTHER"; then ng "$name — 값 노출"; return; fi
|
|
79
|
+
printf '%s' "$out" | grep -q 'MASKED\|PROTECTED\|REDACTED' && ok "$name — 가려짐" || ng "$name — 마스크 흔적 없음: $(printf '%s' "$out" | head -c 80)"
|
|
80
|
+
}
|
|
81
|
+
expect_masked "따옴표 조각 cat" "cat \"$W/vault/my.\"\"cfg\""
|
|
82
|
+
expect_masked "변수 경로 awk" "C=$W/vault/my.cfg; awk -F' = ' '/setup-token/{print \$2}' \"\$C\""
|
|
83
|
+
expect_masked "python 문자열 조립" "python3 -c \"print(open('$W/vault/my.'+'cfg').read())\""
|
|
84
|
+
expect_masked "node 인라인" "node -e \"console.log(require('fs').readFileSync('$W/vault/my'+'.cfg','utf8'))\""
|
|
85
|
+
expect_masked "base64 인코딩 덤프" "python3 -c \"import base64;print(base64.b64encode(open('$W/vault/my.'+'cfg','rb').read()).decode())\""
|
|
86
|
+
expect_masked "디렉토리 grep" "grep -rh token $W"
|
|
87
|
+
|
|
88
|
+
echo ""
|
|
89
|
+
echo "=== Read / Grep: Bash 로 만든 사본 ==="
|
|
90
|
+
COPY="$W/copy.txt"; cp "$CFG" "$COPY"; chmod 644 "$COPY"
|
|
91
|
+
read_redirect() {
|
|
92
|
+
local tool="$1" key="$2" input out
|
|
93
|
+
input=$(python3 -c "import json,sys; print(json.dumps({'tool_name':sys.argv[1],'tool_input':{sys.argv[2]:sys.argv[3],'pattern':'token'},'session_id':'t'}))" "$tool" "$key" "$COPY")
|
|
94
|
+
out=$(printf '%s' "$input" | "$HOOK_DIR/$3" 2>/dev/null)
|
|
95
|
+
printf '%s' "$out" | python3 -c "import sys,json; print(json.loads(sys.stdin.read() or '{}').get('hookSpecificOutput',{}).get('updatedInput',{}).get(sys.argv[1],''))" "$key"
|
|
96
|
+
}
|
|
97
|
+
R=$(read_redirect Read file_path pre-read-guard.sh)
|
|
98
|
+
if [ -n "$R" ] && [ "$R" != "$COPY" ] && ! grep -qF "$SECRET" "$R" && grep -q "setup-token" "$R"; then ok "Read 사본 → 값만 가린 사본으로 대체(키 이름 유지)"; else ng "Read 사본 대체 실패 [$R]"; fi
|
|
99
|
+
G=$(read_redirect Grep path pre-grep-guard.sh)
|
|
100
|
+
if [ -n "$G" ] && [ "$G" != "$COPY" ] && ! grep -qF "$SECRET" "$G"; then ok "Grep 사본 → 값만 가린 사본 검색"; else ng "Grep 사본 대체 실패 [$G]"; fi
|
|
101
|
+
PLAIN="$W/plain.txt"; echo "hello" > "$PLAIN"
|
|
102
|
+
P=$(COPY="$PLAIN"; input=$(python3 -c "import json,sys; print(json.dumps({'tool_name':'Read','tool_input':{'file_path':sys.argv[1]},'session_id':'t'}))" "$PLAIN"); printf '%s' "$input" | "$HOOK_DIR/pre-read-guard.sh" 2>/dev/null | grep -c updatedInput)
|
|
103
|
+
[ "$P" = "0" ] && ok "회귀: 보호 값 없는 파일 Read 는 그대로" || ng "회귀: 일반 파일이 재작성됨"
|
|
104
|
+
|
|
105
|
+
echo ""
|
|
106
|
+
echo "결과: PASS $PASS / FAIL $FAIL"
|
|
107
|
+
[ "$FAIL" -eq 0 ]
|
|
@@ -15,6 +15,16 @@ LIB_DIR="$HOOK_DIR/lib"
|
|
|
15
15
|
PASS=0
|
|
16
16
|
FAIL=0
|
|
17
17
|
|
|
18
|
+
# 셸 환경과 무관하게 판정 — 개발자 셸의 ROUTINECODE_DEV=1 은 CORE 를 의도적으로 완화한다.
|
|
19
|
+
unset ROUTINECODE_DEV
|
|
20
|
+
# CORE 는 '실물 RoutineCode 패키지'만 보호한다(6cd3898). 이름만 routinecode 인 가상 경로는
|
|
21
|
+
# 사용자 레포로 보고 통과시키므로, package.json 을 가진 픽스처 패키지로 검증한다.
|
|
22
|
+
RC_FIXTURE=$(mktemp -d)
|
|
23
|
+
RC_PKG="$RC_FIXTURE/routinecode"
|
|
24
|
+
mkdir -p "$RC_PKG/hooks/lib" "$RC_PKG/plugin/agents"
|
|
25
|
+
printf '{"name":"@routinecrew/routinecode"}\n' > "$RC_PKG/package.json"
|
|
26
|
+
trap 'rm -rf "${RC_FIXTURE:?}"' EXIT
|
|
27
|
+
|
|
18
28
|
red() { printf '\033[31m%s\033[0m' "$1"; }
|
|
19
29
|
green() { printf '\033[32m%s\033[0m' "$1"; }
|
|
20
30
|
dim() { printf '\033[2m%s\033[0m' "$1"; }
|
|
@@ -284,7 +294,7 @@ assert_guard() {
|
|
|
284
294
|
# CORE path cannot be exempted even by wildcard allowlist
|
|
285
295
|
assert_guard "CORE hook source not exemptable by allowlist" check-path \
|
|
286
296
|
'{"path_allowlist":["**/*","**/hooks/**"]}' \
|
|
287
|
-
"/
|
|
297
|
+
"$RC_PKG/hooks/lib/secret_filter.py" "True"
|
|
288
298
|
|
|
289
299
|
# CORE: all of .routinecode/*.json protected even with wildcard allowlist
|
|
290
300
|
assert_guard "CORE .routinecode json protected" check-path \
|
|
@@ -299,7 +309,7 @@ assert_guard "replace mode drops generic .env ban" check-path \
|
|
|
299
309
|
# ...but CORE is still enforced under replace
|
|
300
310
|
assert_guard "replace mode keeps CORE hook ban" check-path \
|
|
301
311
|
'{"secret_paths_mode":"replace","banned_paths":[]}' \
|
|
302
|
-
"/
|
|
312
|
+
"$RC_PKG/hooks/pre-foo.sh" "True"
|
|
303
313
|
|
|
304
314
|
# backward-compat: default still bans generic .env
|
|
305
315
|
assert_guard "scrub-only: generic .env passes (value-scrub protects)" check-path \
|
|
@@ -319,7 +329,7 @@ assert_guard "scrub-only: inline secret passes (redaction protects)" check-bash
|
|
|
319
329
|
# CORE command pattern (routinecode-scoped) cannot be exempted by command_allowlist
|
|
320
330
|
assert_guard "CORE command not exemptable by allowlist" check-bash \
|
|
321
331
|
'{"command_allowlist":["cat .*secret_filter"]}' \
|
|
322
|
-
"cat /
|
|
332
|
+
"cat $RC_PKG/hooks/lib/secret_filter.py" "True"
|
|
323
333
|
|
|
324
334
|
# install-scoped CORE: RoutineCode 자기 파일만 보호, 타 프로젝트는 오탐 없이 통과
|
|
325
335
|
assert_guard "CORE scoped: rc install hook blocked" check-path \
|
|
@@ -331,7 +341,7 @@ assert_guard "CORE scoped: other-project hook passes (no FP)" check-path \
|
|
|
331
341
|
assert_guard "CORE scoped: other-project agents passes (no FP)" check-path \
|
|
332
342
|
'{}' "/myapp/plugin/agents/bot.md" "False"
|
|
333
343
|
assert_guard "CORE scoped: rc plugin read blocked" check-bash \
|
|
334
|
-
'{}' "cat /
|
|
344
|
+
'{}' "cat $RC_PKG/plugin/agents/x.md" "True"
|
|
335
345
|
assert_guard "CORE scoped: other-project find plugin passes (no FP)" check-bash \
|
|
336
346
|
'{}' "find plugin/ -name x" "False"
|
|
337
347
|
|
|
@@ -503,8 +513,8 @@ assert_guard "REG: cat own env allowed" check-bash '{}' "cat /Users/dev/app/.env
|
|
|
503
513
|
assert_guard "REG: token-extract + curl Bearer allowed" check-bash '{}' 'export T=$(sed -n 5p /Users/dev/cfg.md); curl -H "Authorization: Bearer $T" https://api.example.com' "False"
|
|
504
514
|
# CORE 쌍대: RoutineCode 자기 것은 계속 차단(개발자로부터도)
|
|
505
515
|
assert_guard "REG: rc runtime config still blocked" check-path '{}' "/u/.routinecode/config.json" "True"
|
|
506
|
-
assert_guard "REG: rc prompt still blocked" check-path '{}' "/
|
|
507
|
-
assert_guard "REG: rc hooks read still blocked" check-bash '{}' "cat /
|
|
516
|
+
assert_guard "REG: rc prompt still blocked" check-path '{}' "$RC_PKG/plugin/routinecode-prompt.md" "True"
|
|
517
|
+
assert_guard "REG: rc hooks read still blocked" check-bash '{}' "cat $RC_PKG/hooks/pre-bash-guard.sh" "True"
|
|
508
518
|
|
|
509
519
|
|
|
510
520
|
# ── REG2: 미등록 파일도 "읽은 도구 무관" 값-스크럽 (2026-09-02 벡터-완전 보장) ──
|
|
@@ -535,15 +545,53 @@ rm -rf "$UNREG_DIR"
|
|
|
535
545
|
|
|
536
546
|
# ── REG3: 변수경로+글롭 rm 선제차단 — Claude Code 하네스 확인창이 고객에게 뜨지 않는다 ──
|
|
537
547
|
# (하네스는 rm+변수글롭을 자체 휴리스틱으로 강제 확인창 처리. 훅이 먼저 block 하면 창 미노출.)
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
548
|
+
# (현행 설계: block 대신 ${VAR:?} 가드로 조용히 재작성 후 allow — 확인창·재시도 모두 없음)
|
|
549
|
+
assert_pre_rewrite() {
|
|
550
|
+
local name="$1" input="$2" expect_cmd="$3"
|
|
551
|
+
local got
|
|
552
|
+
got=$(printf '%s' "$input" | ROUTINECODE_SECRET_POLICY_PATH="$BC_POL" "$HOOK_DIR/pre-bash-guard.sh" 2>/dev/null \
|
|
553
|
+
| python3 -c "import sys,json;d=json.loads(sys.stdin.read() or '{}');print(d.get('hookSpecificOutput',{}).get('updatedInput',{}).get('command',''))")
|
|
554
|
+
if [ "$got" = "$expect_cmd" ]; then printf ' %s %s\n' "$(green ✓)" "$name"; PASS=$((PASS+1)); else printf ' %s %s (expected %s, got %s)\n' "$(red ✗)" "$name" "$expect_cmd" "$got"; FAIL=$((FAIL+1)); fi
|
|
555
|
+
}
|
|
556
|
+
assert_pre_rewrite "REG3: var-glob rm guarded (no harness dialog)" \
|
|
557
|
+
'{"tool_name": "Bash", "tool_input": {"command": "rm -f $SD/*.png"}}' 'rm -f ${SD:?}/*.png'
|
|
558
|
+
assert_pre_rewrite "REG3: braced var-glob rm guarded" \
|
|
559
|
+
'{"tool_name": "Bash", "tool_input": {"command": "rm -rf ${DIR}/*.tmp"}}' 'rm -rf ${DIR:?}/*.tmp'
|
|
560
|
+
assert_pre_rewrite "REG3: bare var rm guarded" \
|
|
561
|
+
'{"tool_name": "Bash", "tool_input": {"command": "rm -rf \"$D\""}}' 'rm -rf "${D:?}"'
|
|
562
|
+
assert_pre_rewrite "REG3: bare var guard only inside rm segment" \
|
|
563
|
+
'{"tool_name": "Bash", "tool_input": {"command": "rm -rf $H && echo $H"}}' 'rm -rf ${H:?} && echo $H'
|
|
544
564
|
assert_pre_block "REG3: literal tmp glob rm allowed" "$HOOK_DIR/pre-bash-guard.sh" \
|
|
545
565
|
'{"tool_name": "Bash", "tool_input": {"command": "rm -f /tmp/x/*.png"}}' "allow"
|
|
546
566
|
|
|
567
|
+
# ── REG4: 하네스 '위험 삭제' 확인창 실측 형태(CC 2.1.301) — 훅이 선제 deny/재작성, 확인창 0 ──
|
|
568
|
+
assert_pre_block "REG4: cd+rm+sh -c var rm (screenshot) denied" "$HOOK_DIR/pre-bash-guard.sh" \
|
|
569
|
+
'{"tool_name": "Bash", "tool_input": {"command": "H=/var/tmp/x\ncd /p && rm -f a.tgz\ncolima ssh -- sudo sh -c \"rm -rf $H; mkdir -p ${H:?}/a\""}}' "deny"
|
|
570
|
+
assert_pre_block "REG4: cd + relative glob denied" "$HOOK_DIR/pre-bash-guard.sh" \
|
|
571
|
+
'{"tool_name": "Bash", "tool_input": {"command": "cd build && rm -rf *"}, "cwd": "/tmp/rcws"}' "deny"
|
|
572
|
+
assert_pre_block "REG4: workspace wipe denied" "$HOOK_DIR/pre-bash-guard.sh" \
|
|
573
|
+
'{"tool_name": "Bash", "tool_input": {"command": "rm -rf ./*"}, "cwd": "/tmp/rcws"}' "deny"
|
|
574
|
+
assert_pre_block "REG4: derived var wipe denied" "$HOOK_DIR/pre-bash-guard.sh" \
|
|
575
|
+
'{"tool_name": "Bash", "tool_input": {"command": "R=$(pwd); rm -rf $R"}}' "deny"
|
|
576
|
+
assert_pre_block "REG4: sh -c literal rm allowed" "$HOOK_DIR/pre-bash-guard.sh" \
|
|
577
|
+
'{"tool_name": "Bash", "tool_input": {"command": "sh -c \"rm -rf /tmp/rcws/build\""}}' "allow"
|
|
578
|
+
assert_pre_block "REG4: sh -c docker --rm allowed" "$HOOK_DIR/pre-bash-guard.sh" \
|
|
579
|
+
'{"tool_name": "Bash", "tool_input": {"command": "sh -c '"'"'docker run --rm alpine true'"'"'"}}' "allow"
|
|
580
|
+
assert_pre_block "REG4: top-level literal remote rm allowed" "$HOOK_DIR/pre-bash-guard.sh" \
|
|
581
|
+
'{"tool_name": "Bash", "tool_input": {"command": "colima ssh -- sudo rm -rf /var/tmp/llm-auth-cli-check"}}' "allow"
|
|
582
|
+
assert_pre_rewrite "REG4: var inside sh -c guarded" \
|
|
583
|
+
'{"tool_name": "Bash", "tool_input": {"command": "sh -c '"'"'rm -rf \"$X\"/*.png'"'"'"}}' 'sh -c '"'"'rm -rf "${X:?}"/*.png'"'"''
|
|
584
|
+
assert_pre_rewrite "REG4: heredoc body not rewritten" \
|
|
585
|
+
'{"tool_name": "Bash", "tool_input": {"command": "cat > /tmp/f <<'"'"'E'"'"'\nrm -rf $D/*\nE\nrm -rf $S/x"}}' "$(printf 'cat > /tmp/f <<'"'"'E'"'"'\nrm -rf $D/*\nE\nrm -rf ${S:?}/x')"
|
|
586
|
+
ROUTINECODE_SESSION=1 assert_pre_block "REG4: plan mode denied" "$HOOK_DIR/pre-planmode-guard.sh" \
|
|
587
|
+
'{"tool_name": "ExitPlanMode", "tool_input": {"plan": "x"}}' "deny"
|
|
588
|
+
ROUTINECODE_SESSION= assert_pre_block "REG4: plan mode untouched in plain claude" "$HOOK_DIR/pre-planmode-guard.sh" \
|
|
589
|
+
'{"tool_name": "ExitPlanMode", "tool_input": {"plan": "x"}}' "allow"
|
|
590
|
+
ROUTINECODE_SESSION=1 assert_pre_block "REG4: ask-user denied" "$HOOK_DIR/pre-askuser-guard.sh" \
|
|
591
|
+
'{"tool_name": "AskUserQuestion", "tool_input": {}}' "deny"
|
|
592
|
+
ROUTINECODE_SESSION= assert_pre_block "REG4: ask-user untouched in plain claude" "$HOOK_DIR/pre-askuser-guard.sh" \
|
|
593
|
+
'{"tool_name": "AskUserQuestion", "tool_input": {}}' "allow"
|
|
594
|
+
|
|
547
595
|
TOTAL=$((PASS+FAIL))
|
|
548
596
|
if [ "$FAIL" -eq 0 ]; then
|
|
549
597
|
printf ' %s %d/%d passed\n\n' "$(green "✓")" "$PASS" "$TOTAL"
|
|
@@ -46,6 +46,19 @@ open(os.path.join(PROJ, '.env'), 'w').write(f'DB_URL=postgres://app:{PW}@db:5432
|
|
|
46
46
|
open(os.path.join(PROJ, '.env.example'), 'w').write('DB_URL=postgres://user:password@localhost/x\n')
|
|
47
47
|
open(os.path.join(PROJ, 'src', 'server.ts'), 'w').write("import { execFileSync } from 'node:child_process';\nconst t = Date.now();\n")
|
|
48
48
|
ENV = {k: v for k, v in os.environ.items() if not k.startswith('ROUTINECODE_')}
|
|
49
|
+
# 가짜 open/xdg-open — 크레딧 게이트 BLOCK 시 hook이 재충전 페이지를 실제 브라우저로 여는 것을 막는다
|
|
50
|
+
# (격리 HOME엔 하루1회 마커가 없어 매 실행마다 창이 열렸다)
|
|
51
|
+
FAKEBIN = os.path.join(TMP, 'bin')
|
|
52
|
+
os.makedirs(FAKEBIN, exist_ok=True)
|
|
53
|
+
for _n in ('open', 'xdg-open'):
|
|
54
|
+
_f = os.path.join(FAKEBIN, _n)
|
|
55
|
+
open(_f, 'w').write('#!/bin/sh\nexit 0\n')
|
|
56
|
+
os.chmod(_f, 0o755)
|
|
57
|
+
ENV['PATH'] = FAKEBIN + os.pathsep + ENV.get('PATH', '')
|
|
58
|
+
_NB = os.path.join(TMP, 'nobrowser'); os.makedirs(_NB)
|
|
59
|
+
for _b in ('open', 'xdg-open'): # 크레딧 차단 케이스가 실제 브라우저를 열지 않게 무동작 스텁
|
|
60
|
+
open(os.path.join(_NB, _b), 'w').write('#!/bin/sh\nexit 0\n'); os.chmod(os.path.join(_NB, _b), 0o755)
|
|
61
|
+
ENV['PATH'] = _NB + ':' + ENV.get('PATH', '')
|
|
49
62
|
ENV.update(HOME=HOME, CLAUDE_PROJECT_DIR=PROJ, MY_API_TOKEN=ENVV, ROUTINECODE_KNOWLEDGE_DIR=os.path.join(RCD, 'knowledge'))
|
|
50
63
|
|
|
51
64
|
|