Skip to content

Fix Node DEP0005 deprecation warning from formidable's Buffer() usage#43

Open
MrWhitee4 wants to merge 2 commits into
citizenfx:masterfrom
MrWhitee4:master
Open

Fix Node DEP0005 deprecation warning from formidable's Buffer() usage#43
MrWhitee4 wants to merge 2 commits into
citizenfx:masterfrom
MrWhitee4:master

Conversation

@MrWhitee4

Copy link
Copy Markdown

Problem

Every multipart screenshot upload (POST /upload/:token) triggers Node's
DEP0005 deprecation warning:

[DEP0005] DeprecationWarning: Buffer() is deprecated due to security and
usability issues.

The deprecated Buffer() constructor is called inside the bundled
formidable@1.2.2 (pulled in by koa-body@4), in two places:

  • MultipartParser.initWithBoundarynew Buffer(str.length + 4) and
    new Buffer(this.boundary.length + 8)
  • the base64 part decoder — new Buffer(str, 'base64') (×2)

On a busy server this spams the console, and the number form of Buffer()
also allocates uninitialized memory.

Why not just bump the dependency

formidable 1.x never adopted the safe Buffer APIs. The versions that did
(formidable 2/3) are only reachable via koa-body 5/6, which require webpack 5.
Since this resource is built by FiveM's bundled webpack (4.x) via
dependency 'webpack', a dependency upgrade breaks the build: webpack 4
can't parse formidable 2's BigInt code (via cuid2), and webpack-5-only
config options are rejected by the webpack 4 schema. So the fix stays on
formidable 1.x.

Fix

Patch formidable's four Buffer() calls via
patch-package, reapplied on
postinstall so the webpack bundle always builds clean:

  • new Buffer(n)Buffer.alloc(n) (boundary + lookbehind)
  • new Buffer(str, 'base64')Buffer.from(str, 'base64') (×2)

Changes

  • patches/formidable+1.2.2.patch — the four replacements
  • package.json — add patch-package + postinstall-postinstall devDeps and
    a postinstall script
  • .gitattributes — keep the patch LF-normalized across platforms

Behavior

No runtime change. The boundary buffer is fully overwritten before it is read,
and the base64 calls take string input (never the uninitialized-number form),
so Buffer.alloc/Buffer.from are drop-in replacements. Verified by running
repeated screenshot uploads: every upload succeeded, files wrote to disk, and
the DEP0005 line no longer appears.

MrWhitee4 added 2 commits June 6, 2026 14:40
The bundled formidable 1.2.2 (via koa-body 4) still uses the deprecated
Buffer() constructor in MultipartParser.initWithBoundary and the base64
part decoder, so Node logs DEP0005 on every screenshot upload.

formidable 1.x never moved to the safe Buffer APIs, and the versions that
did (formidable 2/3) need koa-body 5/6 and webpack 5, which FiveM's
webpack-4 builder cannot compile. So the fix stays on formidable 1.x and
patches the four calls through patch-package, reapplied on postinstall:
- new Buffer(n)            -> Buffer.alloc(n)   (boundary, lookbehind)
- new Buffer(str,'base64') -> Buffer.from(...)  (base64 decode, x2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant