All vulnerabilities
HighA03:2021CWE-190Input Validation

Integer Overflow & Type Juggling

AI-generated code rarely validates numeric input types. Attackers send negative prices, NaN quantities, or overflow values to manipulate business logic — free items, infinite credits, or server crashes.

What Is Integer Overflow / Type Juggling?

Integer overflow occurs when a numeric value exceeds the maximum size its data type can hold, wrapping around to an unexpected value. Type juggling happens when a server accepts a value of the wrong type (string where number expected, array instead of integer) and processes it without error.

AI-generated code is particularly vulnerable because LLMs produce "happy path" code that assumes valid input — they almost never add boundary validation.

How It Works

Negative Price Manipulation

POST /api/cart/add HTTP/1.1
Content-Type: application/json
 
{"product_id": 42, "quantity": -5, "price": -100}

If the server doesn't validate, the cart total becomes negative — effectively paying the customer to "buy" products.

Integer Overflow (Int32 Boundary)

POST /api/transfer HTTP/1.1
Content-Type: application/json
 
{"amount": 2147483648, "to_account": "attacker"}

The value 2147483648 overflows a signed 32-bit integer to -2147483648, potentially reversing a transfer direction.

Type Confusion

POST /api/discount HTTP/1.1
Content-Type: application/json
 
{"discount_code": "SAVE10", "quantity": NaN}

Many frameworks pass NaN through arithmetic without error: price * NaN = NaN, which some payment processors interpret as zero.

Real-World Impact

  • Free purchases — negative prices or quantities create refund-like transactions
  • Infinite credits — overflow wraps large debits into credits
  • Server crashes — unhandled NaN, Infinity, or null in arithmetic causes 500 errors
  • Privilege escalationrole=0 might map to admin in some systems

How to Fix

Validate all numeric inputs server-side:

from pydantic import BaseModel, Field
 
class CartItem(BaseModel):
    product_id: int = Field(gt=0)
    quantity: int = Field(gt=0, le=1000)
    price: float = Field(gt=0, le=999999.99)

Reject non-numeric types explicitly:

if (typeof quantity !== 'number' || !Number.isFinite(quantity)) {
  return res.status(422).json({ error: 'quantity must be a finite number' });
}

Use BigInt or Decimal for financial calculations to avoid floating-point rounding.

What VibeWShield Detects

VibeWShield's Integer Overflow scanner sends 5 categories of extreme values to every numeric field discovered during crawling:

  1. Negative numbers (-1, -100)
  2. Zero values (0)
  3. Overflow boundaries (2147483648, 99999999999999999)
  4. Type confusion (NaN, Infinity, null, [], {})
  5. Precision errors (0.0001, 99.999999999)

If the server accepts a dangerous value (HTTP 2xx) or crashes (HTTP 500), the finding is flagged with the exact field, payload, and business impact.

#integer-overflow#type-juggling#input-validation#price-manipulation#vibe-coded

Free security scan

Test your app for Integer Overflow & Type Juggling

VibeWShield automatically checks for Integer Overflow & Type Juggling and 40+ other vulnerabilities using 63 scanners — in under 3 minutes, no signup required.

Scan your app free