Skip to content

fix: セキュリティ修正 トークンをコマンドライン引数からenv変数経由に変更 - #807

Merged
keito4 merged 3 commits into
mainfrom
claude/issue-804-20260607-0300
Jun 8, 2026
Merged

fix: セキュリティ修正 トークンをコマンドライン引数からenv変数経由に変更#807
keito4 merged 3 commits into
mainfrom
claude/issue-804-20260607-0300

Conversation

@keito4

@keito4 keito4 commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Closes #804

Summary

  • script/install-claude-plugins.sh でトークンを python3 -c のコマンドライン引数として渡していたため、ps aux でトークン値が露出する可能性を修正
  • _write_credentials_json ヘルパー関数を追加し、環境変数経由でトークンをPythonに渡すように変更

Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Streamlined the plugin installation script's credential setup by consolidating repeated credential-to-JSON conversion steps into a single centralized helper. This reduces duplication and simplifies maintenance while preserving existing behavior, directory/permission handling, and installation outcomes; there is no user-facing change.

install-claude-plugins.sh でトークンを python3 -c のコマンドライン引数として
渡していたため、ps aux にトークン値が露出する可能性があった。

_write_credentials_json ヘルパーを追加し、トークンを環境変数 (_CREDS_TOKEN)
経由で Python に渡すように変更。環境変数はプロセスリストに表示されないため、
他のユーザーからの参照リスクを排除する。

Co-authored-by: keito4 <keito4@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Extracts a reusable _write_credentials_json helper in script/install-claude-plugins.sh and updates the BuildKit, CLAUDE_CODE_OAUTH_TOKEN, and ANTHROPIC_API_KEY credential branches to call the helper when generating ${CLAUDE_DIR}/.credentials.json.

Changes

Script Refactoring

Layer / File(s) Summary
Helper function definition
script/install-claude-plugins.sh
Adds _write_credentials_json that reads a token from stdin and writes a credentials JSON file with 0600 permissions using an embedded python3 -c snippet.
Credential setup refactoring
script/install-claude-plugins.sh
Replaces three inline python3 -c token→JSON conversions (BuildKit secret, CLAUDE_CODE_OAUTH_TOKEN, ANTHROPIC_API_KEY) with calls to _write_credentials_json.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • keito4/config#636: Both PRs modify script/install-claude-plugins.sh to generate ${CLAUDE_DIR}/.credentials.json using python3 serialization from tokens.
  • keito4/config#633: Both PRs modify credential token-to-.credentials.json conversion logic for BuildKit secret/token values in the same script.
  • keito4/config#635: Both PRs modify the credential-loading logic path in script/install-claude-plugins.sh at the token conversion level.

Suggested labels

size/XS

Poem

🐰 A tiny helper hops in place,
Pipes a token, writes with grace,
Three repeats folded into one,
Permissions set, the job is done,
Hooray — fewer duplications!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the summary and what was changed, but lacks sections for 'Why', 'How to test', and the complete Checklist as specified in the repository template. Add missing template sections: expand 'Why' with rationale, include detailed 'How to test' steps, and complete the Checklist with appropriate checks marked.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies a security fix related to changing token handling from command-line arguments to environment variables, which directly matches the main change in the changeset.
Linked Issues check ✅ Passed The PR successfully addresses the security concern from #804 by preventing token exposure via process arguments through stdin-based environment variable passing and atomic file creation with secure permissions.
Out of Scope Changes check ✅ Passed All changes are scoped to the security fix in script/install-claude-plugins.sh, refactoring token handling to use environment variables instead of command-line arguments as required by #804.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-804-20260607-0300

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude

claude Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Claude finished @keito4's task in 1m 3s —— View job


コードレビュー

  • 変更ファイルの確認
  • セキュリティ観点のレビュー
  • コード品質・AI Residuals 確認
  • レビューコメント投稿

総評: ✅ APPROVE

セキュリティ修正の方針は正しく、リファクタリングも明瞭です。指摘は minor / recommendation のみのため変更要求なし。


Security

✅ 修正内容は正確

sys.argv[1] 経由でトークンを渡すと ps aux のコマンドライン引数として平文露出するという問題が正しく修正されています。

# Before(問題あり)
python3 -c "..." "$SECRET_CONTENT" "${CLAUDE_DIR}/.credentials.json"
#                  ^^^^^^^^^^^^^^^^^^ ps aux で見える

# After(安全)
_CREDS_TOKEN="$token" _CREDS_PATH="$dest" python3 -c "..."
# インラインenv変数はサブプロセスにのみスコープされる

