T05 · Unauthorized Access and Privilege Escalation
- Location
- scripts/pnl.py:60
- Finding
- Unnecessary Retrieval of Wallet Balance and Token Holdings<![CDATA[ ## Vulnerability Details **File Location**: `scripts/pnl.py:60-92`, `scripts/pnl.py:136-140` **Vulnerability Type**: Excessive data access and violation of least-privilege principles **Risk Level**: Medium ### Complete Code Snippet ```python def fetch_sol_balance(wallet: str) -> float: """Get current SOL balance via public RPC""" rpc_url = (f"https://mainnet.helius-rpc.com/?api-key={HELIUS_KEY}" if HELIUS_KEY else "https://api.mainnet-beta.solana.com") try: r = requests.post(rpc_url, json={ "jsonrpc": "2.0", "id": 1, "method": "getBalance", "params": [wallet] }, headers=HEADERS, timeout=8) if r.status_code == 200: res = r.json().get("result", {}) if isinstance(res, dict) and "value" in res: return res["value"] / 1e9 except Exception: pass return -1 def fetch_token_accounts(wallet: str) -> list: """Get current token holdings""" rpc_url = (f"https://mainnet.helius-rpc.com/?api-key={HELIUS_KEY}" if HELIUS_KEY else "https://api.mainnet-beta.solana.com") try: r = requests.post(rpc_url, json={ "jsonrpc": "2.0", "id": 1, "method": "getTokenAccountsByOwner", "params": [wallet, {"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}, {"encoding": "jsonParsed"}] }, headers=HEADERS, timeout=8) if r.status_code == 200: result = r.json().get("result", {}) return result.get("value", []) except Exception: pass return [] def analyze_wallet(wallet: str, tx_limit: int = 100) -> PnLResult: result = PnLResult(wallet=wallet) # Fetch data txns = fetch_helius_transactions(wallet, tx_limit) sol_balance = fetch_sol_balance(wallet) token_accounts = fetch_token_accounts(wallet) ``` ### Technical Analysis The declared functionality requires recent swap history ...[truncated 1828 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the unused calls from `analyze_wallet`: ```python txns = fetch_helius_transactions(wallet, tx_limit) ``` 2. Delete `fetch_sol_balance` and `fetch_token_accounts` if no documented feature requires them. 3. If portfolio information is introduced as a future feature, make retrieval explicit and opt-in. 4. Document which wallet information is sent to which provider and why. 5. Cache necessary public-chain queries and apply rate limits to reduce provider exposure and quota consumption. 6. Add tests asserting that a normal PnL analysis invokes only the RPC/API operations needed for swap-history analysis. ]]>
