Skip to content

What is a business logic bug?

The code runs fine and does exactly what it was told. Nobody told it the rule.

Choose which version to show
candle-shop.lab/checkout
Candle
$10.00
Quantity sent
-2

Order placed. Total: -$20.00.

Refused. The quantity has to be at least 1.

Made up. There's no candle shop, and real shops are not practice targets.

All six guides
  1. 1What is ethical hacking?
  2. 2Where to practice
  3. 3Business logic bugs
  4. 4IDOR
  5. 5Cross-site scripting
  6. 6A report, with notes

A business logic bug is a rule everybody assumed and nobody told the software. The code does exactly what it was told, and what it was told leaves a gap, like a shop that accepts a negative quantity or a one-time coupon that works twice.

Real shops are not practice targets. Trying this on a real shop is testing a real site, and testing a site without its owner's permission is illegal. Get permission before you access anything, stay in the practice labs, and never touch a real site. Everything below happens in a shop that doesn't exist.

A shop that doesn't exist

This made-up shop sells one thing, a $10 candle. It has one coupon, FIRSTCANDLE, which takes $5 off. The customers, orders and money here are all made up too.

The owner has rules in mind: you have to buy at least one candle, and each customer gets the coupon once. They seem too obvious to write down, and normal customers never come near them, so nobody notices that the server doesn't check either one.

The quantity that goes below zero

The quantity box on the page won't go under 1. That only limits the box. This server never checks the number it gets, so a quantity of -2 comes back like this:

Order placed. Total: -$20.00.

The math is right. There's no error and no crash, which is why this kind of bug is easy to miss.

What it costs depends on the shop. This one now counts two candles coming back that never left, so its stock is wrong, and its books show a sale that lost $20. If it pays out negative totals as store credit, somebody just got $20 for nothing.

The coupon that works twice

The checkout page says FIRSTCANDLE is "one time only." In this shop, that's just a sentence on a page. The server checks that the code exists and takes off $5. It never writes down who used it.

So a customer uses the code on one order, then uses it again on the next. Same account, same code, $5 off both times.

$5 is a small loss on one order, but nothing limits it. Any customer can repeat it on every order they place.

The fix goes on the server

A box that won't go under 1 and a sentence that says "one time only" are both on the page, and the page is on the customer's computer. The server is the part they can't change, so that's where the rules go.

For the quantity, the server refuses any order unless the quantity is a whole number of at least 1.

For the coupon, the server keeps its own record of who has spent which code, and says no if the code is already spent.

Neither fix is much code. The hard part is that someone has to say the rule out loud first. Look at a feature and ask what has to be true for it to make sense: the quantity is at least 1, a code gets spent, an order can't change once it's paid. Anything on that list the server doesn't check is worth a closer look, on a practice shop.

What you'd write down

On a practice shop, a write-up says what rule was missing, what you did and what the fix is. "The cart is broken" doesn't help anyone. "The server accepts a quantity below 1, and here's the order it placed" tells the person fixing it exactly what to check.

Week 3 of the curriculum is about these bugs, on a practice shop built for them.

The course behind these guides

BugClub HQ is an eight-week online course in ethical hacking for anyone 14 and up. It runs in three groups, for high school students, college students and adults, and each one meets on its own night. You practice on apps with bugs put there on purpose, write up what you find, and get my feedback on every write-up. You don't need to know how to code.

Applications for the winter term close Dec 18

The winter term

$399 one time, only if accepted

Starts
January 11
Schedule
  • High school students: Thursdays, 5:30 to 7 PM Eastern
  • College students: Wednesdays, 6 to 7:30 PM Eastern
  • Adults: Tuesdays, 8:15 to 9:45 PM Eastern
Class size
Up to 12 per group
Apply for the winter term

Free to apply, about five minutes. You pay only if I accept the student.