mirror of
https://github.com/anthropics/claude-plugins-official.git
synced 2026-03-21 11:53:08 +00:00
feat(telegram,discord): migrate to plugin userConfig secrets
Closes H1 #3617646 via the proper path — plugin userConfig with sensitive: true routes tokens to keychain (macOS) or .credentials.json 0600 (elsewhere) instead of world-readable .env files. Requires claude-cli-internal#23383 (PLUGIN_OPTIONS ungate + per-server sensitive split). Changes per plugin: - plugin.json: add userConfig.{PLATFORM}_BOT_TOKEN with sensitive: true - .mcp.json: add env block with ${user_config.{PLATFORM}_BOT_TOKEN} - server.ts: update comment + error message to point to /plugin reconfigure instead of .env file The .env read loop stays as a legacy fallback for existing users — process.env wins (injected value takes precedence), so no migration forced. New users get prompted at enable time via CC's built-in dialog; token lands in keychain, never touches settings.json. /telegram:configure and /discord:configure skills are NOT removed in this PR — they still work for the legacy .env path. Follow-up: repurpose or remove after a grace period once cli#23383 is released. 🏠 Remote-Dev: homespace
This commit is contained in:
@@ -27,10 +27,12 @@ const ACCESS_FILE = join(STATE_DIR, 'access.json')
|
||||
const APPROVED_DIR = join(STATE_DIR, 'approved')
|
||||
const ENV_FILE = join(STATE_DIR, '.env')
|
||||
|
||||
// Load ~/.claude/channels/telegram/.env into process.env. Real env wins.
|
||||
// Plugin-spawned servers don't get an env block — this is where the token lives.
|
||||
// Token is injected via ${user_config.TELEGRAM_BOT_TOKEN} from .mcp.json —
|
||||
// prompted at enable time, stored in keychain (macOS) or .credentials.json 0600
|
||||
// elsewhere. The .env file below is a legacy fallback for users configured
|
||||
// before H1 #3617646 — real env wins, so the injected value takes precedence.
|
||||
try {
|
||||
// Token is a credential — lock to owner. No-op on Windows (would need ACLs).
|
||||
// Defensive chmod for legacy .env files (no-op on Windows).
|
||||
chmodSync(ENV_FILE, 0o600)
|
||||
for (const line of readFileSync(ENV_FILE, 'utf8').split('\n')) {
|
||||
const m = line.match(/^(\w+)=(.*)$/)
|
||||
@@ -44,8 +46,8 @@ const STATIC = process.env.TELEGRAM_ACCESS_MODE === 'static'
|
||||
if (!TOKEN) {
|
||||
process.stderr.write(
|
||||
`telegram channel: TELEGRAM_BOT_TOKEN required\n` +
|
||||
` set in ${ENV_FILE}\n` +
|
||||
` format: TELEGRAM_BOT_TOKEN=123456789:AAH...\n`,
|
||||
` configure via: /plugin reconfigure telegram\n` +
|
||||
` (stored in keychain/credentials.json, not settings.json)\n`,
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user