Skip to content

Commit ed95dfe

Browse files
committed
fix(security): validation skips discriminator check (Issue #7)
- validate wallet discriminator (must be 1) in create_session.rs - validate wallet discriminator in manage_authority.rs (add/remove) - validate wallet discriminator in execute.rs - validate wallet discriminator in transfer_ownership.rs
1 parent 17cbf43 commit ed95dfe

5 files changed

Lines changed: 32 additions & 1 deletion

File tree

program/src/processor/create_session.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ pub fn process(
110110
return Err(ProgramError::IllegalOwner);
111111
}
112112

113+
// Validate Wallet Discriminator (Issue #7)
114+
let wallet_data = unsafe { wallet_pda.borrow_data_unchecked() };
115+
if wallet_data.is_empty() || wallet_data[0] != AccountDiscriminator::Wallet as u8 {
116+
return Err(ProgramError::InvalidAccountData);
117+
}
118+
113119
// Verify Authorizer
114120
// Check removed: conditional writable check inside match
115121

program/src/processor/execute.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
},
55
compact::parse_compact_instructions,
66
error::AuthError,
7-
state::authority::AuthorityAccountHeader,
7+
state::{authority::AuthorityAccountHeader, AccountDiscriminator},
88
};
99
use pinocchio::{
1010
account_info::AccountInfo,
@@ -61,6 +61,11 @@ pub fn process(
6161
if wallet_pda.owner() != program_id || authority_pda.owner() != program_id {
6262
return Err(ProgramError::IllegalOwner);
6363
}
64+
// Validate Wallet Discriminator (Issue #7)
65+
let wallet_data = unsafe { wallet_pda.borrow_data_unchecked() };
66+
if wallet_data.is_empty() || wallet_data[0] != AccountDiscriminator::Wallet as u8 {
67+
return Err(ProgramError::InvalidAccountData);
68+
}
6469

6570
if !authority_pda.is_writable() {
6671
return Err(ProgramError::InvalidAccountData);

program/src/processor/manage_authority.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ pub fn process_add_authority(
133133
if admin_auth_pda.owner() != program_id {
134134
return Err(ProgramError::IllegalOwner);
135135
}
136+
// Validate Wallet Discriminator (Issue #7)
137+
let wallet_data = unsafe { wallet_pda.borrow_data_unchecked() };
138+
if wallet_data.is_empty() || wallet_data[0] != AccountDiscriminator::Wallet as u8 {
139+
return Err(ProgramError::InvalidAccountData);
140+
}
141+
142+
// Validate Wallet Discriminator (Issue #7)
143+
let wallet_data = unsafe { wallet_pda.borrow_data_unchecked() };
144+
if wallet_data.is_empty() || wallet_data[0] != AccountDiscriminator::Wallet as u8 {
145+
return Err(ProgramError::InvalidAccountData);
146+
}
136147

137148
// Validate system_program is the correct System Program (audit N2)
138149
if !sol_assert_bytes_eq(

program/src/processor/transfer_ownership.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ pub fn process(
111111
if wallet_pda.owner() != program_id || current_owner.owner() != program_id {
112112
return Err(ProgramError::IllegalOwner);
113113
}
114+
// Validate Wallet Discriminator (Issue #7)
115+
let wallet_data = unsafe { wallet_pda.borrow_data_unchecked() };
116+
if wallet_data.is_empty() || wallet_data[0] != AccountDiscriminator::Wallet as u8 {
117+
return Err(ProgramError::InvalidAccountData);
118+
}
114119

115120
// Validate system_program is the correct System Program (audit N2)
116121
if !sol_assert_bytes_eq(

tests-e2e/TEST_ISSUES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
**Status**: ✅ Fixed
3131
**Fix**: Replaced hardcoded rent calculations with `Rent::minimum_balance(space)` in `create_wallet.rs` and `manage_authority.rs`. Verified by tests.
3232

33+
### Issue #8 (Validation): Wallet Discriminator Check
34+
**Status**: ✅ Fixed
35+
**Fix**: Added `wallet_data[0] == AccountDiscriminator::Wallet` check in `create_session.rs`, `manage_authority.rs`, `execute.rs`, and `transfer_ownership.rs`.
36+
3337
## Current Status
3438
All E2E scenarios are PASSING.
3539
- Happy Path

0 commit comments

Comments
 (0)