Skip to content
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

deprecate process.umask() with no arguments #32499

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2635,6 +2635,22 @@ modules is unsupported.
It is deprecated in favor of [`require.main`][], because it serves the same
purpose and is only available on CommonJS environment.

<a id="DEP0139"></a>
### DEP0139: `process.umask()` with no arguments
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/32499
description: Runtime deprecation.
-->

Type: Runtime

Calling `process.umask()` with no arguments causes the process-wide umask to be
written twice. This introduces a race condition between threads, and is a
potential security vulnerability. There is no safe, cross-platform alternative
API.

[`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`--throw-deprecation`]: cli.html#cli_throw_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
Expand Down
8 changes: 8 additions & 0 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -2426,8 +2426,16 @@ flag's behavior.
## `process.umask([mask])`
<!-- YAML
added: v0.1.19
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/32499
description: Calling `process.umask()` with no arguments is deprecated.

-->

> Stability: 0 - Deprecated. Calling `process.umask()` with no arguments is
> deprecated. No alternative is provided.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stability setting isn't right, is it? The stability applies to the method, not a particular use of the method. That will make it look like the method is deprecated itself, but it's not. We don't do this for any other methods. I'm going to open a PR to change this to a paragraph rather than a stability banner.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could provide separate entries for process.umask() and process.umask(mask) 🤷‍♀️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that could work too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


* `mask` {string|integer}

The `process.umask()` method sets or returns the Node.js process's file mode
Expand Down
8 changes: 8 additions & 0 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,14 @@ void Environment::set_filehandle_close_warning(bool on) {
emit_filehandle_warning_ = on;
}

bool Environment::emit_insecure_umask_warning() const {
return emit_insecure_umask_warning_;
}

void Environment::set_emit_insecure_umask_warning(bool on) {
emit_insecure_umask_warning_ = on;
}

inline uint64_t Environment::thread_id() const {
return thread_id_;
}
Expand Down
3 changes: 3 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,8 @@ class Environment : public MemoryRetainer {

inline bool filehandle_close_warning() const;
inline void set_filehandle_close_warning(bool on);
inline bool emit_insecure_umask_warning() const;
inline void set_emit_insecure_umask_warning(bool on);

inline void ThrowError(const char* errmsg);
inline void ThrowTypeError(const char* errmsg);
Expand Down Expand Up @@ -1285,6 +1287,7 @@ class Environment : public MemoryRetainer {
bool emit_env_nonstring_warning_ = true;
bool emit_err_name_warning_ = true;
bool emit_filehandle_warning_ = true;
bool emit_insecure_umask_warning_ = true;
size_t async_callback_scope_depth_ = 0;
std::vector<double> destroy_async_id_list_;

Expand Down
11 changes: 11 additions & 0 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@ static void Umask(const FunctionCallbackInfo<Value>& args) {

uint32_t old;
if (args[0]->IsUndefined()) {
if (env->emit_insecure_umask_warning()) {
env->set_emit_insecure_umask_warning(false);
if (ProcessEmitDeprecationWarning(
env,
"Calling process.umask() with no arguments is prone to race "
"conditions and is a potential security vulnerability.",
"DEP0139").IsNothing()) {
return;
}
}

old = umask(0);
umask(static_cast<mode_t>(old));
} else {
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-process-umask.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ if (common.isWindows) {
mask = '0664';
}

common.expectWarning(
'DeprecationWarning',
'Calling process.umask() with no arguments is prone to race conditions ' +
'and is a potential security vulnerability.',
'DEP0139'
);

const old = process.umask(mask);

assert.strictEqual(process.umask(old), parseInt(mask, 8));
Expand Down