mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-04-12 06:03:08 +00:00
feat: add owner_program_id field to AccountWithMetadata
Programs can now verify that input accounts are owned by themselves,
preventing spoofing attacks where malicious programs pass fake accounts
with matching data layouts.
Changes:
- Add optional owner_program_id field to AccountWithMetadata
- Add with_owner_program_id() builder method
- Backward compatible: serde(default) = None for existing data
Usage in programs:
if let Some(owner) = account.owner_program_id {
assert_eq!(owner, SELF_PROGRAM_ID, 'account not owned by this program');
}
Fixes #347
This commit is contained in:
parent
fb083ce91e
commit
cc43721cac
@ -126,6 +126,11 @@ pub struct AccountWithMetadata {
|
||||
pub account: Account,
|
||||
pub is_authorized: bool,
|
||||
pub account_id: AccountId,
|
||||
/// The program that owns this account. Programs can use this to verify
|
||||
/// that an input account is owned by themselves, preventing spoofing attacks.
|
||||
/// See: https://github.com/logos-blockchain/logos-execution-zone/issues/347
|
||||
#[serde(default)]
|
||||
pub owner_program_id: Option<crate::program::ProgramId>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "host")]
|
||||
@ -135,8 +140,14 @@ impl AccountWithMetadata {
|
||||
account,
|
||||
is_authorized,
|
||||
account_id: account_id.into(),
|
||||
owner_program_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_owner_program_id(mut self, program_id: crate::program::ProgramId) -> Self {
|
||||
self.owner_program_id = Some(program_id);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user