`fs.realpath.native` on darwin may cause buffer overflow
The libuv realpath implementation on macOS uses a buffer size from pathconf that may be smaller than PATH_MAX, causing a buffer overflow when the resolved path is longer than 256 bytes. An attacker could crash the Node.js process.
- Fixed in 24 days
- Paid in 7 months
- Disclosed after 54 days
NOTE! Thanks for submitting a report! Please replace all the [square] sections below with the pertinent details. Remember, the more detail you provide, the easier it is for us to triage and respond quickly, so be sure to take your time filling out the report!
Summary:
The libuv's implementation of realpath is flawed on darwin and may cause buffer overflow.
Description:
libuv's realpath implementation determines the buffer size with pathconf and fallback to _POSIX_PATH_MAX (256) if that fails for any reason (eg. ENOENT). However realpath requires a buffer of at least PATH_MAX (1024) bytes to be used, hence causes the buffer overflow if the resolved path is longer than 256 bytes.
Steps To Reproduce:
LONG_PATH='/tmp/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long/path/254B'SHORT_LINK='/tmp/short'mkdir -p "${LONG_PATH}"ln -s "${LONG_PATH}" "${SHORT_LINK}"node -e "fs.realpathSync.native('${SHORT_LINK}/file-not-exist')"
Impact:
Cause node process to crash.
Supporting Material/References:
- https://github.com/bazelbuild/rules_nodejs/issues/1958
- https://github.com/libuv/libuv/issues/2965
- https://github.com/libuv/libuv/issues/2966
Impact
Given that nodejs on darwin are mostly desktop applications and used as developer tools, exploit this is very unlikely to cause more damage than an application crash.
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
Root cause
Likely the code used a buffer size from pathconf (or a 256-byte fallback) instead of ensuring at least PATH_MAX (1024) bytes for realpath.
Impact
The Node.js process could crash; the report notes that on macOS this is unlikely to cause more damage than an application crash.
What the attacker needed
MacOS (darwin) system; ability to create long paths and symlinks; Node.js application calls fs.realpath.native
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.
A buffer is a fixed-size space in memory. If a program writes more data than the buffer can hold, it overflows and can crash. Here, a function that resolves file paths used a buffer that was too small for long paths, so a long path could crash the program.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.