Skip to content
Business logic Write-up Intermediate

Integer Overflow

The cart quantity field accepted a number large enough to overflow PHP's signed integer limit, wrapping the quantity to a negative value. By combining a negative quantity of one item with a normal purchase of another, the attacker reduced the cart total to zero and checked out without paying.

Marx Chryz Follow

Published on marxchryz.medium.com

Hello everyone, I am Marx Chryz and I do bug bounty hunting for about a year now. It’s also been two and a half years since I started doing web penetration testing.

Marx Chryz Del Mundo, on marxchryz.medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

Redacted.com is a private e-commerce website that lets users buy items from the site. The researcher had been doing bug bounty hunting for about a year and web penetration testing for two and a half years at the time of writing. The site's name is withheld, so it is referred to throughout as redacted.com.

The feature involved is the shopping cart: adding items, editing quantities, and checking out. The cart is backed by two APIs, one for adding items and one for editing items already in the cart.

Setup

No special accounts, roles or tooling are described beyond ordinary browsing of the site and the use of Wappalyzer during recon. The key precondition is that the target runs PHP, which Wappalyzer reported. The researcher also used PayPal to complete the checkout at the end of the exploitation.

Finding it

During recon, Wappalyzer showed that redacted.com uses PHP. In PHP there are several data types, such as String, Integer and Float. Signed integers in PHP have limits on how large a number they can store, and the limit depends on whether the system is 32-bit or 64-bit.

On 64-bit systems, signed ints can store only from -2⁶³ up to 2⁶³-1. Storing a very large number such as 9223372036854775808 (2⁶³) exceeds the maximum, so PHP forces the number back to the lowest possible value, -2⁶³. The researcher describes it as a clock: when the number passes 2⁶³-1 (23:59) it goes back to -2⁶³ (00:00).

From the original on marxchryz.medium.com

The report links to a reference on integer overflow and to MITRE's CWE-190 entry for further background.

With that in mind, the researcher thought of adding negative items to the cart. The plan was to order -10 items of Item A. Before trying integer overflow, the researcher first tried entering negative numbers directly. There are two APIs, adding and editing items in the cart. The first API forces the quantity to be positive: entering -10 makes the quantity 10. The second API rejects negative numbers with an error message saying that negative numbers are not allowed.

Because of these restrictions, the researcher turned to integer overflow.

Exploitation

For the walkthrough, Item A is 10$ each and Item B is 80$ each.

Step 1: Order an overflowing quantity of Item A

The researcher ordered 9223372036854775808 of Item A, which is 2⁶³, one more than the maximum signed 64-bit integer.

Step 2: Observe the wrapped quantity

Upon submitting, the quantity became -9223372036854775808, proving the existence of the integer overflow bug.

Step 3: Order a second overflowing quantity to reach -8

The researcher ordered again 9223372036854775800 of item A, so that the cart would hold -8 items of Item A in total.

Step 4: Check the cart total

The cart total was now -80$.

Step 5: Add a positively priced item

The researcher ordered 1 item of Item B, at 80$.

Step 6: Check the cart total again

The cart total was now $0.00.

Step 7: Check out and confirm the bug is real

At first the researcher thought this was just a visual bug, and that the server probably had another check for negative quantities. To be sure, the researcher checked out the cart and paid using PayPal. The bug worked: the items were paid for free.

Root cause

The quantity accepted by the cart wraps when a value of 2⁶³ is submitted, consistent with a signed 64-bit integer. A value of 2⁶³ exceeds the maximum of 2⁶³-1, so it wraps to -2⁶³. The two APIs only validate the sign of the input at the point of entry: the add API coerces a negative input to its positive value, and the edit API rejects negative numbers outright. Neither check accounts for a positive input that becomes negative after the integer conversion. The checkout completed at $0.00, so a negative line item offset a positive one. The report does not show the server-side code, so the exact location of the missing check is not described.

Impact

The researcher obtained items for free by combining a negative quantity produced through integer overflow with a positively priced item, as demonstrated with a PayPal checkout that completed at $0.00. The report does not state any limits on which items or quantities can be used, nor whether the technique works on 32-bit systems, where the wrap point would differ. The target is a private program, so the affected population is not described.

Fix

Based on the root cause, the quantity should be validated after conversion, rejecting any value that is not a positive integer within a sane range, and the cart total should be recomputed and checked server-side before checkout so that a negative line item cannot reduce the amount due.

Variants to test

  1. Send a quantity just above the signed integer maximum, such as 9223372036854775808, to any cart or order API and check whether the stored quantity becomes negative.
  2. Send a quantity just below the signed integer minimum, such as -9223372036854775809, and check whether it wraps to a large positive value.
  3. Try the same overflow on 32-bit targets using 2147483648 and -2147483649, and confirm whether the wrap point matches the platform.
  4. Apply the technique to other numeric fields that feed a price or total, such as discount codes, coupon counts, shipping quantities or loyalty points, and check whether a negative result offsets a positive charge.
  5. Combine a wrapped negative quantity with a cheap item and a more expensive item, then proceed to checkout and confirm whether the total is reduced or zeroed.

