Skip to content

fs: return rejected promise when mkdtemp lacks permissions #59045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sjwhole
Copy link

@sjwhole sjwhole commented Jul 13, 2025

Previously, fs.promises.mkdtemp() would cause a TypeError "Method Promise.prototype.then called on incompatible receiver undefined" when called without write permissions. This happened because the promise was never returned to JavaScript after being rejected.

This commit ensures SetReturnValue() is called before returning from the function, so JavaScript receives a proper rejected promise with an ERR_ACCESS_DENIED error that can be caught and handled.

Fixes: #59023

Previously, fs.promises.mkdtemp() would cause a TypeError "Method
Promise.prototype.then called on incompatible receiver undefined"
when called without write permissions. This happened because the
promise was never returned to JavaScript after being rejected.

This commit ensures SetReturnValue() is called before returning
from the function, so JavaScript receives a proper rejected promise
with an ERR_ACCESS_DENIED error that can be caught and handled.

Fixes: nodejs#59023
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Jul 13, 2025
@theanarkh
Copy link
Contributor

This bug affects many fs.promise APIs, Please See #58996.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in fs promise APIs
3 participants