Summary
A logic flaw in Solana's Anchor framework causes programs to accept any executable program ID where the System Program is expected.
When a program assumes Anchor has validated the System Program account but the runtime actually allows arbitrary programs, attackers may gain arbitrary cross-program invocation (CPI) capabilities or bypass payment logic.
Affected context
This vulnerability appears in Solana programs built with vulnerable versions of the Anchor framework that:
- Use
Program<'a, System>accounts and rely on Anchor to validate that the passed program is the System Program - Invoke System Program instructions via CPI using that
Program<'a, System>account - Do not perform their own explicit verification of the System Program's public key
The issue arises specifically in the TryFrom<&'a AccountInfo<'a>> implementation for Program<'a, T>, where the type-level ID comparison treats T = () and T = System equivalently due to both resolving to Pubkey::default().
Exploit preconditions
- Attack surface: Solana programs compiled with affected Anchor versions that expose CPI entrypoints or on-chain logic expecting the System Program.
- Required access: Ability to invoke the vulnerable program with custom account lists (a standard capability for Solana transaction senders).
- Trigger point: Passing an arbitrary executable account in place of the System Program when the program expects
Program<'a, System>. - Why exploitation is possible: Anchor's runtime compares the expected program ID to
Pubkey::default(), causingProgram<'a, System>to be treated like the genericProgram<'a, ()>. As a result, any executable account is accepted where only the System Program should be allowed, breaking the program's assumptions about which program is being called.
Why this happens
The core issue is an improper input validation (CWE-20) in Anchor's type-to-runtime translation for Program<'a, T>.
Anchor uses the Id trait and Id::id() to decide if a program account must match a specific public key or if any executable account is acceptable. Both T = () and T = System use Pubkey::default() as their ID, so the check cannot distinguish between "generic executable program" and "the System Program".
As a result, the runtime validation step fails to enforce the intended invariant "this must be the System Program" and instead permits any executable program, undermining the safety guarantees developers expect from the Program<'a, System> type.
Potential impact
- Attackers can cause the program to perform CPI calls to an attacker-controlled program instead of the System Program.
- Payment-related logic that assumes interaction with the System Program may be bypassed or redirected.
- Authorization checks tied to specific System Program instructions can be subverted.
- On-chain state integrity can be compromised if critical flows rely on trusted System Program behavior.
- Chained exploits may be possible if the attacker-controlled program is used to pivot into other Solana programs.
General mitigation guidance
Effective mitigation focuses on strengthening account validation and reducing implicit trust in framework-level invariants:
- Explicitly validate that any
Program<'a, System>account has the expected System Program public key before using it for CPI. - Treat framework-provided type guarantees as advisory and add explicit runtime checks for critical program IDs (e.g., System, Token, and governance programs).
- Isolate high-privilege or payment-related logic so it depends on strongly validated accounts and minimal assumptions about caller-provided programs.
- Favor patterns where the program derives and validates well-known program IDs internally instead of relying solely on caller-supplied
Programaccounts. - Apply defense-in-depth by validating both the program ID and any related accounts (e.g., payer, source, and destination accounts) before executing business logic.
How teams detect issues like this
Detection can combine code-level inspection with automated checks:
- Static analysis: Search for usages of
Program<'_, System>that perform CPI without an explicit comparison against the System Program public key. - Code review: Flag any reliance on Anchor's default
Program<'a, T>validation where the specific program ID is security-critical (payments, authorization, or governance actions). - Automated review tools: Configure linters or custom analyzers to detect CPI calls into
Program<'_, System>that lack explicit ID checks or to warn on any trust inPubkey::default()-based identity. - Security testing: Design fuzzing or property tests that attempt to substitute arbitrary executable programs in place of the System Program and confirm that the program rejects them.