A positive result in each case is a stored value whose sign differs from the input, or a cart total that is lower than the sum of the positive line items.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

An online shop let people put items in a shopping basket and pay for them. The shop was built with a programming language called PHP. The researcher noticed this and realised that PHP stores whole numbers in a fixed-size box. If you try to put a number bigger than the box can hold, the number does not cause an error: it wraps around to the other end, like the mileage counter on an old car rolling from 99999 back to 00000.

The researcher used that wrap-around to make the shop believe the basket contained a negative number of items. A negative number of items has a negative price, so it cancels out the price of a real item. By carefully choosing the numbers, the researcher made the basket total exactly $0.00 and then checked out, receiving the goods for free.

The two cart APIs handled negative input differently. One forced the quantity to be positive. The other returned an error message saying negative numbers are not allowed. Neither safeguard expected a positive number that turns negative after the computer stores it. That gap is the bug.

This kind of flaw is called an integer overflow. It belongs to a family of problems where a program trusts a number without checking what happens to it after conversion. The report was published on 29 November 2021.

The target and the feature

The site is a private e-commerce website, so its real name is hidden and it is called redacted.com throughout. It lets users buy items from the site. The feature involved is the shopping cart: adding items, editing quantities, and checking out.

The cart is backed by two APIs, one for adding items and one for editing items already in the cart. An API (Application Programming Interface) is the set of addresses a website's own pages use to talk to its server behind the scenes. When you click "Add to cart", your browser does not reload the whole page; it sends a small message to one of these addresses, and the server replies with a small message back. Think of the website's visible pages as the shop counter and the APIs as the staff door at the back: customers normally go through the counter, but the door is there and can be knocked on directly.

Both APIs accept a quantity value for a chosen item. The quantity is simply the number of units you want: 1, 2, 3 and so on.

Setup

No special accounts, roles or tooling are described beyond ordinary browsing of the site and the use of Wappalyzer during recon. Wappalyzer is a browser extension that looks at a website and guesses which technologies it is built with: the programming language, the web server, the JavaScript libraries and so on. It is a bit like reading the labels on the back of a machine to see who made it.

Recon (short for reconnaissance) is the information-gathering phase at the start of any security test: looking at what the site is made of before trying anything. The key precondition here is that the target runs PHP, which Wappalyzer reported. The researcher also used PayPal to complete the checkout at the end of the exploitation. PayPal is an online payment service; it is the equivalent of paying at the till with a card rather than with cash.

Finding it

During recon, Wappalyzer showed that redacted.com uses PHP. In PHP there are several data types, such as String, Integer and Float. A data type is simply the kind of value a variable is allowed to hold: text (String), a whole number (Integer), a number with a decimal point (Float).

Signed integers in PHP have limits on how large a number they can store, and the limit depends on whether the system is 32-bit or 64-bit. "Signed" means the number can be negative as well as positive, so one bit of the box is reserved for the plus or minus sign. "32-bit" and "64-bit" describe how wide that box is: a 64-bit box is twice as wide as a 32-bit one and can therefore hold much larger numbers.

On 64-bit systems, signed ints can store only from -2⁶³ up to 2⁶³-1. In plain numbers that is roughly from minus nine quintillion to plus nine quintillion. Storing a very large number such as 9223372036854775808 (2⁶³) exceeds the maximum, so PHP forces the number back to the lowest possible value, -2⁶³. The researcher describes it as a clock: when the number passes 2⁶³-1 (23:59) it goes back to -2⁶³ (00:00).

From the original on marxchryz.medium.com

The image illustrates that clock idea: the number climbing past its maximum and dropping straight to the minimum, the way 23:59 becomes 00:00.

The report links to a reference on integer overflow and to MITRE's CWE-190 entry for further background. CWE-190 is the catalogue number the security community uses for this exact class of bug, so anyone reading the report can look up the general pattern.

With that in mind, the researcher thought of adding negative items to the cart. The plan was to order -10 items of Item A. Before trying integer overflow, the researcher first tried entering negative numbers directly. There are two APIs, adding and editing items in the cart. The first API forces the quantity to be positive: entering -10 makes the quantity 10. The second API rejects negative numbers with an error message saying that negative numbers are not allowed.

Because of these restrictions, the researcher turned to integer overflow. The reasoning is worth spelling out: the shop had clearly thought about negative numbers, so typing a minus sign was a dead end. But the shop had not thought about a positive number that becomes negative after the computer stores it. That is the gap the researcher aimed at.

Exploitation

For the walkthrough, Item A is 10$ each and Item B is 80$ each. Two different prices make the arithmetic easy to follow: one negative line and one positive line that cancel out.

Step 1: Order an overflowing quantity of Item A

The researcher ordered 9223372036854775808 of Item A, which is 2⁶³, one more than the maximum signed 64-bit integer. The number is deliberately one above the ceiling: it is the smallest positive value that cannot fit in the box.

Step 2: Observe the wrapped quantity

