T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/sniper.py:126
- Finding
- Remote Swap Transaction Is Not Semantically Validated Before Signing and Submission<![CDATA[ ## Vulnerability Details **File Location**: `scripts/sniper.py:126-151` **Vulnerability Type**: Unvalidated remote transaction signing **Risk Level**: High ### Complete Code Snippet ```python async def execute_swap(quote: dict) -> dict: """Execute swap via Jupiter.""" from solders.keypair import Keypair import base58 keypair = Keypair.from_bytes(base58.b58decode(PRIVATE_KEY)) async with httpx.AsyncClient(timeout=30) as client: resp = await client.post(JUPITER_SWAP, json={ "quoteResponse": quote, "userPublicKey": str(keypair.pubkey()), "wrapAndUnwrapSol": True }) swap_data = resp.json() # Sign and send transaction from solders.transaction import VersionedTransaction import base64 tx_bytes = base64.b64decode(swap_data["swapTransaction"]) tx = VersionedTransaction.from_bytes(tx_bytes) signed = keypair.sign_message(tx.message.serialize()) rpc = get_rpc_url() send_resp = await client.post(rpc, json={ "jsonrpc": "2.0", "id": 1, "method": "sendTransaction", "params": [base64.b64encode(bytes(tx)).decode(), {"skipPreflight": True}] }) return send_resp.json() ``` ### Technical Analysis The Skill treats the serialized transaction returned by the remote Jupiter endpoint as trusted. It decodes the transaction and proceeds toward signing without inspecting its instructions, program IDs, writable accounts, recipients, transfer amounts, output mint, fee recipients, or address lookup tables. TLS reduces ordinary network interception risk, but it does not protect against compromise of the Jupiter service, DNS or certificate trust infrastructure, or an upstream dependency. A compromised service could return a transaction materially different from the requested swap. The use of `"skipPreflight": True` further removes RPC simulation that could otherwise detect some transaction fail ...[truncated 1629 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Decode and inspect every instruction before signing. - Allowlist the expected Jupiter and Solana program IDs. - Verify the input mint, output mint, maximum input amount, minimum output amount, slippage, recipient, fee accounts, and all writable accounts. - Reject unexpected transfers, approvals, program invocations, address lookup tables, or additional signers. - Compare the transaction against the locally retained quote rather than trusting the swap response. - Enable RPC preflight simulation and inspect simulation errors and balance changes. - Pin and authenticate the expected API endpoint. - Use a dedicated wallet funded only with the maximum acceptable trading loss. - Add unit and integration tests using intentionally manipulated swap transactions. ]]>
