Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.
Shell agent-teamsai-agentai-automationanthropicautonomous-agentawsbusiness-operationsclaudeclaude-codeclaude-code-plugindevopsecommerceinbox-zeroklaviyomarketingmcpmorning-briefingpr-automationshopifyterminal
fix(account-rotation): address review findings — ESM crypto import, shell injection, TOCTOU, personal data
auroracapitalf38a62fb5fac
diff --git a/claude-ops/scripts/account-rotation/daemon.mjs b/claude-ops/scripts/account-rotation/daemon.mjsindex 455b0c03..0d7ec4fc 100644--- a/claude-ops/scripts/account-rotation/daemon.mjs+++ b/claude-ops/scripts/account-rotation/daemon.mjs@@ -27,7 +27,7 @@ import {} from "fs";import { join, dirname } from "path";import { fileURLToPath } from "url";-import { execSync, spawn } from "child_process";+import { execSync, execFileSync, spawn } from "child_process";import { tmpdir } from "os";const __dirname = dirname(fileURLToPath(import.meta.url));@@ -73,9 +73,11 @@ function log(msg) {function notify(title, msg) {try {- execSync(- `osascript -e 'display notification "${msg.replace(/"/g, '\\"')}" with title "${title}"'`,- );+ // Use execFileSync to avoid shell interpretation of quotes in title/msg+ execFileSync("osascript", [+ "-e",+ `display notification "${msg.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}" with title "${title.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`,+ ], { timeout: 5000 });} catch {}}@@ -208,7 +210,7 @@ async function detectLiveAccountFromVault(config) {);if (matches.length === 1) return accountKey(matches[0]);if (matches.length > 1) {- // Multiple labels for same email (e.g. account-personal vs -team).+ // Multiple labels for same email (e.g. user-personal vs -team).// Use orgName from profile to disambiguate.const orgName = body?.organization?.name?.toLowerCase() || "";const byOrg = matches.find((a) =>@@ -541,8 +543,9 @@ async function doRotation(reason) {// When sessions hit the wall they show "not logged in" — user runs /login → instant// success because the fresh token is already in the keychain.// --session: inject /login into running sessions (safe — keychain token is pre-validated)- const result = execSync(- `node "${ROTATE_SCRIPT}" --no-browser --session --to "${targetKey}" 2>&1`,+ const result = execFileSync(+ process.execPath,+ [ROTATE_SCRIPT, "--no-browser", "--session", "--to", targetKey],{cwd: __dirname,timeout: 300_000, // 5min — session restart takes ~15s per session × up to 8 sessions@@ -616,11 +619,13 @@ async function refreshSingleToken(account) {// Save back to vaultconst svc = `Claude-Rotation-${key}`;- const escaped = JSON.stringify(parsed).replace(/"/g, '\\"');- execSync(- `security add-generic-password -U -s "${svc}" -a "${KEYCHAIN_ACCOUNT}" -w "${escaped}"`,- { timeout: 5000 },- );+ // Use execFileSync to avoid shell-escaping issues with JSON tokens+ execFileSync("security", [+ "add-generic-password", "-U",+ "-s", svc,+ "-a", KEYCHAIN_ACCOUNT,+ "-w", JSON.stringify(parsed),+ ], { timeout: 5000 });log(`[refresh] ${key}: refreshed (${((parsed.claudeAiOauth.expiresAt - Date.now()) / 3_600_000).toFixed(1)}h remaining)`,);@@ -720,9 +725,8 @@ async function mainLoop() {// Post-rotation blackout: ALL rotation triggers are suppressed for 90s// after any rotation. `claude auth status` returns stale data during this// window, which causes drift detection → re-rotation thrashing loops.- const stateForBlackout = readState();- const stateLastRotation = stateForBlackout.lastRotation- ? new Date(stateForBlackout.lastRotation).getTime()+ const stateLastRotation = state.lastRotation+ ? new Date(state.lastRotation).getTime(): 0;const effectiveLastRotated = Math.max(lastRotatedAt, stateLastRotation);const inBlackout =diff --git a/claude-ops/scripts/account-rotation/rotate.mjs b/claude-ops/scripts/account-rotation/rotate.mjsindex c4671df6..26160402 100644--- a/claude-ops/scripts/account-rotation/rotate.mjs+++ b/claude-ops/scripts/account-rotation/rotate.mjs@@ -41,6 +41,7 @@ import { join, dirname } from "path";import { fileURLToPath } from "url";import { execSync, execFileSync, spawn } from "child_process";import { tmpdir } from "os";+import { createHmac } from "node:crypto";import { askAIBrain, executeAIAction, AI_BRAIN_MAX_DECISIONS } from "./ai-brain.mjs";const __dirname = dirname(fileURLToPath(import.meta.url));@@ -546,7 +547,7 @@ function fetchGooglePassword(account) {// Generate a TOTP code from a base32 secret using the Node crypto module.// Used when an account has 2FA and we have the secret in dcli.function generateTOTP(base32Secret) {- const crypto = require("crypto");+ // Uses top-level ESM import: createHmac from "node:crypto"// Decode base32const base32chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";const clean = base32Secret.replace(/\s/g, "").toUpperCase();@@ -567,7 +568,7 @@ function generateTOTP(base32Secret) {const buf = Buffer.alloc(8);buf.writeBigUInt64BE(BigInt(counter));- const hmac = crypto.createHmac("sha1", key).update(buf).digest();+ const hmac = createHmac("sha1", key).update(buf).digest();const offset = hmac[hmac.length - 1] & 0x0f;const code =((hmac[offset] & 0x7f) << 24) |@@ -2169,7 +2170,7 @@ async function runAuthFlow(driver, account) {// so the OAuth flow can complete (org chooser → authorize → callback)if (driver._authUrl) {// For multi-org accounts (same email, multiple workspaces like- // account-personal vs account-team), force an explicit org+ // user-personal vs user-team), force an explicit org// pick BEFORE hitting /oauth/authorize. Otherwise claude.ai uses// the "last active" org silently, and both sibling vaults end up// holding the same org's token.@@ -2854,7 +2855,7 @@ async function rotate(targetEmail, opts = {}) {}if (liveEmail) {// For multi-entry emails (same email under multiple config entries,- // e.g. account-personal + account-team), prefer the entry whose+ // e.g. user-personal + user-team), prefer the entry whose// orgUuid matches live. Fall back to first email match.let liveAccount = null;if (liveOrgUuid) {@@ -3018,7 +3019,7 @@ async function rotate(targetEmail, opts = {}) {);// Org-match check: for accounts where label != email (multi-org under same- // email, like account-personal vs account-team), confirm the live+ // email, like user-personal vs user-team), confirm the live// /oauth/profile returns the expected organization. Drift here means the// OAuth flow landed on the wrong org picker — the stored token will be// usable but will double-count capacity with the sibling account.