Skip to content

Conversation

@vas3a
Copy link
Collaborator

@vas3a vas3a commented Oct 22, 2025

When withdrawing, add a "for udpate" lock on the otp db entry. this way we prevent parallel readings form db.

return { error: otpResponse };
}
} catch (error) {
if (error.code === 'P2010' && error.meta?.code === '55P03') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
Consider using a more specific error type or class for the thrown error instead of a generic Error. This can improve error handling and make it easier to distinguish different error types in the codebase.

} catch (error) {
if (error.code === 'P2010' && error.meta?.code === '55P03') {
this.logger.error(
'Payment request denied because payment row was locked previously!',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ security]
Logging the error object directly might expose sensitive information. Consider sanitizing the error details before logging to ensure no sensitive data is exposed.

};
}
return await this.prisma.$transaction(async (tx) => {
const records = await tx.$queryRaw<otp>`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ security]
Using tx.$queryRaw with raw SQL queries can expose the application to SQL injection vulnerabilities if the input is not properly sanitized. Ensure that hashOtp(otpCode) is sanitized or consider using parameterized queries to prevent SQL injection.

WHERE otp_hash=${hashOtp(otpCode)}
ORDER BY expiration_time DESC
LIMIT 1
FOR UPDATE NOWAIT;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The use of FOR UPDATE NOWAIT can lead to exceptions if the row is locked by another transaction. Consider handling potential exceptions to ensure the application can gracefully handle such scenarios.

@vas3a vas3a merged commit 120fbc5 into dev Oct 22, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants