T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/wallet.js:7
- Finding
- Live Wallet Operations Are Executed by the Package Test Command<![CDATA[ ## Vulnerability Details **File Location**: `package.json:6-8`; `scripts/wallet.js:7-25` **Vulnerability Type**: Unsafe automatic financial operations **Risk Level**: High ### Vulnerable Code `package.json:6-8`: ```json "main": "scripts/wallet.js", "scripts": { "test": "node scripts/wallet.js" } ``` `scripts/wallet.js:7-25`: ```js // Check balance const { balance } = await client.getBalance(); console.log(`Balance: ${Math.floor(balance / 1000)} sats`); // Pay a BOLT11 invoice await client.payInvoice({ invoice: "lnbc...", amount: 1000 * 1000 // msats explicitly }); // Pay a Lightning address const ln = new LN(process.env.ALBY_NWC_URL); await ln.pay("user@getalby.com", SATS(100)); // Create an invoice to receive const result = await client.makeInvoice({ amount: 2000 * 1000, description: "Payment" }); console.log(result.invoice); ``` ### Technical Analysis The package maps the conventional `npm test` command to `scripts/wallet.js`, but that file is not a test suite. It connects to the wallet identified by the spending-capable `ALBY_NWC_URL` credential and performs operations against that live wallet. The script reads and logs the balance, attempts to pay a BOLT11 invoice, contains a hard-coded 100-satoshi transfer to `user@getalby.com`, and creates a receiving invoice. These operations occur immediately through top-level statements without an explicit payment confirmation, test-mode check, mocked client, or environment guard. The placeholder invoice (`lnbc...`) will ordinarily cause the first payment call to fail and prevent subsequent statements from running. However, an expected failure is not a valid security boundary. If the invoice is replaced with a valid value, accepted unexpectedly by a client implementation, or the execution flow is modified, the hard-coded Lightning-address payment becomes reachable. The README documents only `send_sats.mjs` and `pay_bolt11.mjs` as provided scripts. It does not disclose that ...[truncated 1249 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove live wallet operations from the package test command. 2. Replace the current command with a genuine unit-test suite that uses a mocked `NWCClient` and performs no external network or wallet operations. 3. Remove `scripts/wallet.js` as the package entry point unless it is intended to be a supported executable. 4. Convert demonstration operations into non-executable documentation examples. 5. If a live integration test is necessary, require all of the following: - An explicit opt-in environment variable such as `ALLOW_LIVE_WALLET_TESTS=true`. - A separate NWC credential with a minimal spending allowance. - An explicit recipient and amount supplied by the operator. - A confirmation step before every payment. - A clearly named command such as `npm run test:live-wallet`. 6. Do not log wallet balances in routine tests or CI output. 7. Document every executable script and its financial side effects in the README. ]]>
