{"slug": "your-agent-s-vault-checks-tx-origin-a-malicious-contract-can-pay-itself", "title": "Your agent's vault checks tx.origin. A malicious contract can pay itself.", "summary": "A developer demonstrated that a small Solidity vault contract written for an AI agent to pay for API calls is exploitable because it authenticates with tx.origin instead of msg.sender, letting a malicious contract called by the owner's wallet invoke allow() and pay() in the same transaction to drain funds. Running the 25-line contract through the free Kestrova preview (automated Slither analysis) flagged arbitrary-send-eth as High, and the developer also noted that pay() ignores the return value of its ETH transfer, so an agent can record a payment that never left. The fix replaces tx.origin with msg.sender via an onlyOwner modifier and reverts when the transfer fails.", "body_md": "Agents are starting to hold money. A common pattern is a small vault: the owner funds it, an AI agent calls `pay()` when it needs an API or a service, and an allowlist keeps the agent from paying just anyone.\n\nIt is also the kind of contract a coding agent writes in a few seconds when you ask for one. Here is a version that compiles, passes a happy-path test and looks reasonable at a glance:\n\n```\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\n/// A small vault an AI agent uses to pay for API calls on its owner's behalf.\ncontract AgentVault {\n    address public owner;\n    mapping(address => bool) public allowedPayee;\n\n    constructor() {\n        owner = msg.sender;\n    }\n\n    function allow(address payee) external {\n        require(tx.origin == owner, \"not owner\");\n        allowedPayee[payee] = true;\n    }\n\n    function pay(address payee, uint256 amount) external {\n        require(tx.origin == owner, \"not owner\");\n        require(allowedPayee[payee], \"payee not allowed\");\n        payee.call{value: amount}(\"\");\n    }\n\n    receive() external payable {}\n}\n```\n\nThere are two problems in it, and both are the kind that survive a quick review because the code \"has a require\".\n\nI ran this file through the free Kestrova preview (automated Slither analysis, no account and no wallet). The result, unedited:\n\nThe preview names each issue and explains why it matters. It doesn't give the file, line or fix, but in a 25-line contract you don't need them.\n\n`tx.origin` is the externally owned account that started the transaction, not the contract or account that called you directly. `msg.sender` is the direct caller.\n\nSo `require(tx.origin == owner)` really says: \"allow this if the owner started the transaction, whatever path it took to get here.\" Picture the owner's wallet, or an agent signing with the owner's key, calling some other contract: a token claim, a swap router, an \"airdrop checker\" a tool suggested. If that contract is malicious, it can call `AgentVault.allow(attacker)` and then `pay(attacker, balance)` in the same transaction. Both checks pass, because `tx.origin` is still the owner.\n\nAgents make this easier to trigger, not harder. They interact with many contracts, often ones they found a minute ago, and they sign more transactions than a careful human would. Any of those transactions can carry a hidden call back into your vault.\n\nThat is also why the scanner raises **arbitrary-send-eth** to High. `pay()` sends ETH to an address the caller chooses, and the only thing protecting it is a weak check. The allowlist doesn't help, because the attacker can add itself through `allow()` first.\n\n`payee.call{value: amount}(\"\")` returns a success flag. The contract ignores it. If the payee reverts (a contract with no `receive`, an out-of-gas callback), `pay()` still succeeds.\n\nFor a person that's an annoyance. For an agent it's a logic bug: the agent sees a successful transaction, marks the API call as paid and moves on, while the money never left. Some agents will then retry with a fresh payment, and the books stop matching reality.\n\n```\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\ncontract AgentVault {\n    address public immutable owner;\n    mapping(address => bool) public allowedPayee;\n\n    error NotOwner();\n    error PayeeNotAllowed();\n    error PaymentFailed();\n\n    constructor() {\n        owner = msg.sender;\n    }\n\n    modifier onlyOwner() {\n        if (msg.sender != owner) revert NotOwner();\n        _;\n    }\n\n    function allow(address payee) external onlyOwner {\n        allowedPayee[payee] = true;\n    }\n\n    function pay(address payable payee, uint256 amount) external onlyOwner {\n        if (!allowedPayee[payee]) revert PayeeNotAllowed();\n        (bool ok, ) = payee.call{value: amount}(\"\");\n        if (!ok) revert PaymentFailed();\n    }\n\n    receive() external payable {}\n}\n```\n\nThree changes:\n\n`msg.sender` instead of `tx.origin`, in one `onlyOwner` modifier. A contract in the middle of the call chain is now the caller, so it fails the check.`owner` is `immutable`, which removes a storage read and makes it clear it never changes.\nRunning the fixed file through the same preview gives: High 0, Medium 0, one Informational note (`low-level-calls`), which just records that the contract uses `.call`. That's expected here, since `.call` is the recommended way to send ETH.\n\nIf the agent itself should be able to pay, give the agent its own key and check `msg.sender == agent` for `pay()` only, keeping `allow()` owner-only. Never solve it by going back to `tx.origin`.\n\nThe useful part isn't this one contract. It's making the check happen every time an agent writes or changes Solidity, before anyone deploys.\n\n`https://kestrova-api.onrender.com/mcp` to Claude Code, Cursor, VS Code, Claude.ai or ChatGPT (no sign-in). The agent can call `scan_solidity_preview` after editing a contract and fix what it finds before showing you the diff.`scan_contract_address_preview`.\nThis is automated Slither analysis, not an audit. It catches known patterns like the ones above. It won't prove the vault is correct, and it says nothing about business logic, key management or whether the payees are honest. A clean result means \"no known pattern was found\", nothing more.\n\nPaste the first contract above into the scanner at [https://kestrova.dev](https://kestrova.dev) and compare the result with the fixed version. If you're building agents that hold or move funds, I'd like to hear which checks you run before an agent touches a contract.", "url": "https://wpnews.pro/news/your-agent-s-vault-checks-tx-origin-a-malicious-contract-can-pay-itself", "canonical_source": "https://dev.to/kestrova/your-agents-vault-checks-txorigin-a-malicious-contract-can-pay-itself-m28", "published_at": "2026-11-30 23:03:41+00:00", "updated_at": "2026-11-30 23:15:59.146872+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "artificial-intelligence"], "entities": ["Kestrova", "Slither", "AgentVault"], "also_reported_by": [], "takeaway": "Vault contracts that gate payments with require(tx.origin == owner) can be drained by any malicious contract the owner's wallet or agent calls, since tx.origin stays the owner through the whole call chain; use msg.sender in an onlyOwner modifier and revert when the ETH transfer returns false.", "recommendation": {"advice": "Authenticate agent vault payments with msg.sender, not tx.origin, and check the return value of every ETH transfer so a reverted payment cannot be recorded as paid.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/your-agent-s-vault-checks-tx-origin-a-malicious-contract-can-pay-itself", "markdown": "https://wpnews.pro/news/your-agent-s-vault-checks-tx-origin-a-malicious-contract-can-pay-itself.md", "text": "https://wpnews.pro/news/your-agent-s-vault-checks-tx-origin-a-malicious-contract-can-pay-itself.txt", "jsonld": "https://wpnews.pro/news/your-agent-s-vault-checks-tx-origin-a-malicious-contract-can-pay-itself.jsonld"}}