You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
basics/pda-rent-payer: create_new_account has no caller check — worth a note for people copying it? #671
new_account is a Signer, but it signs for itself — it is the account being
created, and the caller generates that keypair. rent_vault is a PDA on a
single literal seed, shared by everyone. So there is no authority account and
no has_one, and each call moves one rent-exempt minimum out of the shared
vault into an account the caller controls.
That is almost certainly intentional for the example's purpose — it exists to
show a PDA signing for itself, and it does that cleanly and readably. My
question is only about the people who copy it, since a rent vault is exactly
the kind of helper that gets lifted into a real program.
Would a short comment on the accounts struct be welcome? Something like:
// NOTE: this example does not restrict who may call it. A real rent vault// needs an authority check — a `has_one` against an admin recorded at// initialisation, seeds that bind the vault to one funder, or a per-caller// limit. (A bare `authority: Signer` alone is not enough — any keypair// can sign for itself.)
Happy to open a PR with just that comment if it's useful. I did not want to add
a constraint, since that would change what the example teaches.
For context: basics/checking-accounts is the example that teaches exactly this
check, so a pointer between the two might do the job on its own.
I checked the native and Pinocchio flavors too, and they are more exposed than the Anchor one.
In Anchor, new_account must sign and is created through create_account, so an attacker needs a fresh keypair per call and then has to move the lamports out.
The native and Pinocchio flavors don't create the account, they just move lamports from the vault to whatever new_account is passed (native/.../create_new_account.rs:25-26, pinocchio/.../create_new_account.rs:29-30). new_account is never checked to be a signer or to be empty, so the caller can pass their own existing wallet and get paid directly.
I confirmed it with a LiteSVM test against both flavors: an unrelated wallet funded with 0.01 SOL calls CreateNewAccount 100 times, passing itself as new_account without signing for it.
for _ in0..100{let ix = Instruction{
program_id,accounts:vec![AccountMeta::new(attacker.pubkey(),false),// new_account = attacker's own walletAccountMeta::new(rent_vault_pda,false),AccountMeta::new(solana_system_interface::program::ID,false),],data: borsh::to_vec(&MyInstruction::CreateNewAccount).unwrap(),};
svm.expire_blockhash();let tx = Transaction::new_signed_with_payer(&[ix],Some(&attacker.pubkey()),&[&attacker], svm.latest_blockhash());
svm.send_transaction(tx).unwrap();}
I agree the example shouldn't gain an authority check. Should the proposed note cover all three flavors? For native and Pinocchio it might also be worth saying that nothing requires new_account to be a new account.
Happy to help with the comments if useful, but I don't want to step on your PR, @moviendome.
Sorry for the slow reply @LeandroColombo111 , and thanks for the test. I checked both on main, you're right.
So the note goes in all three, with different wording in each.
I'll take the Anchor one, that's where I work:
// NOTE: this example does not restrict who may call it. A real rent vault
// needs an authority check: a `has_one` against an admin recorded at
// initialisation, seeds that bind the vault to one funder, or a per-caller
// limit. (A bare `authority: Signer` is not enough, any keypair can sign
// for itself.)
Btw, you're not stepping on anything. Feel free to take native and Pinocchio if you want them, you already have the tests.
One for the maintainers: should those two get the signer check instead, so the three flavors match? That's code and not a comment, so not my call. Happy to open a separate issue.
Hi @donut! I have submitted PR #759 adding the caller-check security note across all three �asics/pda-rent-payer implementations (�nchor,
ative, and pinocchio) so developers copying the snippet are aware of the unauthorized-drain risk. Happy to adjust the wording if you prefer!
Activity
LeandroColombo111 commentedon Sep 22, 2026
I checked the native and Pinocchio flavors too, and they are more exposed than the Anchor one.
In Anchor,
new_accountmust sign and is created throughcreate_account, so an attacker needs a fresh keypair per call and then has to move the lamports out.The native and Pinocchio flavors don't create the account, they just move lamports from the vault to whatever
new_accountis passed (native/.../create_new_account.rs:25-26,pinocchio/.../create_new_account.rs:29-30).new_accountis never checked to be a signer or to be empty, so the caller can pass their own existing wallet and get paid directly.I confirmed it with a LiteSVM test against both flavors: an unrelated wallet funded with 0.01 SOL calls
CreateNewAccount100 times, passing itself asnew_accountwithout signing for it.Minimal loop for the native flavor:
I agree the example shouldn't gain an authority check. Should the proposed note cover all three flavors? For native and Pinocchio it might also be worth saying that nothing requires
new_accountto be a new account.Happy to help with the comments if useful, but I don't want to step on your PR, @moviendome.
moviendome commentedon Oct 14, 2026
Sorry for the slow reply @LeandroColombo111 , and thanks for the test. I checked both on main, you're right.
So the note goes in all three, with different wording in each.
I'll take the Anchor one, that's where I work:
Btw, you're not stepping on anything. Feel free to take native and Pinocchio if you want them, you already have the tests.
One for the maintainers: should those two get the signer check instead, so the three flavors match? That's code and not a comment, so not my call. Happy to open a separate issue.
docs(pda-rent-payer): add caller authority check note to Anchor flavor (
docs(pda-rent-payer): add caller and new_account check note to Native…
docs(pda-rent-payer): add caller and new_account check note to Pinocc…
khoap1220-hue commentedon Oct 25, 2026
Hi @donut! I have submitted PR #759 adding the caller-check security note across all three �asics/pda-rent-payer implementations (�nchor,
ative, and pinocchio) so developers copying the snippet are aware of the unauthorized-drain risk. Happy to adjust the wording if you prefer!
docs(pda-rent-payer): add caller authority check security note (solan…
docs(pda-rent-payer): add caller authority check security note (#671) (…