Blog / A04:2021 Insecure Design
A04:2021 · Insecure Design

The device on the other end sizes your buffers

When a Bluetooth peer tells you how big its response will be and you allocate that up front, a lying peer can ask for gigabytes and crash your app.

peer advertises aresponse sizevalue passed tothe assemblerbuffers sized tothat valueextreme valueexhausts memoryATTACKER INPUTIMPACTresource exhausted
Attack path · peer advertises a response size → value passed to the assembler → buffers sized to that value → extreme value exhausts memory

When a Bluetooth peer tells you how big its response will be and you allocate that up front, a lying peer can ask for gigabytes and crash your app.

What goes wrong

A message from the connected peer carries two numbers: how large the whole response will be and how big each chunk is. Both go straight into the object that allocates buffers to reassemble the transfer. Nothing checks them against a sane ceiling first.

A real device sends modest numbers. A malicious one advertises an enormous response size, and the allocator dutifully tries to reserve room for it during setup, before a single byte of actual data arrives. The app spikes memory or falls over. The peer never had to send a large payload, only claim that it would.

The pattern

Vulnerable
function onMessage(msg) {
  const size = msg.responseSize   // from the peer
  const chunk = msg.maxDataBytes  // from the peer
  const buffer = new TransferBuffer(size, chunk)  // allocates up front
  return buffer
}
Hardened
function onMessage(msg) {
  const size = msg.responseSize
  const chunk = msg.maxDataBytes
  if (size > MAX_RESPONSE || chunk <= 0 || chunk > MAX_CHUNK)
    throw new Error('declared size out of range')
  const buffer = new TransferBuffer(size, chunk)
  return buffer
}
How the pipeline adjudicated itHELD
ABCDEFGH

Grounding and reachability were confirmed. The exploit-path gate would not conclude without the calling code, so the finding was held and an evidence request was raised instead of being reported as fact.

Ed25519 · per-tenant signing key · gate ledger A–H · verify offline against the published payload hash

Why it matters to you

Anything that pairs over Bluetooth trusts a device the user may not control and you certainly do not. Treat a wireless peer the way you treat a network client: hostile until proven otherwise. A crash here is a denial of service on a phone or an access device, triggered by a peer in radio range with no authentication.

Numbers that describe how much to allocate are the most dangerous fields a peer can send. Clamp them to limits you set before you hand them to any allocator.

Check your own code