| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 081c708 commit a0b1378
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -518,9 +518,6 @@ static void Execve(const FunctionCallbackInfo<Value>& args) { | |||
| 518 | 518 | Isolate* isolate = env->isolate(); | |
| 519 | 519 | Local<Context> context = env->context(); | |
| 520 | 520 | ||
| 521 | - THROW_IF_INSUFFICIENT_PERMISSIONS( | ||
| 522 | - env, permission::PermissionScope::kChildProcess, ""); | ||
| 523 | - | ||
| 524 | 521 | CHECK(args[0]->IsString()); | |
| 525 | 522 | CHECK(args[1]->IsArray()); | |
| 526 | 523 | CHECK(args[2]->IsArray()); | |
@@ -530,6 +527,11 @@ static void Execve(const FunctionCallbackInfo<Value>& args) { | |||
| 530 | 527 | ||
| 531 | 528 | // Copy arguments and environment | |
| 532 | 529 | Utf8Value executable(isolate, args[0]); | |
| 530 | + | ||
| 531 | + THROW_IF_INSUFFICIENT_PERMISSIONS(env, | ||
| 532 | + permission::PermissionScope::kChildProcess, | ||
| 533 | + executable.ToStringView()); | ||
| 534 | + | ||
| 533 | 535 | std::vector<std::string> argv_strings(argv_array->Length()); | |
| 534 | 536 | std::vector<std::string> envp_strings(envp_array->Length()); | |
| 535 | 537 | std::vector<char*> argv(argv_array->Length() + 1); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -186,8 +186,6 @@ class ProcessWrap : public HandleWrap { | |||
| 186 | 186 | Local<Context> context = env->context(); | |
| 187 | 187 | ProcessWrap* wrap; | |
| 188 | 188 | ASSIGN_OR_RETURN_UNWRAP(&wrap, args.This()); | |
| 189 | - THROW_IF_INSUFFICIENT_PERMISSIONS( | ||
| 190 | - env, permission::PermissionScope::kChildProcess, ""); | ||
| 191 | 189 | int err = 0; | |
| 192 | 190 | ||
| 193 | 191 | if (!args[0]->IsObject()) { | |
@@ -201,6 +199,20 @@ class ProcessWrap : public HandleWrap { | |||
| 201 | 199 | ||
| 202 | 200 | options.exit_cb = OnExit; | |
| 203 | 201 | ||
| 202 | + // TODO(bnoordhuis) is this possible to do without mallocing ? | ||
| 203 | + | ||
| 204 | + // options.file | ||
| 205 | + Local<Value> file_v; | ||
| 206 | + if (!js_options->Get(context, env->file_string()).ToLocal(&file_v)) { | ||
| 207 | + return; | ||
| 208 | + } | ||
| 209 | + CHECK(file_v->IsString()); | ||
| 210 | + node::Utf8Value file(env->isolate(), file_v); | ||
| 211 | + options.file = *file; | ||
| 212 | + | ||
| 213 | + THROW_IF_INSUFFICIENT_PERMISSIONS( | ||
| 214 | + env, permission::PermissionScope::kChildProcess, file.ToStringView()); | ||
| 215 | + | ||
| 204 | 216 | // options.uid | |
| 205 | 217 | Local<Value> uid_v; | |
| 206 | 218 | if (!js_options->Get(context, env->uid_string()).ToLocal(&uid_v)) { | |
@@ -225,17 +237,6 @@ class ProcessWrap : public HandleWrap { | |||
| 225 | 237 | options.gid = static_cast<uv_gid_t>(gid); | |
| 226 | 238 | } | |
| 227 | 239 | ||
| 228 | - // TODO(bnoordhuis) is this possible to do without mallocing ? | ||
| 229 | - | ||
| 230 | - // options.file | ||
| 231 | - Local<Value> file_v; | ||
| 232 | - if (!js_options->Get(context, env->file_string()).ToLocal(&file_v)) { | ||
| 233 | - return; | ||
| 234 | - } | ||
| 235 | - CHECK(file_v->IsString()); | ||
| 236 | - node::Utf8Value file(env->isolate(), file_v); | ||
| 237 | - options.file = *file; | ||
| 238 | - | ||
| 239 | 240 | // Undocumented feature of Win32 CreateProcess API allows spawning | |
| 240 | 241 | // batch files directly but is potentially insecure because arguments | |
| 241 | 242 | // are not escaped (and sometimes cannot be unambiguously escaped), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -378,8 +378,24 @@ void SyncProcessRunner::RegisterExternalReferences( | |||
| 378 | 378 | ||
| 379 | 379 | void SyncProcessRunner::Spawn(const FunctionCallbackInfo<Value>& args) { | |
| 380 | 380 | Environment* env = Environment::GetCurrent(args); | |
| 381 | + Local<Context> context = env->context(); | ||
| 382 | + | ||
| 383 | + std::string resource = ""; | ||
| 384 | + if (env->permission()->enabled() && args[0]->IsObject()) { | ||
| 385 | + Local<Object> js_options = args[0].As<Object>(); | ||
| 386 | + Local<Value> js_file; | ||
| 387 | + if (!js_options->Get(context, env->file_string()).ToLocal(&js_file)) { | ||
| 388 | + return; | ||
| 389 | + } | ||
| 390 | + | ||
| 391 | + if (js_file->IsString()) { | ||
| 392 | + node::Utf8Value executable(env->isolate(), js_file.As<String>()); | ||
| 393 | + resource = executable.ToString(); | ||
| 394 | + } | ||
| 395 | + } | ||
| 396 | + | ||
| 381 | 397 | THROW_IF_INSUFFICIENT_PERMISSIONS( | |
| 382 | - env, permission::PermissionScope::kChildProcess, ""); | ||
| 398 | + env, permission::PermissionScope::kChildProcess, resource); | ||
| 383 | 399 | env->PrintSyncTrace(); | |
| 384 | 400 | SyncProcessRunner p(env); | |
| 385 | 401 | Local<Value> result; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,12 +29,14 @@ if (process.argv[2] === 'child') { | |||
| 29 | 29 | message: 'Access to this API has been restricted. Use --allow-child-process to manage permissions.', | |
| 30 | 30 | code: 'ERR_ACCESS_DENIED', | |
| 31 | 31 | permission: 'ChildProcess', | |
| 32 | + resource: process.execPath, | ||
| 32 | 33 | })); | |
| 33 | 34 | assert.throws(() => { | |
| 34 | 35 | childProcess.spawnSync(process.execPath, ['--version']); | |
| 35 | 36 | }, common.expectsError({ | |
| 36 | 37 | code: 'ERR_ACCESS_DENIED', | |
| 37 | 38 | permission: 'ChildProcess', | |
| 39 | + resource: process.execPath, | ||
| 38 | 40 | })); | |
| 39 | 41 | assert.throws(() => { | |
| 40 | 42 | childProcess.exec(...common.escapePOSIXShell`"${process.execPath}" --version`); | |
@@ -53,6 +55,7 @@ if (process.argv[2] === 'child') { | |||
| 53 | 55 | }, common.expectsError({ | |
| 54 | 56 | code: 'ERR_ACCESS_DENIED', | |
| 55 | 57 | permission: 'ChildProcess', | |
| 58 | + resource: process.execPath, | ||
| 56 | 59 | })); | |
| 57 | 60 | assert.throws(() => { | |
| 58 | 61 | childProcess.execFile(...common.escapePOSIXShell`"${process.execPath}" --version`); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,5 +17,5 @@ if (process.argv[2] === 'replaced') { | |||
| 17 | 17 | } else { | |
| 18 | 18 | throws(mustCall(() => { | |
| 19 | 19 | process.execve(process.execPath, [process.execPath, __filename, 'replaced'], process.env); | |
| 20 | - }), { code: 'ERR_ACCESS_DENIED', permission: 'ChildProcess' }); | ||
| 20 | + }), { code: 'ERR_ACCESS_DENIED', permission: 'ChildProcess', resource: process.execPath }); | ||
| 21 | 21 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments