logicsrc/apps/pwa/src/lib/signing-keys.mjs
sh1pt-actions-fleet[bot] b5f875837a
Some checks are pending
CI / build (push) Waiting to run
Deploy to dev2 / deploy (push) Waiting to run
test / test (push) Waiting to run
security: keep signing keys out of deployable team vaults (CLI 0.13.0) (#264)
* security: keep signing keys out of deployable team vaults (CLI 0.13.0)

After the 2026-10-27 dev2 incident, root on the box drained every wallet
whose key sat in an app.env, and deploys write app.env from team vaults.
Wallet keys, seed phrases, hsm secrets and SSH/deploy keys now stay out of
that path:

- server: a machine (deploy) key never receives a signing key from
  GET /vaults/:id/secrets (listed as `withheld`, audited as
  secrets:withheld:signing) and cannot write or delete one (403
  signing_key_machine_write). People still see them, so they can move them.
- CLI `teams push` refuses a .env holding signing keys, by name or by value
  shape (PEM private key, 0x-hex, Solana base58/byte array, mnemonic), unless
  --allow-signing-keys.
- CLI `teams pull` withholds signing keys by default; --include-signing-keys
  needs a person at a terminal, so deploy-app.sh's fallback to the logged-in
  account withholds them too.
- One name rule in packages/opencreds/src/signing-keys.ts, mirrored in
  apps/pwa/src/lib/signing-keys.mjs, both held to one fixture file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: bound the wallet-name regex, build PEM fixtures at runtime

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Anthony Ettinger <anthony@profullstack.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 19:31:28 +00:00

24 lines
1.6 KiB
JavaScript

// Copy of the NAME rule in packages/opencreds/src/signing-keys.ts (read the
// reasoning there). The server only sees secret names, so this is what it
// enforces: a machine key never receives or writes a signing key. Both copies
// are held to packages/opencreds/src/signing-keys.fixtures.json.
const norm = (name) => `_${name.toUpperCase().replace(/[^A-Z0-9]+/g, "_")}_`;
/** Seed phrases and raw key material, whatever service they belong to. */
const ALWAYS = /_(MNEMONIC|SEED_PHRASE|SEEDPHRASE|SEED_WORDS|RECOVERY_PHRASE|XPRV|XPRIV|HSM_SECRET|KEYPAIR|KEY_PAIR)_/;
/** "Private key" in any spelling, and SSH / deploy keys that open a box. */
const PRIVATE = /_(PRIVATE_KEY|PRIV_KEY|PRIVKEY|PRIVATEKEY|SIGNING_KEY|SIGNER_KEY|SSH_KEY|DEPLOY_KEY)(_|$)/;
/** App keys that sign tokens or pushes, not funds; needed by a running service. */
const SERVICE = /_(VAPID|GITHUB_APP|GH_APP|JWT|JWK|DKIM|APNS|APPLE|FIREBASE|GOOGLE|GCP|SERVICE_ACCOUNT|SAML|OIDC|WEBHOOK|TLS|SSL|CERT|CLERK|SUPABASE)_/;
/** A wallet word next to KEY / SECRET / SEED: SOLANA_SECRET_KEY, RELAYER_KEY, WALLET_SEED. */
const WALLET = /_(SOLANA|SOL|EVM|ETH|ETHEREUM|BTC|BITCOIN|WALLET|HOT_WALLET|RELAYER|TREASURY|SIGNER|OPERATOR|DEPLOYER|PAYER|FEE_PAYER)_(?:[A-Z0-9]{1,24}_){0,4}(KEY|SECRET|SEED)_/;
/** ...unless it is plainly an address, an RPC or an API credential. */
const NOT_A_KEY = /_(RPC|API|URL|ADDRESS|ADDR|PUBLIC|PUBKEY|PUB|ID|NAME)_/;
export function isSigningKeyName(name) {
const n = norm(name);
if (ALWAYS.test(n)) return true;
if (PRIVATE.test(n)) return !SERVICE.test(n);
return WALLET.test(n) && !NOT_A_KEY.test(n);
}