Sailias / bitcoin_payable

A rails bitcoin payment processing gem
MIT License
121 stars 31 forks source link

[Logic error] All transactions from a payment must be confirmed before setting the payment as :confirmed #40

Closed maesitos closed 6 years ago

maesitos commented 6 years ago

Since BitcoinPayable::Interactors::TransactionProcessor::DeterminePaymentStatus checks a single transaction and sets the payment as :confirmed if only that particular transaction has more confirmations than BitcoinPayable.config.confirmations there is an immediate loophole:

It's true AASM restricts the states the class can transition from

event :confirm do
        transitions :from => [:pending, :paid_in_full], :to => :confirmed
end

Nonetheless the current code still allows the class to transition from :pending to :confirm and I don't recommend to limit the transition from only:paid_in_full

maesitos commented 6 years ago

The pull request https://github.com/Sailias/bitcoin_payable/pull/41 solves the problem and gives more clarity to the code.

maesitos commented 6 years ago

Actually since BitcoinPayable::Interactors::TransactionProcessor::DeterminePaymentStatus only sets the payment as confirmed if the total fiat received is correct the steps to bypass the payment system is:

It's obviously a pretty involved process and a very hard attack but the user of the Gem can receive a double spend attack when he thought he was waiting for n confirmations.

Sailias commented 6 years ago

@maesitos I see. It should ensure each transaction meets the minimum confirmation count.

maesitos commented 6 years ago

@Sailias PR #41 is a simple fix to this problem.