TLDR Dev · ARTICLES & TUTORIALS

WHEN 'PERFECT' CODE FAILS

marma.dev6 min read

Summary from the TLDR Dev newsletter

A critical security bug found in this dev's Next.js application was caused by a seemingly perfect one-line equality check. Due to Next.js's server function implementation, the synchronous function was unexpectedly converted to an asynchronous function returning a Promise. In JavaScript, a Promise evaluates to true in an `if` statement, effectively bypassing the security check and granting access to everyone.