Upon submitting, the quantity became -9223372036854775808, proving the existence of the integer overflow bug. The shop accepted a positive number and stored a negative one. That single observation is the proof: the sign flipped without anyone typing a minus sign.

Step 3: Order a second overflowing quantity to reach -8

The researcher ordered again 9223372036854775800 of item A, so that the cart would hold -8 items of Item A in total. This second order is the fine-tuning step. The first overflow produced a huge negative number; the second produced a slightly smaller one, and the difference between the two leaves exactly -8. Think of it as using two very large weights on a balance to end up with a tiny difference.

Step 4: Check the cart total

The cart total was now -80$. Eight items at 10$ each, with a minus sign, is -80$. The cart total was now -80$.

Step 5: Add a positively priced item

The researcher ordered 1 item of Item B, at 80$. This is the ordinary, honest part of the order: a real product at its real price.

Step 6: Check the cart total again

The cart total was now $0.00. The -80$ from the negative quantity and the +80$ from Item B cancel exactly.

Step 7: Check out and confirm the bug is real

At first the researcher thought this was just a visual bug, and that the server probably had another check for negative quantities. A visual bug is one where the page displays something wrong but the server behind it still does the right thing: the screen lies, the till does not. To be sure, the researcher checked out the cart and paid using PayPal. The bug worked: the items were paid for free. The payment going through at $0.00 is what turns a curious display into a real, money-losing flaw.

Root cause

The quantity accepted by the cart wraps when a value of 2⁶³ is submitted, consistent with a signed 64-bit integer. A value of 2⁶³ exceeds the maximum of 2⁶³-1, so it wraps to -2⁶³. The two APIs only validate the sign of the input at the point of entry: the add API coerces a negative input to its positive value, and the edit API rejects negative numbers outright. Neither check accounts for a positive input that becomes negative after the integer conversion. The checkout completed at $0.00, so a negative line item offset a positive one. The report does not show the server-side code, so the exact location of the missing check is not described.

In everyday terms: the guard at the front door checked everyone's ticket, but nobody checked the tickets again once people were inside. The number was inspected before it was stored, never after.

Impact

The researcher obtained items for free by combining a negative quantity produced through integer overflow with a positively priced item, as demonstrated with a PayPal checkout that completed at $0.00. The report does not state any limits on which items or quantities can be used, nor whether the technique works on 32-bit systems, where the wrap point would differ. The target is a private program, so the affected population is not described.

Fix

Based on the root cause, the quantity should be validated after conversion, rejecting any value that is not a positive integer within a sane range, and the cart total should be recomputed and checked server-side before checkout so that a negative line item cannot reduce the amount due. The principle is simple: check the number again after it has been stored, not only before, and never let the browser's version of the total be the one that is charged.

Variants to test

  1. Send a quantity just above the signed integer maximum, such as 9223372036854775808, to any cart or order API and check whether the stored quantity becomes negative.
  2. Send a quantity just below the signed integer minimum, such as -9223372036854775809, and check whether it wraps to a large positive value.
  3. Try the same overflow on 32-bit targets using 2147483648 and -2147483649, and confirm whether the wrap point matches the platform.
  4. Apply the technique to other numeric fields that feed a price or total, such as discount codes, coupon counts, shipping quantities or loyalty points, and check whether a negative result offsets a positive charge.
  5. Combine a wrapped negative quantity with a cheap item and a more expensive item, then proceed to checkout and confirm whether the total is reduced or zeroed.

A positive result in each case is a stored value whose sign differs from the input, or a cart total that is lower than the sum of the positive line items.

Glossary

  • API: the set of behind-the-scenes addresses a website's pages use to talk to its server, separate from the pages a person clicks.
  • Bug bounty: a programme where a company pays researchers for reporting security flaws in its systems.
  • Cart total: the sum of the prices of everything in the shopping basket, which the shop uses to decide how much to charge.
  • Checkout: the final step of an order where the basket is confirmed and payment is taken.
  • CWE-190: the community catalogue entry for integer overflow and wraparound bugs.
  • Data type: the kind of value a variable can hold, such as text, a whole number, or a number with decimals.
  • Float: a data type for numbers with a decimal point.
  • Integer: a data type for whole numbers, positive or negative.
  • Integer overflow: what happens when a number is too large for the fixed-size box that stores it, so it wraps around to the other end of the range.
  • PayPal: an online payment service used to pay for the order.
  • PHP: a programming language commonly used to build websites.
  • Quantity: the number of units of an item a customer wants in the basket.
  • Recon: the information-gathering phase at the start of a security test, looking at what a site is built from.
  • Signed integer: a whole-number type that can hold negative values as well as positive ones, because one bit is reserved for the sign.
  • String: a data type for text.
  • Visual bug: a flaw where the page displays something wrong but the server still behaves correctly.
  • Wappalyzer: a browser extension that guesses which technologies a website is built with.
  • 32-bit / 64-bit: descriptions of how wide the box for a number is; a 64-bit box holds much larger numbers than a 32-bit one.

More by Marx Chryz

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.