fix: セキュリティ修正 トークンをコマンドライン引数からenv変数経由に変更 - #807
Conversation
install-claude-plugins.sh でトークンを python3 -c のコマンドライン引数として 渡していたため、ps aux にトークン値が露出する可能性があった。 _write_credentials_json ヘルパーを追加し、トークンを環境変数 (_CREDS_TOKEN) 経由で Python に渡すように変更。環境変数はプロセスリストに表示されないため、 他のユーザーからの参照リスクを排除する。 Co-authored-by: keito4 <keito4@users.noreply.github.com>
📝 WalkthroughWalkthroughExtracts a reusable ChangesScript Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Claude finished @keito4's task in 1m 3s —— View job コードレビュー
総評: ✅ APPROVEセキュリティ修正の方針は正しく、リファクタリングも明瞭です。指摘は minor / recommendation のみのため変更要求なし。 Security✅ 修正内容は正確
# Before(問題あり)
python3 -c "..." "$SECRET_CONTENT" "${CLAUDE_DIR}/.credentials.json"
# ^^^^^^^^^^^^^^^^^^ ps aux で見える
# After(安全)
_CREDS_TOKEN="$token" _CREDS_PATH="$dest" python3 -c "..."
# インラインenv変数はサブプロセスにのみスコープされるRecommendation: Linux では Quality✅ DRY 原則の適切な適用 3箇所に重複していた Python インラインスクリプトが ✅ インライン環境変数のスコープ _CREDS_TOKEN="$token" _CREDS_PATH="$dest" python3 -c "..."
AI ResidualsMinor(既存コード・今回のPRで導入されたものではない): creds = {'claudeAiOauth': {'accessToken': token, 'expiresAt': 9999999999999}}
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b6ec3c1ed6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| _write_credentials_json() { | ||
| local token="$1" | ||
| local dest="$2" | ||
| _CREDS_TOKEN="$token" _CREDS_PATH="$dest" python3 -c " |
There was a problem hiding this comment.
Avoid passing credentials via process environment
In environments where another process can inspect this python3 child while it is running, this still exposes the token: I checked procps ps --help all, which documents the e option as showing the environment after the command, so ps eww -p <pid> can include _CREDS_TOKEN=.... Since this change is meant to remove process-list credential exposure, pass the token through stdin or a protected temp file instead of exporting it in the child environment.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@script/install-claude-plugins.sh`:
- Around line 62-71: The helper _write_credentials_json should stop passing the
secret via environment and instead read the token from stdin and create the
credentials file with mode 0600 atomically; change the python invocation to read
the token from sys.stdin (not os.environ), write the JSON to the target path,
and set file permissions to 0o600 (or use os.open with mode=0o600) so the file
is not created with the caller's umask, and remove any code that exports the
token into the child environment; apply the same stdin + 0600 approach to the
CLAUDE_CODE_OAUTH_TOKEN and ANTHROPIC_API_KEY branches so no secret is exposed
in the process environment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4a73ba88-47a1-4fbf-8909-5349434f5c58
📒 Files selected for processing (1)
script/install-claude-plugins.sh
|
(aside) |
|
Claude finished @keito4's task in 8m 0s —— View job CI修正完了
修正内容
問題(CodeRabbit 前回の修正(環境変数経由)は 修正後(stdin + _write_credentials_json() {
local token="$1"
local dest="$2"
- _CREDS_TOKEN="$token" _CREDS_PATH="$dest" python3 -c "
-import json, os
-token = os.environ['_CREDS_TOKEN']
-creds = {'claudeAiOauth': {'accessToken': token, 'expiresAt': 9999999999999}}
-with open(os.environ['_CREDS_PATH'], 'w') as f:
+ printf '%s' "$token" | python3 -c '
+import json, os, sys
+token = sys.stdin.read()
+dest = sys.argv[1]
+creds = {"claudeAiOauth": {"accessToken": token, "expiresAt": 9999999999999}}
+fd = os.open(dest, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
+with os.fdopen(fd, "w") as f:
json.dump(creds, f, indent=2)
-"
+' "$dest"
}
|
- _write_credentials_json で環境変数経由のトークン渡しはプロセス環境から 読み取り可能な問題があったため修正 - printf | python3 stdin 経由でトークンを渡し環境変数への露出を防ぐ - os.open で O_CREAT | O_TRUNC | mode 0o600 を指定しumaskに依存しない アトミックなファイル作成と権限設定を実現 Co-authored-by: keito4 <keito4@users.noreply.github.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
script/install-claude-plugins.sh (1)
85-91: 💤 Low valueConsider atomic permissions for the JSON copy branch.
The plain-token branch now writes with
0600atomically, but the JSON branch usescpfollowed bychmod 600, leaving a brief window where the file could be world-readable depending on umask.For consistency:
🔒 Suggested fix using install or explicit mode
if echo "$SECRET_CONTENT" | python3 -c "import sys,json; json.load(sys.stdin)" 2>/dev/null; then # JSON 形式: そのままコピー - cp "$CREDENTIALS_SECRET" "${CLAUDE_DIR}/.credentials.json" + install -m 600 "$CREDENTIALS_SECRET" "${CLAUDE_DIR}/.credentials.json" else # プレーンテキスト(トークン文字列): JSON に変換 log_info "トークン文字列を credentials JSON に変換中..." _write_credentials_json "$SECRET_CONTENT" "${CLAUDE_DIR}/.credentials.json" fi - chmod 600 "${CLAUDE_DIR}/.credentials.json"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@script/install-claude-plugins.sh` around lines 85 - 91, The branch that copies an existing JSON credential uses cp then chmod, creating a window where the file mode may be too permissive; replace that two-step approach by performing an atomic copy with the desired mode in one operation (e.g., use install -m 600 or copy to a temp file and mv with explicit chmod) when copying CREDENTIALS_SECRET to "${CLAUDE_DIR}/.credentials.json" so the resulting file is created with 0600 atomically and matches the _write_credentials_json behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@script/install-claude-plugins.sh`:
- Around line 85-91: The branch that copies an existing JSON credential uses cp
then chmod, creating a window where the file mode may be too permissive; replace
that two-step approach by performing an atomic copy with the desired mode in one
operation (e.g., use install -m 600 or copy to a temp file and mv with explicit
chmod) when copying CREDENTIALS_SECRET to "${CLAUDE_DIR}/.credentials.json" so
the resulting file is created with 0600 atomically and matches the
_write_credentials_json behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 80c461dd-1a4c-4633-8e47-5b527f637a5c
📒 Files selected for processing (1)
script/install-claude-plugins.sh
|
(aside) |
|
Claude finished @keito4's task in 3m 15s —— View job CI修正完了 ✅
原因と対処原因: 対処: CIチェック(CI / CI Fallback / Security Scans)が現在実行中です。全チェックが通過次第マージ可能になります。 |
|
🎉 This PR is included in version 1.116.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Closes #804
Summary
script/install-claude-plugins.shでトークンをpython3 -cのコマンドライン引数として渡していたため、ps aux でトークン値が露出する可能性を修正_write_credentials_jsonヘルパー関数を追加し、環境変数経由でトークンをPythonに渡すように変更Generated with Claude Code
Summary by CodeRabbit