Skip to content

Out-of-bounds write in Buffer API

Description

The application is using Buffer API methods with the `noAssert` parameter set to `true` for the write buffer methods, which disables bounds checking and could result in writing beyond the end of the buffer, leading to potential memory corruption and security vulnerabilities.

Examples

Insecure Code

javascript
const buffer = Buffer.alloc(10); buffer.writeUInt8(0, 15, true);

Secure Code

javascript
const buffer = Buffer.alloc(10); if (5 < buffer.length) { buffer.writeUInt8(0, 5); }

Remediation

Ensure that the `noAssert` parameter is not set to `true` and always use bounds checking to prevent out-of-bounds memory access. Validate the offset before performing write operations on the buffer.

Rule Details

FieldValue
IDCODE-0192
CategoryInjection
SeverityMEDIUM
CWECWE-787
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsbuffer overflow, out-of-bounds write
OWASPA6:2017-Security Misconfiguration, A05:2021-Security Misconfiguration