Rules › Solidity
tx.origin used for authorization
Checking tx.origin lets any contract the owner interacts with act as the owner.
Why it matters
tx.origin is the externally owned account that started the transaction, however many contracts it passed through. If an owner calls any malicious contract (a token, an airdrop claim, an NFT mint), that contract can call yours and pass a tx.origin == owner check. msg.sender is the immediate caller, which is what authorization needs.
Vulnerable
function sweep(address payable to) external {
require(tx.origin == owner, "not owner");
to.transfer(address(this).balance);
}
Fixed
function sweep(address payable to) external onlyOwner {
(bool ok, ) = to.call{value: address(this).balance}("");
if (!ok) revert TransferFailed();
}
What other tools call it
| Tool | Detector or reference |
|---|---|
| Slither | tx-origin |
| Solhint | avoid-tx-origin |
| SWC registry | SWC-115 |
Check your code
Paste a contract into the in-browser checker, or let the Claude Code plugin scan before every deploy. The quick check for this rule is a pattern match: treat a hit as "look here", and a miss as no guarantee.
Related rules
- State written after an external call (reentrancy)
- Return value of a low-level call is ignored
- delegatecall to an address the caller controls
- Initializer anyone can call
- Privileged function without access control
- selfdestruct in contract code
Static analysis finds known bug classes; it can't prove code is safe and isn't an audit. Get a professional audit before deploying code that will hold value.