Replayable recovery requests allow attacker to permanently block account recovery
Recovery requests were signed but not bound to the account version or a nonce, so an old recovery request could be replayed to overwrite the current recovery key. An attacker could keep replaying an old request so guardians encrypt shares to a key the user no longer holds, permanently blocking account recovery.
Submitted by Rhaydden, also found by 0xanony, 0xAsen, 0xnija, 0xpetern, Agontuk, akupemulaygbaik, Alradyin, aman234, arkheionx, boodieboodieboo, bunnyhunter, clems4ever, cosin3, count-sum, czarcas7ic, eloujoe, Guilherme, holtzzx, kind0dev, Legend, maxim371, montecristo, niffylord, oxwhite, REHEroadchick, RotiTelur, SanketKogekar, th3_hybrid, tradingview, vangrim, Yu4n, Ziusz, zubyoz, and zzebra83
lib/src/account/v0.rs #L118-L127
The account recovery protocol lets a user who holds a RecoveryInitiationKey initiate recovery by posting a Recovery-type AccountUpdate to the contract. The core issue is that these recovery requests are authenticated but not bound to any notion of freshness or account version. As a result, any previously valid recovery request can be replayed at any time in the future, even after a newer recovery request has been made, and the contract will accept it and overwrite the newer request.
The recovery request that is signed by the RIK-derived key is RecoveryRequestMessage:
#[derive(Serialize)]
#[cfg_attr(test, derive(Clone))]
pub(crate) struct RecoveryRequestMessage {
pub(crate) account_id: AccountId,
pub(crate) recovery_pke: pke::EncryptionKey,
}
impl Tagged for RecoveryRequestMessage {
const SEPARATOR: &'static str = "v0:recovery-request";
}
This message only includes the account_id and the new recovery_pke. It doesnt include the current account version (cnt), any nonce, or timestamp.
On the client side, AccountStateV0::initiate_recovery signs this message using the RIK based signing key and constructs an AccountUpdate of type Recovery:
pub fn initiate_recovery<R: Rng + CryptoRng>(
&self,
rng: &mut R,
acc: AccountId,
rik: &RecoveryInitiationKey,
) -> Result<(AccountUpdate, RecoverySecrets)> {
// decrypt AssociationsV0 using RIK, then:
let dkey = pke::DecryptionKey::gen(rng);
let sig = encap.key_sig.sign(
rng,
&RecoveryRequestMessage {
account_id: acc,
recovery_pke: dkey.encryption_key(),
},
);
let update = AccountUpdate::V0(AccountUpdateV0 {
acc,
msg: AccountMessageV0::Recovery(AccountUpdateRecoveryV0 {
pke: dkey.encryption_key(),
sig,
}),
});
// ...
Ok((update, RecoverySecrets { /* ... */ }))
}
On the verification side, AccountUpdateV0::verify_update processes Recovery messages as follows:
pub(super) fn verify_update(self, old: &AccountStateV0) -> Result<AccountStateV0> {
match self.msg {
AccountMessageV0::Update(auth) => {
let st = auth.state;
// version must increase by exactly one
if Some(st.cnt) != old.cnt.checked_add(1) {
return Err(SwafeError::InvalidAccountStateVersion);
}
old.sig.verify(&auth.sig, &st)?;
Ok(st)
}
AccountMessageV0::Recovery(recovery) => {
let mut new_state = old.clone();
{
let rec = &mut new_state.rec;
let recovery_msg = RecoveryRequestMessage {
account_id: self.acc,
recovery_pke: recovery.pke.clone(),
};
let mut verified = false;
for assoc in &rec.assoc {
if assoc.sig.verify(&recovery.sig, &recovery_msg).is_ok() {
verified = true;
break;
}
}
if !verified {
return Err(SwafeError::InvalidSignature);
}
// Set the recovery PKE to indicate recovery has been initiated
rec.pke = Some(recovery.pke);
}
Ok(new_state)
}
}
}
For normal Update messages, the code strictly enforces st.cnt == old.cnt + 1. For Recovery messages, there’s no version check at all. The function simply clones the old state, validates the signature against the stored recovery associations, and overwrites rec.pke with the pke from the message. The account version cnt remains unchanged.
The contract action in contracts/src/lib.rs then blindly trusts the result of update.verify:
#[action]
fn update_account(
_ctx: ContractContext,
mut state: ContractState,
update_str: String,
) -> ContractState {
// deserialize the account update from a string,
let update: AccountUpdate =
encode::deserialize_str(update_str.as_str()).expect("Failed to decode account update");
// retrieve the *claimed* account ID
let account_id = update.unsafe_account_id();
// retrieve the old account state
let st_old: Option<AccountState> = state
.accounts
.get(account_id.as_ref())
.map(|bytes| encode::deserialize(&bytes).expect("failed to deserialize account state"));
// verify the update using the lib
let st_new = update
.verify(st_old.as_ref())
.expect("Failed to verify account update");
// store the updated account state
state.set_account(account_id, st_new);
state
}
There is no additional replay protection. Any Recovery update that verifies under one of the existing associations is accepted, regardless of how old it is.
Finally, guardians drive the actual recovery off the on-chain rec.pke value:
pub fn check_for_recovery<R: Rng + CryptoRng>(
&self,
rng: &mut R,
acc: AccountId,
state: &AccountState,
) -> Result<Option<GuardianShare>> {
let AccountState::V0(requester_state_v0) = state;
// check if recovery has been initiated
let rec_st = &requester_state_v0.rec;
if rec_st.pke.is_none() {
return Ok(None); // Recovery not initiated yet
}
// decrypt our share
let guardian_secrets = self.clone();
let secret_share = guardian_secrets
.decrypt_share_recovery(acc, &rec_st.social)
.ok_or_else(|| {
SwafeError::InvalidOperation(
"Guardian not authorized for this recovery or failed to decrypt share".to_string(),
)
})?;
// reencrypt the share for the requester's recovery PKE key
Ok(Some(secret_share.send_for_recovery(rng, state)?))
}
Guardians always use the current rec.pke to encrypt shares. If an attacker can cause the on-chain rec.pke to revert to an older key by replaying an old Recovery update, guardians will encrypt to that old key instead of the latest one the user intended.
This gives an attacker a reliable way to deny liveness of the recovery process. A realistic scenario looks like this:
- User loses their primary device and relies on the email + guardians-based recovery path.
- User initiates Recovery session A with some ephemeral public key
PKE_A. The transaction either fails, is abandoned, or just gets observed by an adversary. - Later, user initiates Recovery session B with a fresh key
PKE_B. - Every time B is attempted, the adversary replays the old A update. Since there is no version or nonce binding, the contract happily accepts the old message and sets
rec.pkeback toPKE_A. - Guardians observing the chain generate shares for whatever
rec.pkeis at that moment. If the attacker’s replay wins the race, that will bePKE_A, notPKE_B. - The user only holds the private key for
PKE_B. They cannot decrypt shares encrypted toPKE_A, so recovery repeatedly fails.
This can permanently prevent a user who has actually lost their main device from ever recovering their account, as long as an attacker can keep replaying the old Recovery update (for eg, from a public mempool or any log of prior transactions).
Recommended mitigation steps
The core problem is that recovery requests are authenticated but not tied to a specific state or time. It’s recommended to add freshness to the signed RecoveryRequestMessage and make sure to enforce it in verify_update.
View detailed Proof of Concept
- Add
cnt_acc(mirrors account version) andcnt_recinRecoveryStateV0.verify_updatechecksrecovery.cnt == old.cntand incrementscnt_recon acceptance- Each recovery request is valid only for the exact state version it targets
Status: Mitigation confirmed. Full details in reports from montecristo, niffylord, and DCENT09.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The signed recovery message contains only the account ID and new encryption key, with no account version, nonce or timestamp, and the verification path for recovery messages performs no freshness check.
Impact
An attacker could permanently prevent a user who has lost their main device from recovering their account, as long as the attacker can keep replaying the old recovery update.
What the attacker needed
Attacker can observe or replay old recovery updates; victim has lost their primary device; victim relies on guardian-based recovery
The fix
The signed recovery message should include freshness such as the account version and a recovery counter, and verification should enforce that the request targets the exact current state version; the report states this was mitigated and confirmed.
How it was found
- The user initiates recovery session A with an ephemeral public key, and the transaction is observed or later abandoned.
- The user later initiates recovery session B with a fresh key.
- The attacker replays the old session A update, and the contract accepts it and sets the stored recovery key back to the old one.
- Guardians generate shares for whatever recovery key is stored at that moment, which is the old key if the replay wins.
- The user only holds the private key for the new session, cannot decrypt shares encrypted to the old key, and recovery fails.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you lose your device, you start an account recovery by sending a signed request that includes a new public key. The contract checked the signature but never checked whether the request was fresh, so an old request could be sent again later. Because guardians encrypt recovery shares to whatever key is currently stored, replaying an old request makes them encrypt to a key the user cannot use, so recovery never succeeds.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.