A callback is a function invoked automatically during an operation, often when a token is sent or received. In smart contracts, callbacks can create reentry opportunities because they hand control to another contract before the original transaction has fully completed.
What a callback is and why it matters
A callback is a function that runs automatically at a specific point in another operation. In security-sensitive code, that handoff matters because the caller may temporarily yield control before the original flow has fully finished, which changes the trust and execution boundary.
In practice, callbacks are used to make code extensible, event-driven, or asynchronous. They are common in user interfaces, libraries, payment flows, token handling, and smart contracts, where an external component or another contract is allowed to execute logic at a defined moment.
The key security characteristic is not the callback itself, but the fact that it can execute at a boundary where the surrounding state may be incomplete, mutable, or not yet finalised. That is why callbacks are often part of reentry discussions in API security and smart contract analysis.
How callbacks change control flow
Callbacks invert the normal top-down flow by letting the callee or runtime invoke code back into the original system. That makes them powerful for hooks, listeners, and asynchronous completion handlers, but it also means the system must be clear about what state is safe to expose before the callback runs.
In ordinary software, callbacks may be benign and routine. In blockchain and other transaction-oriented systems, they can become security-sensitive because the callback can occur before balances, permissions, or bookkeeping have been fully committed. If the callback can re-enter the original function, the code may behave as if the operation has not yet happened.
This is why callback-heavy code is usually reviewed for ordering, state updates, and trust boundaries. A useful comparison is with externally controlled execution paths that depend on a contract or library following the expected order rather than enforcing it itself.
Common failure modes and examples
The main failure mode is unexpected reentry, where the callback gets enough authority to call back into the original system before the original action is complete. That can lead to duplicate withdrawals, repeated state transitions, inconsistent records, or bypassed checks if the code assumes the callback will be passive.
Another failure mode is overtrusting the callback recipient. If the callback target is untrusted or only partially trusted, the original system may hand over too much control too early. This is especially relevant when a callback is triggered by receiving a token, processing a message, or interacting with another contract that can execute arbitrary logic.
Callbacks also create debugging and review challenges because the visible line of code does not show the full execution path. The real risk often appears only when a callback chain crosses component boundaries, especially if the surrounding code uses stale assumptions about state, authorization, or completion.
How to reason about callback safety
Why practitioners should care: Treat any callback that can cross a trust boundary as a control-flow decision, not just a programming convenience. The safest designs make the post-callback state explicit, minimise what is exposed before the callback, and avoid assuming that the callback will return control unchanged.
What to watch for: Review any callback that can invoke external code, especially in token transfers, smart contracts, plugin systems, and event handlers. If the callback can observe or influence state before the initiating operation finishes, the implementation needs stronger ordering and validation discipline.
Practitioner takeaway: Callbacks are ordinary in software design, but they become security-relevant when they cross boundaries where execution order, state finality, or trust assumptions matter.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Agentic AI Top 10, OWASP Non-Human Identity Top 10 and MITRE ATT&CK address the attack and risk surface, while CIS Controls v8 and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Agentic AI Top 10 | A2 — Tool and Action Misuse | Callbacks can hand execution back to untrusted logic or tools. |
| Recommendation — Restrict callback authority to the minimum action set needed and validate every external handoff. | ||
| OWASP Non-Human Identity Top 10 | NHI-04 — Unauthorized Access and Overprivilege | Callback-driven control transfer can expose overbroad authority during execution. |
| Recommendation — Limit what callback recipients can do before state is finalised. | ||
| CIS Controls v8 | 8 — Audit Log Management | Callback paths need traceability when control flow crosses trust boundaries. |
| Recommendation — Log callback entry, exit, and state-changing actions for later review. | ||
| MITRE ATT&CK | T1210 — Exploitation of Remote Services | External callbacks can be abused to pivot through exposed execution paths. |
| Recommendation — Hunt for callback-triggered pivots that abuse externally reachable services. | ||
| NIST CSF 2.0 | PR.AC-4 — Access Permissions and Authorizations | Callback execution should not exceed the permissions required for the operation. |
| Recommendation — Apply least privilege to callback execution paths and dependent components. | ||