mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 06:21:59 +09:00
* feat(plugins): sensitive userConfig secrets, readSecret helper, plugin secrets audit (ADR-506) - ruflo-cost-tracker, ruflo-metaharness: `openrouterApiKey`; ruflo-x-gateway: `adminToken`. Each is type string, sensitive, optional, no default. - readSecret(name, envFallbacks): CLAUDE_PLUGIN_OPTION_<NAME> first, then the variables the plugin always read. Copied per plugin (x-gateway in src/, the only folder its Docker image ships); a test keeps the copies identical. - Consumers: openrouter.mjs key/generation, x-gateway checkAdmin (call time, fail closed), redblue child env (OPENROUTER_API_KEY, never argv). - scripts/audit-plugin-secrets.mjs: credential-named option without sensitive: true, or a literal secret (the mods' COMMON_SECRETS, parsed from screen.ts) in plugin.json/hooks.json, fails. Wired into plugin-package-audit. Co-Authored-By: RuFlo <ruv@ruv.net> * docs(adr): ADR-506 status points at PR #4587 Co-Authored-By: RuFlo <ruv@ruv.net> * fix(plugins): deliver the ADR-506 secret option, harden the plugin secrets audit Review fixes for #4587: - Delivery: Claude Code gives a plugin option only to the plugin's own hooks and MCP servers, never to the Bash tool that runs openrouter.mjs and the redblue skill path. ruflo-cost-tracker and ruflo-metaharness now carry a SessionStart hook (scripts/_secret-env.cjs) that writes the sensitive openrouterApiKey option to CLAUDE_ENV_FILE as OPENROUTER_API_KEY, only when that variable is unset. Live-verified with Claude Code 2.1.289 (probe plugin and the real cost-tracker): a Bash tool command resolved the key. - ruflo-x-gateway adminToken removed: the gateway is a deployed server that no Claude Code process of the plugin runs, so the option could never arrive. - Audit: a secret used as a JSON key is shown as <redacted-key> and never printed; .mcp.json and .lsp.json are scanned; OpenRouter key shape added; credential-named env/headers entries holding a 16+ char literal fail; ${user_config.*} in command/headersHelper/args fails. - ADR-506 updated with the delivery trade-off and what the bridge does not reach (the metaharness_redblue MCP tool in ruflo-core's server). Co-Authored-By: RuFlo <ruv@ruv.net> * test(plugins): skip the bash-only ADR-506 bridge tests on Windows; hedge env-file mode wording Co-Authored-By: RuFlo <ruv@ruv.net> * chore(plugins): cost-tracker 0.29.0, metaharness 0.3.0 for ADR-506 Co-Authored-By: RuFlo <ruv@ruv.net> --------- Co-authored-by: r <r@x>
36 lines
2.0 KiB
JavaScript
36 lines
2.0 KiB
JavaScript
// readSecret: one way to read a plugin credential (ADR-506). Copied verbatim into each plugin that
|
|
// needs it, since a plugin may not import from another plugin's folder; keep the copies identical
|
|
// (a test compares them).
|
|
//
|
|
// Order: CLAUDE_PLUGIN_OPTION_<NAME>, which Claude Code sets for a plugin's hooks when the
|
|
// `userConfig` option (declared with "sensitive": true, kept in the credential store) is filled in;
|
|
// then the environment variables the plugin always read, for standalone CLI use and backward
|
|
// compatibility. The value is never logged, echoed, or placed in an error message.
|
|
|
|
/** The environment variable Claude Code sets for a `userConfig` key (non-identifier characters to `_`, upper-cased). */
|
|
export const optionEnvName = (name) => `CLAUDE_PLUGIN_OPTION_${String(name).replace(/[^A-Za-z0-9_]/g, '_').toUpperCase()}`
|
|
|
|
/** The secret, or undefined when neither the option nor any fallback variable holds a non-empty value. Read at call time. */
|
|
export function readSecret(name, envFallbacks = [], env = process.env) {
|
|
for (const variable of [optionEnvName(name), ...envFallbacks]) {
|
|
const value = env[variable]
|
|
if (typeof value === 'string' && value.trim() !== '') return value
|
|
}
|
|
return undefined
|
|
}
|
|
|
|
/** Where the secret was found (a variable NAME, never the value), or undefined. */
|
|
export function secretSource(name, envFallbacks = [], env = process.env) {
|
|
for (const variable of [optionEnvName(name), ...envFallbacks]) {
|
|
const value = env[variable]
|
|
if (typeof value === 'string' && value.trim() !== '') return variable
|
|
}
|
|
return undefined
|
|
}
|
|
|
|
/** Error text for a missing secret: names the option and the variables, never a value. */
|
|
export function secretHint(name, envFallbacks = []) {
|
|
const vars = envFallbacks.length ? ` or export ${envFallbacks.join(' / ')} in your shell` : ''
|
|
return `no ${name} configured: set the plugin option "${name}" with /plugin (it is stored in the credential store)${vars}. Never paste a key into a prompt or a file.`
|
|
}
|