@encharm/cws 4.5.3 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/CLAUDE.md +83 -0
- package/README.md +20 -4
- package/binding.gyp +8 -2
- package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
- package/dist/bindings/cws_linux_arm64_node115.node +0 -0
- package/dist/bindings/cws_linux_arm64_node127.node +0 -0
- package/dist/bindings/cws_linux_arm64_node137.node +0 -0
- package/dist/bindings/cws_linux_arm64_node147.node +0 -0
- package/dist/bindings/cws_linux_x64_node115.node +0 -0
- package/dist/bindings/cws_linux_x64_node127.node +0 -0
- package/dist/bindings/cws_linux_x64_node137.node +0 -0
- package/dist/bindings/cws_linux_x64_node147.node +0 -0
- package/dist/bindings/cws_win32_x64_node115.node +0 -0
- package/dist/bindings/cws_win32_x64_node127.node +0 -0
- package/dist/bindings/cws_win32_x64_node137.node +0 -0
- package/dist/bindings/cws_win32_x64_node147.node +0 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +15 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +2 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +16 -2
- package/dist/shared.d.ts +1 -0
- package/dist/shared.js +3 -2
- package/package.json +1 -1
- package/src/Addon.cpp +4 -1
- package/src/Addon.h +80 -15
- package/src/Extensions.cpp +7 -1
- package/src/Extensions.h +2 -1
- package/src/Group.cpp +1 -1
- package/src/Group.h +4 -1
- package/src/HTTPSocket.cpp +1 -1
- package/src/Hub.cpp +11 -76
- package/src/Hub.h +12 -10
- package/src/Networking.h +11 -0
- package/src/Socket.h +201 -6
- package/src/WebSocket.cpp +8 -5
- package/src/Zlib.cpp +138 -0
- package/src/Zlib.h +38 -0
- package/src/cSNode.cpp +2 -0
- package/src/cSNode.h +4 -0
- package/src/headers/26/acorn_version.h +6 -0
- package/src/headers/26/aliased_buffer-inl.h +264 -0
- package/src/headers/26/aliased_buffer.h +205 -0
- package/src/headers/26/aliased_struct-inl.h +143 -0
- package/src/headers/26/aliased_struct.h +248 -0
- package/src/headers/26/amaro_version.h +6 -0
- package/src/headers/26/async_context_frame.h +33 -0
- package/src/headers/26/async_wrap-inl.h +123 -0
- package/src/headers/26/async_wrap.h +254 -0
- package/src/headers/26/base_object-inl.h +333 -0
- package/src/headers/26/base_object.h +339 -0
- package/src/headers/26/base_object_types.h +76 -0
- package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
- package/src/headers/26/blob_serializer_deserializer.h +142 -0
- package/src/headers/26/builtin_info.h +57 -0
- package/src/headers/26/callback_queue-inl.h +97 -0
- package/src/headers/26/callback_queue.h +79 -0
- package/src/headers/26/cares_wrap.h +475 -0
- package/src/headers/26/cleanup_queue-inl.h +36 -0
- package/src/headers/26/cleanup_queue.h +79 -0
- package/src/headers/26/compile_cache.h +134 -0
- package/src/headers/26/connect_wrap.h +26 -0
- package/src/headers/26/connection_wrap.h +30 -0
- package/src/headers/26/cppgc_helpers-inl.h +69 -0
- package/src/headers/26/cppgc_helpers.h +162 -0
- package/src/headers/26/crypto/crypto_aes.h +107 -0
- package/src/headers/26/crypto/crypto_argon2.h +88 -0
- package/src/headers/26/crypto/crypto_bio.h +193 -0
- package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
- package/src/headers/26/crypto/crypto_cipher.h +291 -0
- package/src/headers/26/crypto/crypto_common.h +48 -0
- package/src/headers/26/crypto/crypto_context.h +219 -0
- package/src/headers/26/crypto/crypto_dh.h +104 -0
- package/src/headers/26/crypto/crypto_dsa.h +50 -0
- package/src/headers/26/crypto/crypto_ec.h +102 -0
- package/src/headers/26/crypto/crypto_hash.h +157 -0
- package/src/headers/26/crypto/crypto_hkdf.h +62 -0
- package/src/headers/26/crypto/crypto_hmac.h +92 -0
- package/src/headers/26/crypto/crypto_kem.h +131 -0
- package/src/headers/26/crypto/crypto_keygen.h +382 -0
- package/src/headers/26/crypto/crypto_keys.h +366 -0
- package/src/headers/26/crypto/crypto_kmac.h +79 -0
- package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
- package/src/headers/26/crypto/crypto_pqc.h +39 -0
- package/src/headers/26/crypto/crypto_random.h +127 -0
- package/src/headers/26/crypto/crypto_rsa.h +108 -0
- package/src/headers/26/crypto/crypto_scrypt.h +85 -0
- package/src/headers/26/crypto/crypto_sig.h +159 -0
- package/src/headers/26/crypto/crypto_spkac.h +21 -0
- package/src/headers/26/crypto/crypto_timing.h +20 -0
- package/src/headers/26/crypto/crypto_tls.h +342 -0
- package/src/headers/26/crypto/crypto_turboshake.h +105 -0
- package/src/headers/26/crypto/crypto_util.h +775 -0
- package/src/headers/26/crypto/crypto_x509.h +140 -0
- package/src/headers/26/dataqueue/queue.h +311 -0
- package/src/headers/26/debug_utils-inl.h +291 -0
- package/src/headers/26/debug_utils.h +200 -0
- package/src/headers/26/diagnosticfilename-inl.h +33 -0
- package/src/headers/26/embedded_data.h +17 -0
- package/src/headers/26/encoding_binding.h +59 -0
- package/src/headers/26/env-inl.h +956 -0
- package/src/headers/26/env.h +1294 -0
- package/src/headers/26/env_properties.h +562 -0
- package/src/headers/26/ffi/data.h +30 -0
- package/src/headers/26/ffi/fast.h +96 -0
- package/src/headers/26/ffi/jit_memory.h +26 -0
- package/src/headers/26/ffi/types.h +99 -0
- package/src/headers/26/handle_wrap.h +123 -0
- package/src/headers/26/histogram-inl.h +211 -0
- package/src/headers/26/histogram.h +474 -0
- package/src/headers/26/inspector/dom_storage_agent.h +68 -0
- package/src/headers/26/inspector/inspector_object_utils.h +38 -0
- package/src/headers/26/inspector/io_agent.h +30 -0
- package/src/headers/26/inspector/main_thread_interface.h +116 -0
- package/src/headers/26/inspector/network_agent.h +110 -0
- package/src/headers/26/inspector/network_inspector.h +45 -0
- package/src/headers/26/inspector/network_requests_buffer.h +195 -0
- package/src/headers/26/inspector/network_resource_manager.h +29 -0
- package/src/headers/26/inspector/node_json.h +24 -0
- package/src/headers/26/inspector/node_string.h +101 -0
- package/src/headers/26/inspector/notification_emitter.h +38 -0
- package/src/headers/26/inspector/protocol_helper.h +27 -0
- package/src/headers/26/inspector/runtime_agent.h +41 -0
- package/src/headers/26/inspector/storage_agent.h +33 -0
- package/src/headers/26/inspector/target_agent.h +59 -0
- package/src/headers/26/inspector/target_manager.h +70 -0
- package/src/headers/26/inspector/tracing_agent.h +43 -0
- package/src/headers/26/inspector/worker_agent.h +40 -0
- package/src/headers/26/inspector/worker_inspector.h +124 -0
- package/src/headers/26/inspector_agent.h +168 -0
- package/src/headers/26/inspector_io.h +78 -0
- package/src/headers/26/inspector_profiler.h +149 -0
- package/src/headers/26/inspector_socket.h +60 -0
- package/src/headers/26/inspector_socket_server.h +110 -0
- package/src/headers/26/js_native_api.h +634 -0
- package/src/headers/26/js_native_api_types.h +244 -0
- package/src/headers/26/js_native_api_v8.h +485 -0
- package/src/headers/26/js_native_api_v8_internals.h +45 -0
- package/src/headers/26/js_stream.h +57 -0
- package/src/headers/26/json_utils.h +172 -0
- package/src/headers/26/large_pages/node_large_page.h +34 -0
- package/src/headers/26/lru_cache-inl.h +69 -0
- package/src/headers/26/memory_tracker-inl.h +461 -0
- package/src/headers/26/memory_tracker.h +341 -0
- package/src/headers/26/module_wrap.h +231 -0
- package/src/headers/26/ncrypto.h +2008 -0
- package/src/headers/26/node.h +1693 -0
- package/src/headers/26/node_api.h +265 -0
- package/src/headers/26/node_api_internals.h +48 -0
- package/src/headers/26/node_api_types.h +58 -0
- package/src/headers/26/node_binding.h +170 -0
- package/src/headers/26/node_blob.h +160 -0
- package/src/headers/26/node_bob-inl.h +36 -0
- package/src/headers/26/node_bob.h +107 -0
- package/src/headers/26/node_buffer.h +92 -0
- package/src/headers/26/node_builtins.h +239 -0
- package/src/headers/26/node_concepts.h +46 -0
- package/src/headers/26/node_config_file.h +77 -0
- package/src/headers/26/node_constants.h +82 -0
- package/src/headers/26/node_context_data.h +171 -0
- package/src/headers/26/node_contextify.h +261 -0
- package/src/headers/26/node_crypto.h +66 -0
- package/src/headers/26/node_debug.h +30 -0
- package/src/headers/26/node_diagnostics_channel.h +121 -0
- package/src/headers/26/node_dir.h +52 -0
- package/src/headers/26/node_dotenv.h +45 -0
- package/src/headers/26/node_errors.h +378 -0
- package/src/headers/26/node_exit_code.h +54 -0
- package/src/headers/26/node_external_reference.h +171 -0
- package/src/headers/26/node_ffi.h +212 -0
- package/src/headers/26/node_file-inl.h +421 -0
- package/src/headers/26/node_file.h +561 -0
- package/src/headers/26/node_file_utils.h +39 -0
- package/src/headers/26/node_hash.h +212 -0
- package/src/headers/26/node_http2.h +1202 -0
- package/src/headers/26/node_http2_state.h +159 -0
- package/src/headers/26/node_http_common-inl.h +199 -0
- package/src/headers/26/node_http_common.h +535 -0
- package/src/headers/26/node_i18n.h +132 -0
- package/src/headers/26/node_internals.h +485 -0
- package/src/headers/26/node_locks.h +184 -0
- package/src/headers/26/node_main_instance.h +67 -0
- package/src/headers/26/node_mem-inl.h +113 -0
- package/src/headers/26/node_mem.h +45 -0
- package/src/headers/26/node_messaging.h +389 -0
- package/src/headers/26/node_metadata.h +172 -0
- package/src/headers/26/node_modules.h +102 -0
- package/src/headers/26/node_mutex.h +323 -0
- package/src/headers/26/node_object_wrap.h +145 -0
- package/src/headers/26/node_options-inl.h +524 -0
- package/src/headers/26/node_options.h +710 -0
- package/src/headers/26/node_perf.h +167 -0
- package/src/headers/26/node_perf_common.h +103 -0
- package/src/headers/26/node_platform.h +290 -0
- package/src/headers/26/node_process-inl.h +26 -0
- package/src/headers/26/node_process.h +112 -0
- package/src/headers/26/node_profiling.h +38 -0
- package/src/headers/26/node_realm-inl.h +156 -0
- package/src/headers/26/node_realm.h +236 -0
- package/src/headers/26/node_report.h +43 -0
- package/src/headers/26/node_revert.h +82 -0
- package/src/headers/26/node_root_certs.h +2937 -0
- package/src/headers/26/node_sea.h +101 -0
- package/src/headers/26/node_shadow_realm.h +46 -0
- package/src/headers/26/node_snapshot_builder.h +57 -0
- package/src/headers/26/node_snapshotable.h +167 -0
- package/src/headers/26/node_sockaddr-inl.h +248 -0
- package/src/headers/26/node_sockaddr.h +459 -0
- package/src/headers/26/node_sqlite.h +607 -0
- package/src/headers/26/node_stat_watcher.h +73 -0
- package/src/headers/26/node_task_runner.h +92 -0
- package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
- package/src/headers/26/node_threadsafe_cow.h +105 -0
- package/src/headers/26/node_union_bytes.h +81 -0
- package/src/headers/26/node_url.h +101 -0
- package/src/headers/26/node_url_pattern.h +118 -0
- package/src/headers/26/node_v8.h +78 -0
- package/src/headers/26/node_v8_embedder.h +26 -0
- package/src/headers/26/node_v8_platform-inl.h +96 -0
- package/src/headers/26/node_version.h +116 -0
- package/src/headers/26/node_wasi.h +184 -0
- package/src/headers/26/node_wasm_web_api.h +55 -0
- package/src/headers/26/node_watchdog.h +164 -0
- package/src/headers/26/node_webstorage.h +62 -0
- package/src/headers/26/node_worker.h +162 -0
- package/src/headers/26/path.h +36 -0
- package/src/headers/26/permission/boolean_permission.h +50 -0
- package/src/headers/26/permission/fs_permission.h +192 -0
- package/src/headers/26/permission/permission.h +155 -0
- package/src/headers/26/permission/permission_base.h +79 -0
- package/src/headers/26/pipe_wrap.h +80 -0
- package/src/headers/26/quic/application.h +279 -0
- package/src/headers/26/quic/arena.h +373 -0
- package/src/headers/26/quic/bindingdata.h +440 -0
- package/src/headers/26/quic/cid.h +127 -0
- package/src/headers/26/quic/data.h +358 -0
- package/src/headers/26/quic/defs.h +417 -0
- package/src/headers/26/quic/endpoint.h +519 -0
- package/src/headers/26/quic/guard.h +5 -0
- package/src/headers/26/quic/http3.h +25 -0
- package/src/headers/26/quic/packet.h +166 -0
- package/src/headers/26/quic/preferredaddress.h +72 -0
- package/src/headers/26/quic/session.h +770 -0
- package/src/headers/26/quic/session_manager.h +107 -0
- package/src/headers/26/quic/sessionticket.h +110 -0
- package/src/headers/26/quic/streams.h +518 -0
- package/src/headers/26/quic/tlscontext.h +353 -0
- package/src/headers/26/quic/tokens.h +263 -0
- package/src/headers/26/quic/transportparams.h +184 -0
- package/src/headers/26/req_wrap-inl.h +175 -0
- package/src/headers/26/req_wrap.h +79 -0
- package/src/headers/26/spawn_sync.h +243 -0
- package/src/headers/26/stream_base-inl.h +170 -0
- package/src/headers/26/stream_base.h +487 -0
- package/src/headers/26/stream_pipe.h +76 -0
- package/src/headers/26/stream_wrap.h +137 -0
- package/src/headers/26/string_bytes.h +114 -0
- package/src/headers/26/string_decoder-inl.h +31 -0
- package/src/headers/26/string_decoder.h +49 -0
- package/src/headers/26/tcp_wrap.h +138 -0
- package/src/headers/26/threadpoolwork-inl.h +70 -0
- package/src/headers/26/timer_wrap-inl.h +32 -0
- package/src/headers/26/timer_wrap.h +87 -0
- package/src/headers/26/timers.h +70 -0
- package/src/headers/26/tracing/agent.h +125 -0
- package/src/headers/26/tracing/agent_legacy.h +146 -0
- package/src/headers/26/tracing/agent_perfetto.h +145 -0
- package/src/headers/26/tracing/node_trace_buffer.h +91 -0
- package/src/headers/26/tracing/node_trace_writer.h +79 -0
- package/src/headers/26/tracing/trace_event.h +27 -0
- package/src/headers/26/tracing/trace_event_helper.h +40 -0
- package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
- package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
- package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
- package/src/headers/26/tracing/traced_value.h +167 -0
- package/src/headers/26/tty_wrap.h +65 -0
- package/src/headers/26/udp_wrap.h +231 -0
- package/src/headers/26/undici_version.h +6 -0
- package/src/headers/26/util-inl.h +788 -0
- package/src/headers/26/util.h +1207 -0
- package/src/headers/26/v8-cpp-heap-external.h +56 -0
- package/src/headers/26/v8-external-memory-accounter.h +60 -0
- package/src/headers/26/v8-fast-api-calls.h +784 -0
- package/src/headers/26/v8-inspector-protocol.h +13 -0
- package/src/headers/26/v8-inspector.h +458 -0
- package/src/headers/26/v8-metrics.h +273 -0
- package/src/headers/26/v8-trace-categories.h +28 -0
- package/src/headers/26/v8-unwinder-state.h +30 -0
- package/src/headers/26/v8-util.h +549 -0
- package/src/headers/26/v8-value-serializer-version.h +24 -0
- package/src/headers/26/v8-version-string.h +38 -0
- package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
- package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
- package/src/headers/26/zlib_version.h +6 -0
- package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Info.plist +0 -20
- package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node115.node.yml +0 -931
- package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Info.plist +0 -20
- package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node127.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node127.node.yml +0 -931
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#ifndef SRC_NODE_WORKER_H_
|
|
2
|
+
#define SRC_NODE_WORKER_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <optional>
|
|
7
|
+
#include <unordered_map>
|
|
8
|
+
#include "json_utils.h"
|
|
9
|
+
#include "node_exit_code.h"
|
|
10
|
+
#include "node_messaging.h"
|
|
11
|
+
#include "util.h"
|
|
12
|
+
#include "uv.h"
|
|
13
|
+
|
|
14
|
+
namespace node {
|
|
15
|
+
|
|
16
|
+
struct SnapshotData;
|
|
17
|
+
namespace worker {
|
|
18
|
+
|
|
19
|
+
class WorkerThreadData;
|
|
20
|
+
|
|
21
|
+
enum ResourceLimits {
|
|
22
|
+
kMaxYoungGenerationSizeMb,
|
|
23
|
+
kMaxOldGenerationSizeMb,
|
|
24
|
+
kCodeRangeSizeMb,
|
|
25
|
+
kStackSizeMb,
|
|
26
|
+
kTotalResourceLimitCount
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// A worker thread, as represented in its parent thread.
|
|
30
|
+
class Worker : public AsyncWrap {
|
|
31
|
+
public:
|
|
32
|
+
Worker(Environment* env,
|
|
33
|
+
v8::Local<v8::Object> wrap,
|
|
34
|
+
const std::string& url,
|
|
35
|
+
const std::string& name,
|
|
36
|
+
std::shared_ptr<PerIsolateOptions> per_isolate_opts,
|
|
37
|
+
std::vector<std::string>&& exec_argv,
|
|
38
|
+
std::shared_ptr<KVStore> env_vars,
|
|
39
|
+
const SnapshotData* snapshot_data,
|
|
40
|
+
const bool is_internal);
|
|
41
|
+
~Worker() override;
|
|
42
|
+
|
|
43
|
+
// Run the worker. This is only called from the worker thread.
|
|
44
|
+
void Run();
|
|
45
|
+
|
|
46
|
+
// Forcibly exit the thread with a specified exit code. This may be called
|
|
47
|
+
// from any thread. `error_code` and `error_message` can be used to create
|
|
48
|
+
// a custom `'error'` event before emitting `'exit'`.
|
|
49
|
+
void Exit(ExitCode code,
|
|
50
|
+
const char* error_code = nullptr,
|
|
51
|
+
const char* error_message = nullptr);
|
|
52
|
+
|
|
53
|
+
// Wait for the worker thread to stop (in a blocking manner).
|
|
54
|
+
void JoinThread();
|
|
55
|
+
|
|
56
|
+
template <typename Fn>
|
|
57
|
+
inline bool RequestInterrupt(Fn&& cb);
|
|
58
|
+
|
|
59
|
+
SET_NO_MEMORY_INFO()
|
|
60
|
+
SET_MEMORY_INFO_NAME(Worker)
|
|
61
|
+
SET_SELF_SIZE(Worker)
|
|
62
|
+
bool IsNotIndicativeOfMemoryLeakAtExit() const override;
|
|
63
|
+
|
|
64
|
+
bool is_stopped() const;
|
|
65
|
+
const SnapshotData* snapshot_data() const { return snapshot_data_; }
|
|
66
|
+
bool is_internal() const { return is_internal_; }
|
|
67
|
+
std::string_view name() const { return name_; }
|
|
68
|
+
|
|
69
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
70
|
+
static void StartThread(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
71
|
+
static void StopThread(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
72
|
+
static void HasRef(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
73
|
+
static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
74
|
+
static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
75
|
+
static void GetResourceLimits(
|
|
76
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
77
|
+
v8::Local<v8::Float64Array> GetResourceLimits(v8::Isolate* isolate) const;
|
|
78
|
+
static void TakeHeapSnapshot(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
79
|
+
static void LoopIdleTime(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
80
|
+
static void LoopStartTime(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
81
|
+
static void GetHeapStatistics(
|
|
82
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
83
|
+
static void CpuUsage(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
84
|
+
static void StartCpuProfile(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
85
|
+
static void StopCpuProfile(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
86
|
+
static void StartHeapProfile(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
87
|
+
static void StopHeapProfile(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
88
|
+
|
|
89
|
+
private:
|
|
90
|
+
bool CreateEnvMessagePort(Environment* env);
|
|
91
|
+
static size_t NearHeapLimit(void* data, size_t current_heap_limit,
|
|
92
|
+
size_t initial_heap_limit);
|
|
93
|
+
|
|
94
|
+
std::shared_ptr<PerIsolateOptions> per_isolate_opts_;
|
|
95
|
+
std::vector<std::string> exec_argv_;
|
|
96
|
+
std::vector<std::string> argv_;
|
|
97
|
+
|
|
98
|
+
MultiIsolatePlatform* platform_;
|
|
99
|
+
v8::Isolate* isolate_ = nullptr;
|
|
100
|
+
std::optional<uv_thread_t> tid_; // Set while the thread is running
|
|
101
|
+
|
|
102
|
+
std::unique_ptr<InspectorParentHandle> inspector_parent_handle_;
|
|
103
|
+
|
|
104
|
+
// This mutex protects access to all variables listed below it.
|
|
105
|
+
mutable Mutex mutex_;
|
|
106
|
+
|
|
107
|
+
const char* custom_error_ = nullptr;
|
|
108
|
+
std::string custom_error_str_;
|
|
109
|
+
ExitCode exit_code_ = ExitCode::kNoFailure;
|
|
110
|
+
ThreadId thread_id_;
|
|
111
|
+
uintptr_t stack_base_ = 0;
|
|
112
|
+
// Optional name used for debugging in inspector and trace events.
|
|
113
|
+
std::string name_;
|
|
114
|
+
|
|
115
|
+
// Custom resource constraints:
|
|
116
|
+
double resource_limits_[kTotalResourceLimitCount];
|
|
117
|
+
void UpdateResourceConstraints(v8::ResourceConstraints* constraints);
|
|
118
|
+
|
|
119
|
+
// Full size of the thread's stack.
|
|
120
|
+
size_t stack_size_ = 4 * 1024 * 1024;
|
|
121
|
+
// Stack buffer size that is not available to the JS engine.
|
|
122
|
+
static constexpr size_t kStackBufferSize = 192 * 1024;
|
|
123
|
+
|
|
124
|
+
std::unique_ptr<MessagePortData> child_port_data_;
|
|
125
|
+
std::shared_ptr<KVStore> env_vars_;
|
|
126
|
+
EmbedderPreloadCallback embedder_preload_;
|
|
127
|
+
|
|
128
|
+
// A raw flag that is used by creator and worker threads to
|
|
129
|
+
// sync up on pre-mature termination of worker - while in the
|
|
130
|
+
// warmup phase. Once the worker is fully warmed up, use the
|
|
131
|
+
// async handle of the worker's Environment for the same purpose.
|
|
132
|
+
bool stopped_ = true;
|
|
133
|
+
|
|
134
|
+
bool has_ref_ = true;
|
|
135
|
+
uint64_t environment_flags_ = EnvironmentFlags::kNoFlags;
|
|
136
|
+
|
|
137
|
+
// The real Environment of the worker object. It has a lesser
|
|
138
|
+
// lifespan than the worker object itself - comes to life
|
|
139
|
+
// when the worker thread creates a new Environment, and gets
|
|
140
|
+
// destroyed alongwith the worker thread.
|
|
141
|
+
Environment* env_ = nullptr;
|
|
142
|
+
|
|
143
|
+
const SnapshotData* snapshot_data_ = nullptr;
|
|
144
|
+
const bool is_internal_;
|
|
145
|
+
friend class WorkerThreadData;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
template <typename Fn>
|
|
149
|
+
bool Worker::RequestInterrupt(Fn&& cb) {
|
|
150
|
+
Mutex::ScopedLock lock(mutex_);
|
|
151
|
+
if (env_ == nullptr) return false;
|
|
152
|
+
env_->RequestInterrupt(std::move(cb));
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
} // namespace worker
|
|
157
|
+
} // namespace node
|
|
158
|
+
|
|
159
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
#endif // SRC_NODE_WORKER_H_
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#ifndef SRC_PATH_H_
|
|
2
|
+
#define SRC_PATH_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <vector>
|
|
8
|
+
#include "node_options-inl.h"
|
|
9
|
+
#include "util-inl.h"
|
|
10
|
+
|
|
11
|
+
namespace node {
|
|
12
|
+
|
|
13
|
+
constexpr bool IsPathSeparator(const char c) noexcept;
|
|
14
|
+
|
|
15
|
+
std::string NormalizeString(const std::string_view path,
|
|
16
|
+
bool allowAboveRoot,
|
|
17
|
+
const std::string_view separator);
|
|
18
|
+
|
|
19
|
+
std::string PathResolve(Environment* env,
|
|
20
|
+
const std::vector<std::string_view>& paths);
|
|
21
|
+
std::string NormalizeFileURLOrPath(Environment* env, std::string_view path);
|
|
22
|
+
bool IsAbsoluteFilePath(std::string_view path);
|
|
23
|
+
|
|
24
|
+
#ifdef _WIN32
|
|
25
|
+
constexpr bool IsWindowsDeviceRoot(const char c) noexcept;
|
|
26
|
+
constexpr bool IsWindowsDriveLetter(const std::string_view path) noexcept;
|
|
27
|
+
#endif // _WIN32
|
|
28
|
+
|
|
29
|
+
void ToNamespacedPath(Environment* env, BufferValue* path);
|
|
30
|
+
void FromNamespacedPath(std::string* path);
|
|
31
|
+
|
|
32
|
+
} // namespace node
|
|
33
|
+
|
|
34
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
35
|
+
|
|
36
|
+
#endif // SRC_PATH_H_
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#ifndef SRC_PERMISSION_BOOLEAN_PERMISSION_H_
|
|
2
|
+
#define SRC_PERMISSION_BOOLEAN_PERMISSION_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "permission/permission_base.h"
|
|
7
|
+
|
|
8
|
+
namespace node::permission {
|
|
9
|
+
|
|
10
|
+
// A simple boolean permission that either denies or allows access.
|
|
11
|
+
// Used for permission scopes that don't need per-resource granularity.
|
|
12
|
+
template <bool deny_only>
|
|
13
|
+
class BooleanPermission final : public PermissionBase {
|
|
14
|
+
public:
|
|
15
|
+
void Apply(Environment* env,
|
|
16
|
+
std::span<const std::string> allow,
|
|
17
|
+
PermissionScope scope) override {
|
|
18
|
+
flag_ = true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
void Drop(Environment* env,
|
|
22
|
+
PermissionScope scope,
|
|
23
|
+
std::string_view param) override {
|
|
24
|
+
flag_ = deny_only;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
bool is_granted(Environment* env,
|
|
28
|
+
PermissionScope perm,
|
|
29
|
+
std::string_view param) const override {
|
|
30
|
+
if constexpr (deny_only) {
|
|
31
|
+
return !flag_;
|
|
32
|
+
} else {
|
|
33
|
+
return flag_;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private:
|
|
38
|
+
bool flag_ = false;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Once denied, the permission cannot be re-granted.
|
|
42
|
+
using DenyOnlyPermission = BooleanPermission<true>;
|
|
43
|
+
|
|
44
|
+
// Apply grants access, Drop revokes.
|
|
45
|
+
using AllowRevokePermission = BooleanPermission<false>;
|
|
46
|
+
|
|
47
|
+
} // namespace node::permission
|
|
48
|
+
|
|
49
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
50
|
+
#endif // SRC_PERMISSION_BOOLEAN_PERMISSION_H_
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
#ifndef SRC_PERMISSION_FS_PERMISSION_H_
|
|
2
|
+
#define SRC_PERMISSION_FS_PERMISSION_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <vector>
|
|
7
|
+
#include "permission/permission_base.h"
|
|
8
|
+
#include "util.h"
|
|
9
|
+
|
|
10
|
+
namespace node::permission {
|
|
11
|
+
|
|
12
|
+
class FSPermission final : public PermissionBase {
|
|
13
|
+
public:
|
|
14
|
+
void Apply(Environment* env,
|
|
15
|
+
std::span<const std::string> allow,
|
|
16
|
+
PermissionScope scope) override;
|
|
17
|
+
void Drop(Environment* env,
|
|
18
|
+
PermissionScope scope,
|
|
19
|
+
std::string_view param) override;
|
|
20
|
+
bool is_granted(Environment* env,
|
|
21
|
+
PermissionScope perm,
|
|
22
|
+
std::string_view param) const override;
|
|
23
|
+
|
|
24
|
+
struct RadixTree {
|
|
25
|
+
struct Node {
|
|
26
|
+
std::string prefix;
|
|
27
|
+
std::vector<std::pair<char, Node*>> children;
|
|
28
|
+
Node* wildcard_child = nullptr;
|
|
29
|
+
bool is_leaf = false;
|
|
30
|
+
|
|
31
|
+
explicit Node(std::string_view pre) : prefix(pre) {}
|
|
32
|
+
|
|
33
|
+
Node() = default;
|
|
34
|
+
|
|
35
|
+
Node* FindChild(char label) const {
|
|
36
|
+
for (const auto& [c, node] : children) {
|
|
37
|
+
if (c == label) return node;
|
|
38
|
+
}
|
|
39
|
+
return nullptr;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
void SetChild(char label, Node* node) {
|
|
43
|
+
for (auto& [c, n] : children) {
|
|
44
|
+
if (c == label) {
|
|
45
|
+
n = node;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
children.emplace_back(label, node);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Node* CreateChild(std::string_view path_prefix) {
|
|
53
|
+
if (path_prefix.empty() && !is_leaf) {
|
|
54
|
+
is_leaf = true;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
CHECK(!path_prefix.empty());
|
|
59
|
+
char label = path_prefix[0];
|
|
60
|
+
|
|
61
|
+
Node* child = FindChild(label);
|
|
62
|
+
if (child == nullptr) {
|
|
63
|
+
child = new Node(path_prefix);
|
|
64
|
+
children.emplace_back(label, child);
|
|
65
|
+
return child;
|
|
66
|
+
}
|
|
67
|
+
bool child_was_end_node = child->IsEndNode();
|
|
68
|
+
|
|
69
|
+
// swap prefix
|
|
70
|
+
size_t i = 0;
|
|
71
|
+
size_t prefix_len = path_prefix.length();
|
|
72
|
+
for (; i < child->prefix.length(); ++i) {
|
|
73
|
+
if (i >= prefix_len || path_prefix[i] != child->prefix[i]) {
|
|
74
|
+
std::string parent_prefix(child->prefix.substr(0, i));
|
|
75
|
+
std::string child_prefix(child->prefix.substr(i));
|
|
76
|
+
|
|
77
|
+
child->prefix = child_prefix;
|
|
78
|
+
Node* split_child = new Node(parent_prefix);
|
|
79
|
+
split_child->children.emplace_back(child_prefix[0], child);
|
|
80
|
+
SetChild(parent_prefix[0], split_child);
|
|
81
|
+
|
|
82
|
+
return split_child->CreateChild(path_prefix.substr(i));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (child_was_end_node) {
|
|
86
|
+
child->is_leaf = true;
|
|
87
|
+
}
|
|
88
|
+
return child->CreateChild(path_prefix.substr(i));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
Node* CreateWildcardChild() {
|
|
92
|
+
if (wildcard_child != nullptr) {
|
|
93
|
+
return wildcard_child;
|
|
94
|
+
}
|
|
95
|
+
wildcard_child = new Node();
|
|
96
|
+
return wildcard_child;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
Node* NextNode(std::string_view path, size_t idx) const {
|
|
100
|
+
if (idx >= path.length()) {
|
|
101
|
+
return nullptr;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// wildcard node takes precedence
|
|
105
|
+
if (children.size() > 1) {
|
|
106
|
+
Node* wc = FindChild('*');
|
|
107
|
+
if (wc != nullptr) {
|
|
108
|
+
return wc;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Node* child = FindChild(path[idx]);
|
|
113
|
+
if (child == nullptr) {
|
|
114
|
+
return nullptr;
|
|
115
|
+
}
|
|
116
|
+
// match prefix
|
|
117
|
+
size_t prefix_len = child->prefix.length();
|
|
118
|
+
for (size_t i = 0; i < path.length(); ++i) {
|
|
119
|
+
if (i >= prefix_len || child->prefix[i] == '*') {
|
|
120
|
+
return child;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Handle optional trailing
|
|
124
|
+
// path = /home/subdirectory
|
|
125
|
+
// child = subdirectory/*
|
|
126
|
+
if (idx >= path.length()) {
|
|
127
|
+
if (child->prefix[i] == node::kPathSeparator) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
// Path is exhausted but prefix expects more characters
|
|
131
|
+
return nullptr;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (path[idx++] != child->prefix[i]) {
|
|
135
|
+
return nullptr;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return child;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// A node can be a *end* node and have children
|
|
142
|
+
// E.g: */slower*, */slown* are inserted:
|
|
143
|
+
// /slow
|
|
144
|
+
// ---> er
|
|
145
|
+
// ---> n
|
|
146
|
+
// If */slow* is inserted right after, it will create an
|
|
147
|
+
// empty node
|
|
148
|
+
// /slow
|
|
149
|
+
// ---> '\000' ASCII (0) || \0
|
|
150
|
+
// ---> er
|
|
151
|
+
// ---> n
|
|
152
|
+
bool IsEndNode() const {
|
|
153
|
+
if (children.empty()) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
return is_leaf;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
RadixTree();
|
|
161
|
+
~RadixTree();
|
|
162
|
+
void Insert(const std::string& s);
|
|
163
|
+
void Clear();
|
|
164
|
+
bool Lookup(std::string_view s) const { return Lookup(s, false); }
|
|
165
|
+
bool Lookup(std::string_view s, bool when_empty_return) const;
|
|
166
|
+
|
|
167
|
+
private:
|
|
168
|
+
Node* root_node_;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
private:
|
|
172
|
+
void GrantAccess(PermissionScope scope, const std::string& param);
|
|
173
|
+
void RevokeAccess(PermissionScope scope, const std::string& param);
|
|
174
|
+
void RebuildTree(PermissionScope scope);
|
|
175
|
+
// fs granted on startup
|
|
176
|
+
RadixTree granted_in_fs_;
|
|
177
|
+
RadixTree granted_out_fs_;
|
|
178
|
+
|
|
179
|
+
std::vector<std::string> granted_paths_in_;
|
|
180
|
+
std::vector<std::string> granted_paths_out_;
|
|
181
|
+
|
|
182
|
+
bool deny_all_in_ = true;
|
|
183
|
+
bool deny_all_out_ = true;
|
|
184
|
+
|
|
185
|
+
bool allow_all_in_ = false;
|
|
186
|
+
bool allow_all_out_ = false;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
} // namespace node::permission
|
|
190
|
+
|
|
191
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
192
|
+
#endif // SRC_PERMISSION_FS_PERMISSION_H_
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#ifndef SRC_PERMISSION_PERMISSION_H_
|
|
2
|
+
#define SRC_PERMISSION_PERMISSION_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "debug_utils.h"
|
|
7
|
+
#include "node_diagnostics_channel.h"
|
|
8
|
+
#include "permission/permission_base.h"
|
|
9
|
+
|
|
10
|
+
#include <array>
|
|
11
|
+
#include <string_view>
|
|
12
|
+
|
|
13
|
+
namespace node {
|
|
14
|
+
|
|
15
|
+
class Environment;
|
|
16
|
+
|
|
17
|
+
namespace fs {
|
|
18
|
+
class FSReqBase;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
namespace permission {
|
|
22
|
+
|
|
23
|
+
#define THROW_IF_INSUFFICIENT_PERMISSIONS(env, perm, resource, ...) \
|
|
24
|
+
do { \
|
|
25
|
+
node::Environment* env__ = (env); \
|
|
26
|
+
const node::permission::PermissionScope perm__ = (perm); \
|
|
27
|
+
const auto resource__ = (resource); \
|
|
28
|
+
if (!env__->permission()->is_granted(env__, perm__, resource__)) \
|
|
29
|
+
[[unlikely]] { \
|
|
30
|
+
if (!env__->permission()->warning_only()) { \
|
|
31
|
+
node::permission::Permission::ThrowAccessDenied( \
|
|
32
|
+
env__, perm__, resource__); \
|
|
33
|
+
return __VA_ARGS__; \
|
|
34
|
+
} \
|
|
35
|
+
} \
|
|
36
|
+
} while (0)
|
|
37
|
+
|
|
38
|
+
#define ASYNC_THROW_IF_INSUFFICIENT_PERMISSIONS( \
|
|
39
|
+
env, wrap, perm, resource, ...) \
|
|
40
|
+
do { \
|
|
41
|
+
node::Environment* env__ = (env); \
|
|
42
|
+
const node::permission::PermissionScope perm__ = (perm); \
|
|
43
|
+
const auto resource__ = (resource); \
|
|
44
|
+
if (!env__->permission()->is_granted(env__, perm__, resource__)) \
|
|
45
|
+
[[unlikely]] { \
|
|
46
|
+
if (!env__->permission()->warning_only()) { \
|
|
47
|
+
node::permission::Permission::AsyncThrowAccessDenied( \
|
|
48
|
+
env__, (wrap), perm__, resource__); \
|
|
49
|
+
return __VA_ARGS__; \
|
|
50
|
+
} \
|
|
51
|
+
} \
|
|
52
|
+
} while (0)
|
|
53
|
+
|
|
54
|
+
#define ERR_ACCESS_DENIED_IF_INSUFFICIENT_PERMISSIONS( \
|
|
55
|
+
env, perm, resource, args, ...) \
|
|
56
|
+
do { \
|
|
57
|
+
node::Environment* env__ = (env); \
|
|
58
|
+
const node::permission::PermissionScope perm__ = (perm); \
|
|
59
|
+
const auto resource__ = (resource); \
|
|
60
|
+
if (!env__->permission()->is_granted(env__, perm__, resource__)) \
|
|
61
|
+
[[unlikely]] { \
|
|
62
|
+
if (!env__->permission()->warning_only()) { \
|
|
63
|
+
Local<Value> err_access; \
|
|
64
|
+
if (node::permission::CreateAccessDeniedError( \
|
|
65
|
+
env__, perm__, resource__) \
|
|
66
|
+
.ToLocal(&err_access)) { \
|
|
67
|
+
args.GetReturnValue().Set(err_access); \
|
|
68
|
+
} else { \
|
|
69
|
+
args.GetReturnValue().Set(UV_EACCES); \
|
|
70
|
+
} \
|
|
71
|
+
return __VA_ARGS__; \
|
|
72
|
+
} \
|
|
73
|
+
} \
|
|
74
|
+
} while (0)
|
|
75
|
+
|
|
76
|
+
#define SET_INSUFFICIENT_PERMISSION_ERROR_CALLBACK(scope) \
|
|
77
|
+
void InsufficientPermissionError(std::string_view resource) { \
|
|
78
|
+
v8::HandleScope handle_scope(env()->isolate()); \
|
|
79
|
+
v8::Context::Scope context_scope(env()->context()); \
|
|
80
|
+
v8::Local<v8::Value> arg; \
|
|
81
|
+
if (!permission::CreateAccessDeniedError(env(), (scope), resource) \
|
|
82
|
+
.ToLocal(&arg)) { \
|
|
83
|
+
} \
|
|
84
|
+
MakeCallback(env()->oncomplete_string(), 1, &arg); \
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class Permission {
|
|
88
|
+
public:
|
|
89
|
+
Permission();
|
|
90
|
+
|
|
91
|
+
FORCE_INLINE bool is_granted(Environment* env,
|
|
92
|
+
PermissionScope permission,
|
|
93
|
+
std::string_view res = "") const {
|
|
94
|
+
if (!enabled_) [[likely]] {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return is_scope_granted(env, permission, res);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
FORCE_INLINE bool enabled() const { return enabled_; }
|
|
101
|
+
|
|
102
|
+
FORCE_INLINE bool warning_only() const { return warning_only_; }
|
|
103
|
+
|
|
104
|
+
static PermissionScope StringToPermission(std::string_view perm);
|
|
105
|
+
static v8::Local<v8::String> PermissionToString(Environment* env,
|
|
106
|
+
PermissionScope perm);
|
|
107
|
+
static void ThrowAccessDenied(Environment* env,
|
|
108
|
+
PermissionScope perm,
|
|
109
|
+
std::string_view res);
|
|
110
|
+
static void AsyncThrowAccessDenied(Environment* env,
|
|
111
|
+
fs::FSReqBase* req_wrap,
|
|
112
|
+
PermissionScope perm,
|
|
113
|
+
std::string_view res);
|
|
114
|
+
|
|
115
|
+
// CLI Call
|
|
116
|
+
void Apply(Environment* env,
|
|
117
|
+
std::span<const std::string> allow,
|
|
118
|
+
PermissionScope scope);
|
|
119
|
+
// Runtime Call
|
|
120
|
+
void Drop(Environment* env, PermissionScope scope, std::string_view param);
|
|
121
|
+
void EnablePermissions();
|
|
122
|
+
void EnableWarningOnly();
|
|
123
|
+
|
|
124
|
+
private:
|
|
125
|
+
COLD_NOINLINE bool is_scope_granted(Environment* env,
|
|
126
|
+
PermissionScope permission,
|
|
127
|
+
std::string_view res = "") const;
|
|
128
|
+
|
|
129
|
+
BaseObjectPtr<diagnostics_channel::Channel> GetOrCreateChannel(
|
|
130
|
+
Environment* env, PermissionScope scope) const;
|
|
131
|
+
|
|
132
|
+
static constexpr size_t kPermissionCount =
|
|
133
|
+
static_cast<size_t>(PermissionScope::kPermissionsCount);
|
|
134
|
+
|
|
135
|
+
std::array<std::shared_ptr<PermissionBase>, kPermissionCount> nodes_;
|
|
136
|
+
bool enabled_;
|
|
137
|
+
bool warning_only_;
|
|
138
|
+
mutable bool publishing_ = false;
|
|
139
|
+
// Weak refs: BindingData (via BaseObjectPtr) is the sole owner of Channels.
|
|
140
|
+
// Using weak refs here avoids keeping Channels alive past Realm teardown.
|
|
141
|
+
mutable std::array<BaseObjectWeakPtr<diagnostics_channel::Channel>,
|
|
142
|
+
kPermissionCount>
|
|
143
|
+
channels_;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
v8::MaybeLocal<v8::Value> CreateAccessDeniedError(Environment* env,
|
|
147
|
+
PermissionScope perm,
|
|
148
|
+
std::string_view res);
|
|
149
|
+
|
|
150
|
+
} // namespace permission
|
|
151
|
+
|
|
152
|
+
} // namespace node
|
|
153
|
+
|
|
154
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
155
|
+
#endif // SRC_PERMISSION_PERMISSION_H_
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#ifndef SRC_PERMISSION_PERMISSION_BASE_H_
|
|
2
|
+
#define SRC_PERMISSION_PERMISSION_BASE_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <span>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <string_view>
|
|
9
|
+
|
|
10
|
+
namespace node {
|
|
11
|
+
|
|
12
|
+
class Environment;
|
|
13
|
+
|
|
14
|
+
namespace permission {
|
|
15
|
+
|
|
16
|
+
#define FILESYSTEM_PERMISSIONS(V) \
|
|
17
|
+
V(FileSystem, "fs", PermissionsRoot, "") \
|
|
18
|
+
V(FileSystemRead, "fs.read", FileSystem, "--allow-fs-read") \
|
|
19
|
+
V(FileSystemWrite, "fs.write", FileSystem, "--allow-fs-write")
|
|
20
|
+
|
|
21
|
+
#define CHILD_PROCESS_PERMISSIONS(V) \
|
|
22
|
+
V(ChildProcess, "child", PermissionsRoot, "--allow-child-process")
|
|
23
|
+
|
|
24
|
+
#define WASI_PERMISSIONS(V) V(WASI, "wasi", PermissionsRoot, "--allow-wasi")
|
|
25
|
+
|
|
26
|
+
#define WORKER_THREADS_PERMISSIONS(V) \
|
|
27
|
+
V(WorkerThreads, "worker", PermissionsRoot, "--allow-worker")
|
|
28
|
+
|
|
29
|
+
#define INSPECTOR_PERMISSIONS(V) \
|
|
30
|
+
V(Inspector, "inspector", PermissionsRoot, "--allow-inspector")
|
|
31
|
+
|
|
32
|
+
#define NET_PERMISSIONS(V) V(Net, "net", PermissionsRoot, "--allow-net")
|
|
33
|
+
|
|
34
|
+
#define ADDON_PERMISSIONS(V) \
|
|
35
|
+
V(Addon, "addon", PermissionsRoot, "--allow-addons")
|
|
36
|
+
|
|
37
|
+
#define FFI_PERMISSIONS(V) V(FFI, "ffi", PermissionsRoot, "--allow-ffi")
|
|
38
|
+
|
|
39
|
+
#define OPENSSL_STORE_PERMISSIONS(V) \
|
|
40
|
+
V(OpenSSLStore, "openssl.store", PermissionsRoot, "--allow-openssl-store")
|
|
41
|
+
|
|
42
|
+
#define PERMISSIONS(V) \
|
|
43
|
+
FILESYSTEM_PERMISSIONS(V) \
|
|
44
|
+
CHILD_PROCESS_PERMISSIONS(V) \
|
|
45
|
+
WASI_PERMISSIONS(V) \
|
|
46
|
+
WORKER_THREADS_PERMISSIONS(V) \
|
|
47
|
+
INSPECTOR_PERMISSIONS(V) \
|
|
48
|
+
NET_PERMISSIONS(V) \
|
|
49
|
+
ADDON_PERMISSIONS(V) \
|
|
50
|
+
FFI_PERMISSIONS(V) \
|
|
51
|
+
OPENSSL_STORE_PERMISSIONS(V)
|
|
52
|
+
|
|
53
|
+
#define V(name, _, __, ___) k##name,
|
|
54
|
+
enum class PermissionScope {
|
|
55
|
+
kPermissionsRoot = -1,
|
|
56
|
+
PERMISSIONS(V) kPermissionsCount
|
|
57
|
+
};
|
|
58
|
+
#undef V
|
|
59
|
+
|
|
60
|
+
class PermissionBase {
|
|
61
|
+
public:
|
|
62
|
+
virtual ~PermissionBase() = default;
|
|
63
|
+
virtual void Apply(Environment* env,
|
|
64
|
+
std::span<const std::string> allow,
|
|
65
|
+
PermissionScope scope) = 0;
|
|
66
|
+
virtual void Drop(Environment* env,
|
|
67
|
+
PermissionScope scope,
|
|
68
|
+
std::string_view param) = 0;
|
|
69
|
+
virtual bool is_granted(Environment* env,
|
|
70
|
+
PermissionScope perm,
|
|
71
|
+
std::string_view param) const = 0;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
} // namespace permission
|
|
75
|
+
|
|
76
|
+
} // namespace node
|
|
77
|
+
|
|
78
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
79
|
+
#endif // SRC_PERMISSION_PERMISSION_BASE_H_
|