T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/exchange.mjs:221
- Finding
- Environment Variable Bypasses Mandatory Order Confirmation<![CDATA[ ## Vulnerability Details **File Location**: `scripts/exchange.mjs:221-240` **Vulnerability Type**: Confirmation bypass and excessive trading privilege **Risk Level**: High ### Vulnerable Code ```js create_order: async ({ exchange, symbol, type, side, amount, price, market_type, params, confirmed }) => { const pendingFile = resolve(__dir, '..', '.pending-order.json'); // Internal calls (from auto-trade.mjs) bypass file-based confirmation const isInternal = process.env.AICOIN_INTERNAL_CALL === '1'; // Step 2: Confirmation — only works if a pending order file exists from Step 1 if (confirmed === 'true' || confirmed === true) { if (isInternal) { // Internal call: execute directly with provided params const ex = await getExchange(exchange, market_type); const orderParams = { ...(params || {}) }; if (exchange === 'okx' && market_type && market_type !== 'spot' && !orderParams.posSide) { if (orderParams.reduceOnly) { orderParams.posSide = side === 'buy' ? 'short' : 'long'; } else { orderParams.posSide = side === 'buy' ? 'long' : 'short'; } } const order = await ex.createOrder(symbol, type, side, amount, price, orderParams); ``` Additional write-capable operations are exposed at `scripts/exchange.mjs:380-386` and `scripts/exchange.mjs:530-547`: ```js cancel_order: async ({ exchange, symbol, order_id, market_type }) => { const ex = await getExchange(exchange, market_type); if (order_id) return ex.cancelOrder(order_id, symbol); return ex.cancelAllOrders(symbol); }, set_leverage: async ({ exchange, symbol, leverage, market_type }) => { const ex = await getExchange(exchange, market_type); return ex.setLeverage(leverage, symbol); }, ``` ```js try { return await ex.transfer(code, amount, from, to); } catch (err) { ``` ### Technical Analysis The normal order workflow stores a pending order and expects a subsequent confirmation. However, setting `AICOIN_ ...[truncated 1510 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Remove the `AICOIN_INTERNAL_CALL` bypass. - Require explicit confirmation for every financially consequential operation, including order creation, cancellation, transfers, leverage changes, and margin-mode changes. - Bind confirmation to an immutable order digest containing the exchange, symbol, side, type, amount, price, market type, and parameters. - Store confirmation state with restrictive permissions and reject expired, missing, modified, or previously consumed confirmations. - Separate read-only account functionality from trading functionality into different Skills or executables. - Require separate read-only and trading credentials, with read-only credentials as the default. - Add strict input validation and transaction-size limits. - Update `SKILL.md` to disclose every write-capable operation accurately. ]]>
