Skip to content

Commit 6b2f8ff

Browse files
committed
fix(audit): add non-witness-utxo validation for psbt
1 parent db1eab4 commit 6b2f8ff

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/psbt/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@ impl PsbtUtils for Psbt {
4343

4444
match (&input.witness_utxo, &input.non_witness_utxo) {
4545
(Some(_), _) => input.witness_utxo.clone(),
46-
(_, Some(_)) => input.non_witness_utxo.as_ref().map(|in_tx| {
47-
in_tx.output[tx.input[input_index].previous_output.vout as usize].clone()
46+
(_, Some(_)) => input.non_witness_utxo.as_ref().and_then(|in_tx| {
47+
// Validate that the non_witness_utxo txid matches the input's previous output txid
48+
if in_tx.compute_txid() != tx.input[input_index].previous_output.txid {
49+
return None;
50+
}
51+
in_tx
52+
.output
53+
.get(tx.input[input_index].previous_output.vout as usize)
54+
.cloned()
4855
}),
4956
_ => None,
5057
}

0 commit comments

Comments
 (0)