Hacking Node.js with buffer overflows
Several Node.js built-in string conversion functions mishandled their input, causing memory corruption when a zero-sized output buffer was supplied. An attacker able to reach these functions could corrupt memory and potentially execute malicious code.
blog.firosolutions.com
Published on blog.firosolutions.com
2020-07-30 00:00 tags: nodejs buffer overflow Cargo.toml
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely an integer underflow: the buffer size is unsigned, so subtracting one from a size of zero wraps around to a huge value and the whole string is written out of bounds.
Impact
Memory corruption could allow a third party to manipulate the program into executing malicious code, though no working exploit had been published at the time of writing.
What the attacker needed
Code calling the affected N-API functions; a zero-length output buffer
The fix
It was fixed by upgrading Node.js to a release that no longer contains the vulnerable functions.
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 write-up has not been written yet. The Original tab links to the source.
Node.js lets JavaScript run outside a browser, and some of its internal functions convert strings between encodings. When asked to write into a buffer of size zero, those functions miscounted and wrote past the end of the memory they were given, which is a buffer overflow. That kind of mistake can let an attacker overwrite nearby memory and change how the program behaves.
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.