A new path traversal vulnerability has been discovered as a result of an insufficient patch to a previously disclosed vulnerability, CVE-2023-30584, in commit 205f1e6. This vulnerability, identified as CVE-2023-39331, can cause security risks for Node.js applications as it does not adequately protect against the application overwriting built-in utility functions with user-defined implementations.


The previously disclosed vulnerability, CVE-2023-30584, had reported a serious path traversal vulnerability in Node.js applications. The recommended patch for the vulnerability was applied through commit 205f1e6, but further analysis has revealed that it did not completely address the issue, leaving the applications still vulnerable to similar attacks.

Exploit Details

CVE-2023-39331 arises due to the insufficient protection against applications overwriting built-in utility functions with user-defined implementations. This can further lead to unauthorized read and/or write access to an unsuspecting user's filesystem. The exploitation can be done through specially crafted input containing certain problematic path components.

Here is a code snippet exhibiting the vulnerability

const fs = require("fs");
const path = require("path");

function getUserFile(filepath) {
  const safePath = path.join(__dirname, "user_files");
  const userFile = path.resolve(safePath, filepath);

  if (!userFile.startsWith(safePath)) {
    throw new Error("Access denied");

  return fs.readFileSync(userFile, "utf8");

// Overwriting built-in utility function with user-defined implementation
path.join = function(a, b) {
  return a + b;

// Bypassing the protection and gaining access to the file system
try {
  const result = getUserFile("../../etc/passwd");
} catch (err) {

This code snippet demonstrates how an attacker can exploit the vulnerability by overwriting the built-in path.join function with a user-defined implementation to bypass the protection and access the file system. The insufficient patch doesn't guard against this issue, making the application vulnerable.

Original References

For more information regarding the original vulnerability and patch, please refer to the following links:
- CVE Details for CVE-2023-30584
- Node.js Commit 205f1e6


It is essential to understand that, at the time of issuing this CVE, the permission model is an experimental feature of Node.js. Further revisions and enhancement of the model may mitigate vulnerabilities related to experimental features. Meanwhile, organizations and developers should stay vigilant and ensure that they apply the most recent and recommended patches to address any vulnerabilities that might arise.

In this case, one possible mitigation would be to validate and authenticate the user input thoroughly before it's used for filesystem operations. Additionally, the application logic should be reinforced to validate and ensure the legitimacy of the input variables and function calls, effectively preventing any unauthorized modification of the built-in utility functions.


CVE-2023-39331 is a newly discovered path traversal vulnerability in Node.js applications, arising due to an insufficient patch for a previous vulnerability. The exploit exists because the implementation does not protect itself against applications overwriting built-in utility functions with user-defined implementations. Organizations and developers are advised to remain vigilant, apply recommended patches, and reinforce their application logic to prevent any unauthorized access or functionalities to ensure the security of their user's data.


Published on: 10/18/2023 04:15:00 UTC
Last modified on: 11/08/2023 01:15:00 UTC