Recommendation: Linux では /proc/<pid>/environ 経由で同一 UID または root から環境変数を読むことは技術的に可能ですが、コマンドライン引数露出と比べて攻撃面は格段に小さく、今回のアプローチは実用的に十分です。


Quality

✅ DRY 原則の適切な適用

3箇所に重複していた Python インラインスクリプトが _write_credentials_json ヘルパーに統一され、可読性・保守性が向上しています。

✅ インライン環境変数のスコープ

_CREDS_TOKEN="$token" _CREDS_PATH="$dest" python3 -c "..."

VAR=value command 構文によりこれらの変数は親シェル環境に漏れません。正しいアプローチです。


AI Residuals

Minor(既存コード・今回のPRで導入されたものではない): script/install-claude-plugins.sh:68

creds = {'claudeAiOauth': {'accessToken': token, 'expiresAt': 9999999999999}}

expiresAt: 9999999999999 はマジックナンバーです。今回の変更で導入されたものではありませんが、将来的に定数として定義するか、コメントで意図(実質的な無期限を表す)を明記するとよいでしょう。

Fix this →


@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread script/install-claude-plugins.sh Outdated
_write_credentials_json() {
local token="$1"
local dest="$2"
_CREDS_TOKEN="$token" _CREDS_PATH="$dest" python3 -c "

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@keito4 keito4 self-assigned this Jun 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between dfefa8f and b6ec3c1.

📒 Files selected for processing (1)
  • script/install-claude-plugins.sh

Comment thread script/install-claude-plugins.sh Outdated
@keito4

keito4 commented Jun 8, 2026

Copy link
Copy Markdown
Owner Author

(aside)
@claude PRがbaseにマージする際にCIが落ちています。
修正してください。

@claude

claude Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Claude finished @keito4's task in 8m 0s —— View job


CI修正完了

  • コンテキスト把握
  • CIの失敗内容を確認
  • 失敗原因の特定
  • 修正実施
  • shellcheck / lint / format / unit tests チェック(343テスト全通過)
  • コミット・プッシュ(ec9e766

修正内容

_write_credentials_json ヘルパーをさらにセキュリティ強化しました。

問題(CodeRabbit 🟠 Major / Codex P2 指摘)

前回の修正(環境変数経由)は _CREDS_TOKEN/proc/<pid>/environ から同一UID・rootに読み取れる脆弱性が残っていました。

修正後(stdin + os.open で 0600 アトミック作成)

 _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"
 }
対策 効果
printf '%s' | python3 (stdin) コマンドライン引数・環境変数どちらにもトークン非露出
os.open(..., 0o600) umask 非依存でファイル作成時に 0600 を保証
os.O_CREAT | os.O_TRUNC アトミックな作成/上書き

- _write_credentials_json で環境変数経由のトークン渡しはプロセス環境から
  読み取り可能な問題があったため修正
- printf | python3 stdin 経由でトークンを渡し環境変数への露出を防ぐ
- os.open で O_CREAT | O_TRUNC | mode 0o600 を指定しumaskに依存しない
  アトミックなファイル作成と権限設定を実現

Co-authored-by: keito4 <keito4@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
script/install-claude-plugins.sh (1)

85-91: 💤 Low value

Consider atomic permissions for the JSON copy branch.

The plain-token branch now writes with 0600 atomically, but the JSON branch uses cp followed by chmod 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

📥 Commits

Reviewing files that changed from the base of the PR and between b6ec3c1 and ec9e766.

📒 Files selected for processing (1)
  • script/install-claude-plugins.sh

@keito4

keito4 commented Jun 8, 2026

Copy link
Copy Markdown
Owner Author

(aside)
@claude PRがbaseにマージする際にCIが落ちています。
修正してください。

@claude

claude Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Claude finished @keito4's task in 3m 15s —— View job


CI修正完了 ✅

  • CIの失敗内容を確認
  • 失敗原因の特定 → mergeStateStatus: BEHIND(mainが1コミット先行)
  • ブランチをmainの最新に更新(gh pr update-branch 807
  • CIが再トリガーされ実行中

原因と対処

原因: mainに PR #805(dependabot actions-minor update: 5159eba)がマージされており、このブランチが1コミット遅れていたため mergeStateStatus: BEHIND 状態でした。

対処: gh pr update-branch でmainの最新変更をブランチにマージしました(マージコミット 5516ee5)。

CIチェック(CI / CI Fallback / Security Scans)が現在実行中です。全チェックが通過次第マージ可能になります。
| ブランチ

@keito4
keito4 merged commit 85b9223 into main Jun 8, 2026
16 checks passed
@keito4
keito4 deleted the claude/issue-804-20260607-0300 branch June 8, 2026 12:28
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.116.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released リリース済み label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

セキュリティ問題の調査

1 participant