Skip to content

Commit 60c4c2b

Browse files
committed
src: runtime deprecate process.umask()
This commit runtime deprecates calling process.umask() with no arguments. PR-URL: #32499 Fixes: #32321 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 75ee5b2 commit 60c4c2b

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

doc/api/deprecations.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2635,16 +2635,16 @@ modules is unsupported.
26352635
It is deprecated in favor of [`require.main`][], because it serves the same
26362636
purpose and is only available on CommonJS environment.
26372637
2638-
<a id="DEP0XXX"></a>
2639-
### DEP0XXX: `process.umask()` with no arguments
2638+
<a id="DEP0139"></a>
2639+
### DEP0139: `process.umask()` with no arguments
26402640
<!-- YAML
26412641
changes:
26422642
- version: REPLACEME
26432643
pr-url: https://github.com/nodejs/node/pull/32499
2644-
description: Documentation-only deprecation.
2644+
description: Runtime deprecation.
26452645
-->
26462646
2647-
Type: Documentation-only
2647+
Type: Runtime
26482648
26492649
Calling `process.umask()` with no arguments causes the process-wide umask to be
26502650
written twice. This introduces a race condition between threads, and is a

src/env-inl.h

+8
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,14 @@ void Environment::set_filehandle_close_warning(bool on) {
910910
emit_filehandle_warning_ = on;
911911
}
912912

913+
bool Environment::emit_insecure_umask_warning() const {
914+
return emit_insecure_umask_warning_;
915+
}
916+
917+
void Environment::set_emit_insecure_umask_warning(bool on) {
918+
emit_insecure_umask_warning_ = on;
919+
}
920+
913921
inline uint64_t Environment::thread_id() const {
914922
return thread_id_;
915923
}

src/env.h

+3
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,8 @@ class Environment : public MemoryRetainer {
10651065

10661066
inline bool filehandle_close_warning() const;
10671067
inline void set_filehandle_close_warning(bool on);
1068+
inline bool emit_insecure_umask_warning() const;
1069+
inline void set_emit_insecure_umask_warning(bool on);
10681070

10691071
inline void ThrowError(const char* errmsg);
10701072
inline void ThrowTypeError(const char* errmsg);
@@ -1285,6 +1287,7 @@ class Environment : public MemoryRetainer {
12851287
bool emit_env_nonstring_warning_ = true;
12861288
bool emit_err_name_warning_ = true;
12871289
bool emit_filehandle_warning_ = true;
1290+
bool emit_insecure_umask_warning_ = true;
12881291
size_t async_callback_scope_depth_ = 0;
12891292
std::vector<double> destroy_async_id_list_;
12901293

src/node_process_methods.cc

+11
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,17 @@ static void Umask(const FunctionCallbackInfo<Value>& args) {
245245

246246
uint32_t old;
247247
if (args[0]->IsUndefined()) {
248+
if (env->emit_insecure_umask_warning()) {
249+
env->set_emit_insecure_umask_warning(false);
250+
if (ProcessEmitDeprecationWarning(
251+
env,
252+
"Calling process.umask() with no arguments is prone to race "
253+
"conditions and is a potential security vulnerability.",
254+
"DEP0139").IsNothing()) {
255+
return;
256+
}
257+
}
258+
248259
old = umask(0);
249260
umask(static_cast<mode_t>(old));
250261
} else {

test/parallel/test-process-umask.js

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ if (common.isWindows) {
4040
mask = '0664';
4141
}
4242

43+
common.expectWarning(
44+
'DeprecationWarning',
45+
'Calling process.umask() with no arguments is prone to race conditions ' +
46+
'and is a potential security vulnerability.',
47+
'DEP0139'
48+
);
49+
4350
const old = process.umask(mask);
4451

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

0 commit comments

Comments
 (0)