T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/trader.py:247- Finding
Routine Shutdown Liquidates All Positions in the Connected Account
- Content
View full analysis
Vulnerability Details
File Location:
scripts/trader.py:247-251;scripts/execution_engine.py:183-190
Vulnerability Type: Missing ownership and authorization boundary for destructive account operations
Risk Level: HighVulnerable Code
python except Exception as e: logger.exception(f"Unhandled exception in main loop: {e}") finally: execution_engine.close_all_positions() ib.disconnect() logger.info("Disconnected from IBKR.")python def close_all_positions(self) -> None: """Emergency close all open positions (shutdown hook).""" positions = self.get_positions() logger.warning(f"Closing all {len(positions)} positions...") for pos in positions: self.close_trade(pos)The invoked closing operation submits an opposing market order for each returned account position:
python def close_trade(self, position: Position) -> bool: """Market-close an open position.""" symbol = position.contract.symbol qty = abs(int(position.position)) action = "SELL" if position.position > 0 else "BUY" contract = position.contract try: order = MarketOrder(action, qty) trade = self.ib.placeOrder(contract, order) self.ib.sleep(1) logger.info(f"Closing position: {action} {qty}x {symbol}") return True except Exception as e: logger.error(f"close_trade({symbol}) failed: {e}") return FalseTechnical Analysis
The shutdown hook obtains every position visible through
ib.positions()and submits a market order to close each one. It does not distinguish between positions created by this Skill and positions created manually, by another IBKR client, or by another automated strategy.The same destructive operation runs after an ordinary keyboard interrupt and after any unhandled exception. A routine process termination is therefore treated as an account-w ...[truncated 1312 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove account-wide liquidation from the routine
finallyblock. Routine shutdown should cancel or close only explicitly owned resources, then disconnect. - Assign a unique
orderRefor equivalent ownership marker to every order created by the Skill. - Persist permanent order IDs and reconcile them with current positions before performing any close operation.
- Limit shutdown handling to positions demonstrably created by the current strategy and account.
- Make account-wide liquidation a separate emergency command requiring explicit confirmation and, for live accounts, an additional authorization control.
- Cancel outstanding child orders before closing a Skill-owned position to prevent later duplicate or reversing fills.
- Add tests with mixed manual and Skill-owned positions to verify that unrelated positions are never modified.
- Remove account-wide liquidation from the routine
