@encharm/cws 4.3.0 → 4.4.1

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.
Files changed (238) hide show
  1. package/README.md +5 -7
  2. package/dist/bindings/cws_darwin_arm64_node108.node +0 -0
  3. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  4. package/dist/bindings/cws_darwin_arm64_node83.node +0 -0
  5. package/dist/bindings/cws_darwin_arm64_node93.node +0 -0
  6. package/dist/bindings/cws_darwin_x64_node108.node +0 -0
  7. package/dist/bindings/cws_darwin_x64_node115.node +0 -0
  8. package/dist/bindings/cws_darwin_x64_node83.node +0 -0
  9. package/dist/bindings/cws_darwin_x64_node93.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node108.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  12. package/dist/bindings/cws_linux_arm64_node83.node +0 -0
  13. package/dist/bindings/cws_linux_arm64_node93.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node108.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  16. package/dist/bindings/cws_linux_x64_node83.node +0 -0
  17. package/dist/bindings/cws_linux_x64_node93.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node108.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  20. package/dist/bindings/cws_win32_x64_node83.node +0 -0
  21. package/dist/bindings/cws_win32_x64_node93.node +0 -0
  22. package/dist/shared.js +1 -1
  23. package/package.json +5 -5
  24. package/src/Addon.cpp +4 -12
  25. package/src/Addon.h +67 -91
  26. package/src/Socket.h +1 -0
  27. package/src/cSNode.cpp +3 -8
  28. package/src/headers/20/acorn_version.h +6 -0
  29. package/src/headers/20/aliased_buffer-inl.h +243 -0
  30. package/src/headers/20/aliased_buffer.h +206 -0
  31. package/src/headers/20/aliased_struct-inl.h +54 -0
  32. package/src/headers/20/aliased_struct.h +63 -0
  33. package/src/headers/20/async_wrap-inl.h +93 -0
  34. package/src/headers/20/async_wrap.h +252 -0
  35. package/src/headers/20/base64-inl.h +193 -0
  36. package/src/headers/20/base64.h +53 -0
  37. package/src/headers/20/base64_version.h +6 -0
  38. package/src/headers/20/base_object-inl.h +316 -0
  39. package/src/headers/20/base_object.h +320 -0
  40. package/src/headers/20/base_object_types.h +73 -0
  41. package/src/headers/20/blob_serializer_deserializer-inl.h +361 -0
  42. package/src/headers/20/blob_serializer_deserializer.h +132 -0
  43. package/src/headers/20/callback_queue-inl.h +97 -0
  44. package/src/headers/20/callback_queue.h +79 -0
  45. package/src/headers/20/cares_wrap.h +524 -0
  46. package/src/headers/20/cjs_module_lexer_version.h +6 -0
  47. package/src/headers/20/cleanup_queue-inl.h +62 -0
  48. package/src/headers/20/cleanup_queue.h +85 -0
  49. package/src/headers/20/connect_wrap.h +26 -0
  50. package/src/headers/20/connection_wrap.h +30 -0
  51. package/src/headers/20/cppgc/DEPS +8 -0
  52. package/src/headers/20/cppgc/OWNERS +2 -0
  53. package/src/headers/20/cppgc/README.md +135 -0
  54. package/src/headers/20/cppgc/allocation.h +310 -0
  55. package/src/headers/20/cppgc/common.h +28 -0
  56. package/src/headers/20/cppgc/cross-thread-persistent.h +466 -0
  57. package/src/headers/20/cppgc/custom-space.h +97 -0
  58. package/src/headers/20/cppgc/default-platform.h +67 -0
  59. package/src/headers/20/cppgc/ephemeron-pair.h +30 -0
  60. package/src/headers/20/cppgc/explicit-management.h +100 -0
  61. package/src/headers/20/cppgc/garbage-collected.h +106 -0
  62. package/src/headers/20/cppgc/heap-consistency.h +309 -0
  63. package/src/headers/20/cppgc/heap-handle.h +48 -0
  64. package/src/headers/20/cppgc/heap-state.h +82 -0
  65. package/src/headers/20/cppgc/heap-statistics.h +120 -0
  66. package/src/headers/20/cppgc/heap.h +202 -0
  67. package/src/headers/20/cppgc/internal/api-constants.h +68 -0
  68. package/src/headers/20/cppgc/internal/atomic-entry-flag.h +48 -0
  69. package/src/headers/20/cppgc/internal/base-page-handle.h +45 -0
  70. package/src/headers/20/cppgc/internal/caged-heap-local-data.h +111 -0
  71. package/src/headers/20/cppgc/internal/caged-heap.h +61 -0
  72. package/src/headers/20/cppgc/internal/compiler-specific.h +38 -0
  73. package/src/headers/20/cppgc/internal/finalizer-trait.h +93 -0
  74. package/src/headers/20/cppgc/internal/gc-info.h +157 -0
  75. package/src/headers/20/cppgc/internal/logging.h +50 -0
  76. package/src/headers/20/cppgc/internal/member-storage.h +248 -0
  77. package/src/headers/20/cppgc/internal/name-trait.h +137 -0
  78. package/src/headers/20/cppgc/internal/persistent-node.h +214 -0
  79. package/src/headers/20/cppgc/internal/pointer-policies.h +243 -0
  80. package/src/headers/20/cppgc/internal/write-barrier.h +487 -0
  81. package/src/headers/20/cppgc/liveness-broker.h +78 -0
  82. package/src/headers/20/cppgc/macros.h +35 -0
  83. package/src/headers/20/cppgc/member.h +604 -0
  84. package/src/headers/20/cppgc/name-provider.h +65 -0
  85. package/src/headers/20/cppgc/object-size-trait.h +58 -0
  86. package/src/headers/20/cppgc/persistent.h +373 -0
  87. package/src/headers/20/cppgc/platform.h +158 -0
  88. package/src/headers/20/cppgc/prefinalizer.h +75 -0
  89. package/src/headers/20/cppgc/process-heap-statistics.h +36 -0
  90. package/src/headers/20/cppgc/sentinel-pointer.h +32 -0
  91. package/src/headers/20/cppgc/source-location.h +92 -0
  92. package/src/headers/20/cppgc/testing.h +106 -0
  93. package/src/headers/20/cppgc/trace-trait.h +120 -0
  94. package/src/headers/20/cppgc/type-traits.h +250 -0
  95. package/src/headers/20/cppgc/visitor.h +426 -0
  96. package/src/headers/20/crypto/crypto_clienthello.h +131 -0
  97. package/src/headers/20/crypto/crypto_context.h +160 -0
  98. package/src/headers/20/crypto/crypto_keys.h +419 -0
  99. package/src/headers/20/crypto/crypto_tls.h +304 -0
  100. package/src/headers/20/crypto/crypto_util.h +806 -0
  101. package/src/headers/20/crypto_clienthello.h +131 -0
  102. package/src/headers/20/debug_utils-inl.h +226 -0
  103. package/src/headers/20/debug_utils.h +188 -0
  104. package/src/headers/20/diagnosticfilename-inl.h +33 -0
  105. package/src/headers/20/encoding_binding.h +59 -0
  106. package/src/headers/20/env-inl.h +923 -0
  107. package/src/headers/20/env.h +1193 -0
  108. package/src/headers/20/env_properties.h +446 -0
  109. package/src/headers/20/handle_wrap.h +123 -0
  110. package/src/headers/20/histogram-inl.h +107 -0
  111. package/src/headers/20/histogram.h +240 -0
  112. package/src/headers/20/inspector_agent.h +144 -0
  113. package/src/headers/20/inspector_io.h +78 -0
  114. package/src/headers/20/inspector_profiler.h +149 -0
  115. package/src/headers/20/inspector_socket.h +60 -0
  116. package/src/headers/20/inspector_socket_server.h +110 -0
  117. package/src/headers/20/js_native_api.h +601 -0
  118. package/src/headers/20/js_native_api_types.h +168 -0
  119. package/src/headers/20/js_native_api_v8.h +463 -0
  120. package/src/headers/20/js_native_api_v8_internals.h +45 -0
  121. package/src/headers/20/js_stream.h +52 -0
  122. package/src/headers/20/json_parser.h +38 -0
  123. package/src/headers/20/json_utils.h +172 -0
  124. package/src/headers/20/memory_tracker-inl.h +356 -0
  125. package/src/headers/20/memory_tracker.h +289 -0
  126. package/src/headers/20/module_wrap.h +117 -0
  127. package/src/headers/20/node.h +1516 -0
  128. package/src/headers/20/node_api.h +261 -0
  129. package/src/headers/20/node_api_internals.h +42 -0
  130. package/src/headers/20/node_api_types.h +52 -0
  131. package/src/headers/20/node_binding.h +142 -0
  132. package/src/headers/20/node_blob.h +159 -0
  133. package/src/headers/20/node_bob-inl.h +36 -0
  134. package/src/headers/20/node_bob.h +107 -0
  135. package/src/headers/20/node_buffer.h +92 -0
  136. package/src/headers/20/node_builtins.h +197 -0
  137. package/src/headers/20/node_constants.h +82 -0
  138. package/src/headers/20/node_context_data.h +98 -0
  139. package/src/headers/20/node_contextify.h +206 -0
  140. package/src/headers/20/node_crypto.h +56 -0
  141. package/src/headers/20/node_dir.h +52 -0
  142. package/src/headers/20/node_dotenv.h +37 -0
  143. package/src/headers/20/node_errors.h +313 -0
  144. package/src/headers/20/node_exit_code.h +54 -0
  145. package/src/headers/20/node_external_reference.h +172 -0
  146. package/src/headers/20/node_file-inl.h +389 -0
  147. package/src/headers/20/node_file.h +537 -0
  148. package/src/headers/20/node_http2.h +1146 -0
  149. package/src/headers/20/node_http2_state.h +147 -0
  150. package/src/headers/20/node_http_common-inl.h +201 -0
  151. package/src/headers/20/node_http_common.h +532 -0
  152. package/src/headers/20/node_i18n.h +145 -0
  153. package/src/headers/20/node_internals.h +443 -0
  154. package/src/headers/20/node_main_instance.h +67 -0
  155. package/src/headers/20/node_mem-inl.h +112 -0
  156. package/src/headers/20/node_mem.h +45 -0
  157. package/src/headers/20/node_messaging.h +377 -0
  158. package/src/headers/20/node_metadata.h +138 -0
  159. package/src/headers/20/node_mutex.h +323 -0
  160. package/src/headers/20/node_object_wrap.h +132 -0
  161. package/src/headers/20/node_options-inl.h +478 -0
  162. package/src/headers/20/node_options.h +538 -0
  163. package/src/headers/20/node_perf.h +166 -0
  164. package/src/headers/20/node_perf_common.h +98 -0
  165. package/src/headers/20/node_platform.h +195 -0
  166. package/src/headers/20/node_process-inl.h +26 -0
  167. package/src/headers/20/node_process.h +99 -0
  168. package/src/headers/20/node_realm-inl.h +139 -0
  169. package/src/headers/20/node_realm.h +184 -0
  170. package/src/headers/20/node_report.h +42 -0
  171. package/src/headers/20/node_revert.h +82 -0
  172. package/src/headers/20/node_root_certs.h +3443 -0
  173. package/src/headers/20/node_sea.h +56 -0
  174. package/src/headers/20/node_shadow_realm.h +46 -0
  175. package/src/headers/20/node_snapshot_builder.h +54 -0
  176. package/src/headers/20/node_snapshotable.h +164 -0
  177. package/src/headers/20/node_sockaddr-inl.h +266 -0
  178. package/src/headers/20/node_sockaddr.h +405 -0
  179. package/src/headers/20/node_stat_watcher.h +73 -0
  180. package/src/headers/20/node_threadsafe_cow-inl.h +54 -0
  181. package/src/headers/20/node_threadsafe_cow.h +105 -0
  182. package/src/headers/20/node_union_bytes.h +81 -0
  183. package/src/headers/20/node_url.h +92 -0
  184. package/src/headers/20/node_v8.h +77 -0
  185. package/src/headers/20/node_v8_platform-inl.h +205 -0
  186. package/src/headers/20/node_version.h +109 -0
  187. package/src/headers/20/node_wasi.h +184 -0
  188. package/src/headers/20/node_wasm_web_api.h +55 -0
  189. package/src/headers/20/node_watchdog.h +154 -0
  190. package/src/headers/20/node_worker.h +151 -0
  191. package/src/headers/20/permission/child_process_permission.h +29 -0
  192. package/src/headers/20/permission/fs_permission.h +154 -0
  193. package/src/headers/20/permission/inspector_permission.h +29 -0
  194. package/src/headers/20/permission/permission.h +74 -0
  195. package/src/headers/20/permission/permission_base.h +53 -0
  196. package/src/headers/20/permission/worker_permission.h +29 -0
  197. package/src/headers/20/pipe_wrap.h +80 -0
  198. package/src/headers/20/req_wrap-inl.h +171 -0
  199. package/src/headers/20/req_wrap.h +77 -0
  200. package/src/headers/20/spawn_sync.h +242 -0
  201. package/src/headers/20/stream_base-inl.h +173 -0
  202. package/src/headers/20/stream_base.h +469 -0
  203. package/src/headers/20/stream_pipe.h +76 -0
  204. package/src/headers/20/stream_wrap.h +131 -0
  205. package/src/headers/20/string_bytes.h +120 -0
  206. package/src/headers/20/string_decoder-inl.h +37 -0
  207. package/src/headers/20/string_decoder.h +50 -0
  208. package/src/headers/20/string_search.h +638 -0
  209. package/src/headers/20/tcp_wrap.h +105 -0
  210. package/src/headers/20/threadpoolwork-inl.h +70 -0
  211. package/src/headers/20/timer_wrap-inl.h +32 -0
  212. package/src/headers/20/timer_wrap.h +85 -0
  213. package/src/headers/20/timers.h +70 -0
  214. package/src/headers/20/tracing/agent.h +195 -0
  215. package/src/headers/20/tracing/node_trace_buffer.h +83 -0
  216. package/src/headers/20/tracing/node_trace_writer.h +75 -0
  217. package/src/headers/20/tracing/trace_event.h +720 -0
  218. package/src/headers/20/tracing/trace_event_common.h +1109 -0
  219. package/src/headers/20/tracing/traced_value.h +70 -0
  220. package/src/headers/20/tty_wrap.h +65 -0
  221. package/src/headers/20/udp_wrap.h +227 -0
  222. package/src/headers/20/undici_version.h +6 -0
  223. package/src/headers/20/util-inl.h +623 -0
  224. package/src/headers/20/util.h +988 -0
  225. package/src/headers/20/v8-cppgc.h +245 -0
  226. package/src/headers/20/v8-fast-api-calls.h +957 -0
  227. package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
  228. package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
  229. package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
  230. package/dist/bindings/cws_darwin_x64_node64.node +0 -0
  231. package/dist/bindings/cws_darwin_x64_node72.node +0 -0
  232. package/dist/bindings/cws_darwin_x64_node79.node +0 -0
  233. package/dist/bindings/cws_linux_x64_node64.node +0 -0
  234. package/dist/bindings/cws_linux_x64_node72.node +0 -0
  235. package/dist/bindings/cws_linux_x64_node79.node +0 -0
  236. package/dist/bindings/cws_win32_x64_node64.node +0 -0
  237. package/dist/bindings/cws_win32_x64_node72.node +0 -0
  238. package/dist/bindings/cws_win32_x64_node79.node +0 -0
@@ -0,0 +1,154 @@
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 "v8.h"
7
+
8
+ #include <unordered_map>
9
+ #include "permission/permission_base.h"
10
+ #include "util.h"
11
+
12
+ namespace node {
13
+
14
+ namespace permission {
15
+
16
+ class FSPermission final : public PermissionBase {
17
+ public:
18
+ void Apply(const std::vector<std::string>& allow,
19
+ PermissionScope scope) override;
20
+ bool is_granted(PermissionScope perm, const std::string_view& param) override;
21
+
22
+ struct RadixTree {
23
+ struct Node {
24
+ std::string prefix;
25
+ std::unordered_map<char, Node*> children;
26
+ Node* wildcard_child;
27
+ bool is_leaf;
28
+
29
+ explicit Node(const std::string& pre)
30
+ : prefix(pre), wildcard_child(nullptr), is_leaf(false) {}
31
+
32
+ Node() : wildcard_child(nullptr), is_leaf(false) {}
33
+
34
+ Node* CreateChild(std::string prefix) {
35
+ if (prefix.empty() && !is_leaf) {
36
+ is_leaf = true;
37
+ return this;
38
+ }
39
+ char label = prefix[0];
40
+
41
+ Node* child = children[label];
42
+ if (child == nullptr) {
43
+ children[label] = new Node(prefix);
44
+ return children[label];
45
+ }
46
+
47
+ // swap prefix
48
+ unsigned int i = 0;
49
+ unsigned int prefix_len = prefix.length();
50
+ for (; i < child->prefix.length(); ++i) {
51
+ if (i > prefix_len || prefix[i] != child->prefix[i]) {
52
+ std::string parent_prefix = child->prefix.substr(0, i);
53
+ std::string child_prefix = child->prefix.substr(i);
54
+
55
+ child->prefix = child_prefix;
56
+ Node* split_child = new Node(parent_prefix);
57
+ split_child->children[child_prefix[0]] = child;
58
+ children[parent_prefix[0]] = split_child;
59
+
60
+ return split_child->CreateChild(prefix.substr(i));
61
+ }
62
+ }
63
+ child->is_leaf = true;
64
+ return child->CreateChild(prefix.substr(i));
65
+ }
66
+
67
+ Node* CreateWildcardChild() {
68
+ if (wildcard_child != nullptr) {
69
+ return wildcard_child;
70
+ }
71
+ wildcard_child = new Node();
72
+ return wildcard_child;
73
+ }
74
+
75
+ Node* NextNode(const std::string& path, unsigned int idx) {
76
+ if (idx >= path.length()) {
77
+ return nullptr;
78
+ }
79
+
80
+ auto it = children.find(path[idx]);
81
+ if (it == children.end()) {
82
+ return nullptr;
83
+ }
84
+ auto child = it->second;
85
+ // match prefix
86
+ unsigned int prefix_len = child->prefix.length();
87
+ for (unsigned int i = 0; i < path.length(); ++i) {
88
+ if (i >= prefix_len || child->prefix[i] == '*') {
89
+ return child;
90
+ }
91
+
92
+ // Handle optional trailing
93
+ // path = /home/subdirectory
94
+ // child = subdirectory/*
95
+ if (idx >= path.length() &&
96
+ child->prefix[i] == node::kPathSeparator) {
97
+ continue;
98
+ }
99
+
100
+ if (path[idx++] != child->prefix[i]) {
101
+ return nullptr;
102
+ }
103
+ }
104
+ return child;
105
+ }
106
+
107
+ // A node can be a *end* node and have children
108
+ // E.g: */slower*, */slown* are inserted:
109
+ // /slow
110
+ // ---> er
111
+ // ---> n
112
+ // If */slow* is inserted right after, it will create an
113
+ // empty node
114
+ // /slow
115
+ // ---> '\000' ASCII (0) || \0
116
+ // ---> er
117
+ // ---> n
118
+ bool IsEndNode() {
119
+ if (children.size() == 0) {
120
+ return true;
121
+ }
122
+ return is_leaf;
123
+ }
124
+ };
125
+
126
+ RadixTree();
127
+ ~RadixTree();
128
+ void Insert(const std::string& s);
129
+ bool Lookup(const std::string_view& s) { return Lookup(s, false); }
130
+ bool Lookup(const std::string_view& s, bool when_empty_return);
131
+
132
+ private:
133
+ Node* root_node_;
134
+ };
135
+
136
+ private:
137
+ void GrantAccess(PermissionScope scope, const std::string& param);
138
+ // fs granted on startup
139
+ RadixTree granted_in_fs_;
140
+ RadixTree granted_out_fs_;
141
+
142
+ bool deny_all_in_ = true;
143
+ bool deny_all_out_ = true;
144
+
145
+ bool allow_all_in_ = false;
146
+ bool allow_all_out_ = false;
147
+ };
148
+
149
+ } // namespace permission
150
+
151
+ } // namespace node
152
+
153
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
154
+ #endif // SRC_PERMISSION_FS_PERMISSION_H_
@@ -0,0 +1,29 @@
1
+ #ifndef SRC_PERMISSION_INSPECTOR_PERMISSION_H_
2
+ #define SRC_PERMISSION_INSPECTOR_PERMISSION_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <string>
7
+ #include "permission/permission_base.h"
8
+
9
+ namespace node {
10
+
11
+ namespace permission {
12
+
13
+ class InspectorPermission final : public PermissionBase {
14
+ public:
15
+ void Apply(const std::vector<std::string>& allow,
16
+ PermissionScope scope) override;
17
+ bool is_granted(PermissionScope perm,
18
+ const std::string_view& param = "") override;
19
+
20
+ private:
21
+ bool deny_all_;
22
+ };
23
+
24
+ } // namespace permission
25
+
26
+ } // namespace node
27
+
28
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
29
+ #endif // SRC_PERMISSION_INSPECTOR_PERMISSION_H_
@@ -0,0 +1,74 @@
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_options.h"
8
+ #include "permission/child_process_permission.h"
9
+ #include "permission/fs_permission.h"
10
+ #include "permission/inspector_permission.h"
11
+ #include "permission/permission_base.h"
12
+ #include "permission/worker_permission.h"
13
+ #include "v8.h"
14
+
15
+ #include <string_view>
16
+ #include <unordered_map>
17
+
18
+ namespace node {
19
+
20
+ class Environment;
21
+
22
+ namespace permission {
23
+
24
+ #define THROW_IF_INSUFFICIENT_PERMISSIONS(env, perm_, resource_, ...) \
25
+ do { \
26
+ if (UNLIKELY(!(env)->permission()->is_granted(perm_, resource_))) { \
27
+ node::permission::Permission::ThrowAccessDenied( \
28
+ (env), perm_, resource_); \
29
+ return __VA_ARGS__; \
30
+ } \
31
+ } while (0)
32
+
33
+ class Permission {
34
+ public:
35
+ Permission();
36
+
37
+ FORCE_INLINE bool is_granted(const PermissionScope permission,
38
+ const std::string_view& res = "") const {
39
+ if (LIKELY(!enabled_)) return true;
40
+ return is_scope_granted(permission, res);
41
+ }
42
+
43
+ FORCE_INLINE bool enabled() const { return enabled_; }
44
+
45
+ static PermissionScope StringToPermission(const std::string& perm);
46
+ static const char* PermissionToString(PermissionScope perm);
47
+ static void ThrowAccessDenied(Environment* env,
48
+ PermissionScope perm,
49
+ const std::string_view& res);
50
+
51
+ // CLI Call
52
+ void Apply(const std::vector<std::string>& allow, PermissionScope scope);
53
+ void EnablePermissions();
54
+
55
+ private:
56
+ COLD_NOINLINE bool is_scope_granted(const PermissionScope permission,
57
+ const std::string_view& res = "") const {
58
+ auto perm_node = nodes_.find(permission);
59
+ if (perm_node != nodes_.end()) {
60
+ return perm_node->second->is_granted(permission, res);
61
+ }
62
+ return false;
63
+ }
64
+
65
+ std::unordered_map<PermissionScope, std::shared_ptr<PermissionBase>> nodes_;
66
+ bool enabled_;
67
+ };
68
+
69
+ } // namespace permission
70
+
71
+ } // namespace node
72
+
73
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
74
+ #endif // SRC_PERMISSION_PERMISSION_H_
@@ -0,0 +1,53 @@
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 <map>
7
+ #include <string>
8
+ #include <string_view>
9
+ #include "v8.h"
10
+
11
+ namespace node {
12
+
13
+ namespace permission {
14
+
15
+ #define FILESYSTEM_PERMISSIONS(V) \
16
+ V(FileSystem, "fs", PermissionsRoot) \
17
+ V(FileSystemRead, "fs.read", FileSystem) \
18
+ V(FileSystemWrite, "fs.write", FileSystem)
19
+
20
+ #define CHILD_PROCESS_PERMISSIONS(V) V(ChildProcess, "child", PermissionsRoot)
21
+
22
+ #define WORKER_THREADS_PERMISSIONS(V) \
23
+ V(WorkerThreads, "worker", PermissionsRoot)
24
+
25
+ #define INSPECTOR_PERMISSIONS(V) V(Inspector, "inspector", PermissionsRoot)
26
+
27
+ #define PERMISSIONS(V) \
28
+ FILESYSTEM_PERMISSIONS(V) \
29
+ CHILD_PROCESS_PERMISSIONS(V) \
30
+ WORKER_THREADS_PERMISSIONS(V) \
31
+ INSPECTOR_PERMISSIONS(V)
32
+
33
+ #define V(name, _, __) k##name,
34
+ enum class PermissionScope {
35
+ kPermissionsRoot = -1,
36
+ PERMISSIONS(V) kPermissionsCount
37
+ };
38
+ #undef V
39
+
40
+ class PermissionBase {
41
+ public:
42
+ virtual void Apply(const std::vector<std::string>& allow,
43
+ PermissionScope scope) = 0;
44
+ virtual bool is_granted(PermissionScope perm,
45
+ const std::string_view& param = "") = 0;
46
+ };
47
+
48
+ } // namespace permission
49
+
50
+ } // namespace node
51
+
52
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
53
+ #endif // SRC_PERMISSION_PERMISSION_BASE_H_
@@ -0,0 +1,29 @@
1
+ #ifndef SRC_PERMISSION_WORKER_PERMISSION_H_
2
+ #define SRC_PERMISSION_WORKER_PERMISSION_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <vector>
7
+ #include "permission/permission_base.h"
8
+
9
+ namespace node {
10
+
11
+ namespace permission {
12
+
13
+ class WorkerPermission final : public PermissionBase {
14
+ public:
15
+ void Apply(const std::vector<std::string>& allow,
16
+ PermissionScope scope) override;
17
+ bool is_granted(PermissionScope perm,
18
+ const std::string_view& param = "") override;
19
+
20
+ private:
21
+ bool deny_all_;
22
+ };
23
+
24
+ } // namespace permission
25
+
26
+ } // namespace node
27
+
28
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
29
+ #endif // SRC_PERMISSION_WORKER_PERMISSION_H_
@@ -0,0 +1,80 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ #ifndef SRC_PIPE_WRAP_H_
23
+ #define SRC_PIPE_WRAP_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include "async_wrap.h"
28
+ #include "connection_wrap.h"
29
+
30
+ namespace node {
31
+
32
+ class ExternalReferenceRegistry;
33
+ class Environment;
34
+
35
+ class PipeWrap : public ConnectionWrap<PipeWrap, uv_pipe_t> {
36
+ public:
37
+ enum SocketType {
38
+ SOCKET,
39
+ SERVER,
40
+ IPC
41
+ };
42
+
43
+ static v8::MaybeLocal<v8::Object> Instantiate(Environment* env,
44
+ AsyncWrap* parent,
45
+ SocketType type);
46
+ static void Initialize(v8::Local<v8::Object> target,
47
+ v8::Local<v8::Value> unused,
48
+ v8::Local<v8::Context> context,
49
+ void* priv);
50
+
51
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
52
+ SET_NO_MEMORY_INFO()
53
+ SET_MEMORY_INFO_NAME(PipeWrap)
54
+ SET_SELF_SIZE(PipeWrap)
55
+
56
+ private:
57
+ PipeWrap(Environment* env,
58
+ v8::Local<v8::Object> object,
59
+ ProviderType provider,
60
+ bool ipc);
61
+
62
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
63
+ static void Bind(const v8::FunctionCallbackInfo<v8::Value>& args);
64
+ static void Listen(const v8::FunctionCallbackInfo<v8::Value>& args);
65
+ static void Connect(const v8::FunctionCallbackInfo<v8::Value>& args);
66
+ static void Open(const v8::FunctionCallbackInfo<v8::Value>& args);
67
+
68
+ #ifdef _WIN32
69
+ static void SetPendingInstances(
70
+ const v8::FunctionCallbackInfo<v8::Value>& args);
71
+ #endif
72
+ static void Fchmod(const v8::FunctionCallbackInfo<v8::Value>& args);
73
+ };
74
+
75
+
76
+ } // namespace node
77
+
78
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
79
+
80
+ #endif // SRC_PIPE_WRAP_H_
@@ -0,0 +1,171 @@
1
+ #ifndef SRC_REQ_WRAP_INL_H_
2
+ #define SRC_REQ_WRAP_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "req_wrap.h"
7
+ #include "async_wrap-inl.h"
8
+ #include "uv.h"
9
+
10
+ namespace node {
11
+
12
+ ReqWrapBase::ReqWrapBase(Environment* env) {
13
+ CHECK(env->has_run_bootstrapping_code());
14
+ env->req_wrap_queue()->PushBack(this);
15
+ }
16
+
17
+ template <typename T>
18
+ ReqWrap<T>::ReqWrap(Environment* env,
19
+ v8::Local<v8::Object> object,
20
+ AsyncWrap::ProviderType provider)
21
+ : AsyncWrap(env, object, provider),
22
+ ReqWrapBase(env) {
23
+ MakeWeak();
24
+ Reset();
25
+ }
26
+
27
+ template <typename T>
28
+ ReqWrap<T>::~ReqWrap() {}
29
+
30
+ template <typename T>
31
+ void ReqWrap<T>::Dispatched() {
32
+ req_.data = this;
33
+ }
34
+
35
+ template <typename T>
36
+ void ReqWrap<T>::Reset() {
37
+ original_callback_ = nullptr;
38
+ req_.data = nullptr;
39
+ }
40
+
41
+ template <typename T>
42
+ ReqWrap<T>* ReqWrap<T>::from_req(T* req) {
43
+ return ContainerOf(&ReqWrap<T>::req_, req);
44
+ }
45
+
46
+ template <typename T>
47
+ void ReqWrap<T>::Cancel() {
48
+ if (req_.data == this) // Only cancel if already dispatched.
49
+ uv_cancel(reinterpret_cast<uv_req_t*>(&req_));
50
+ }
51
+
52
+ template <typename T>
53
+ AsyncWrap* ReqWrap<T>::GetAsyncWrap() {
54
+ return this;
55
+ }
56
+
57
+ // Below is dark template magic designed to invoke libuv functions that
58
+ // initialize uv_req_t instances in a unified fashion, to allow easier
59
+ // tracking of active/inactive requests.
60
+
61
+ // Invoke a generic libuv function that initializes uv_req_t instances.
62
+ // This is, unfortunately, necessary since they come in three different
63
+ // variants that can not all be invoked in the same way:
64
+ // - int uv_foo(uv_loop_t* loop, uv_req_t* request, ...);
65
+ // - int uv_foo(uv_req_t* request, ...);
66
+ // - void uv_foo(uv_req_t* request, ...);
67
+ template <typename ReqT, typename T>
68
+ struct CallLibuvFunction;
69
+
70
+ // Detect `int uv_foo(uv_loop_t* loop, uv_req_t* request, ...);`.
71
+ template <typename ReqT, typename... Args>
72
+ struct CallLibuvFunction<ReqT, int(*)(uv_loop_t*, ReqT*, Args...)> {
73
+ using T = int(*)(uv_loop_t*, ReqT*, Args...);
74
+ template <typename... PassedArgs>
75
+ static int Call(T fn, uv_loop_t* loop, ReqT* req, PassedArgs... args) {
76
+ return fn(loop, req, args...);
77
+ }
78
+ };
79
+
80
+ // Detect `int uv_foo(uv_req_t* request, ...);`.
81
+ template <typename ReqT, typename... Args>
82
+ struct CallLibuvFunction<ReqT, int(*)(ReqT*, Args...)> {
83
+ using T = int(*)(ReqT*, Args...);
84
+ template <typename... PassedArgs>
85
+ static int Call(T fn, uv_loop_t* loop, ReqT* req, PassedArgs... args) {
86
+ return fn(req, args...);
87
+ }
88
+ };
89
+
90
+ // Detect `void uv_foo(uv_req_t* request, ...);`.
91
+ template <typename ReqT, typename... Args>
92
+ struct CallLibuvFunction<ReqT, void(*)(ReqT*, Args...)> {
93
+ using T = void(*)(ReqT*, Args...);
94
+ template <typename... PassedArgs>
95
+ static int Call(T fn, uv_loop_t* loop, ReqT* req, PassedArgs... args) {
96
+ fn(req, args...);
97
+ return 0;
98
+ }
99
+ };
100
+
101
+ // This is slightly darker magic: This template is 'applied' to each parameter
102
+ // passed to the libuv function. If the parameter type (aka `T`) is a
103
+ // function type, it is assumed that this it is the request callback, and a
104
+ // wrapper that calls the original callback is created.
105
+ // If not, the parameter is passed through verbatim.
106
+ template <typename ReqT, typename T>
107
+ struct MakeLibuvRequestCallback {
108
+ static T For(ReqWrap<ReqT>* req_wrap, T v) {
109
+ static_assert(!is_callable<T>::value,
110
+ "MakeLibuvRequestCallback missed a callback");
111
+ return v;
112
+ }
113
+ };
114
+
115
+ // Match the `void callback(uv_req_t*, ...);` signature that all libuv
116
+ // callbacks use.
117
+ template <typename ReqT, typename... Args>
118
+ struct MakeLibuvRequestCallback<ReqT, void(*)(ReqT*, Args...)> {
119
+ using F = void(*)(ReqT* req, Args... args);
120
+
121
+ static void Wrapper(ReqT* req, Args... args) {
122
+ BaseObjectPtr<ReqWrap<ReqT>> req_wrap{ReqWrap<ReqT>::from_req(req)};
123
+ req_wrap->Detach();
124
+ req_wrap->env()->DecreaseWaitingRequestCounter();
125
+ F original_callback = reinterpret_cast<F>(req_wrap->original_callback_);
126
+ original_callback(req, args...);
127
+ }
128
+
129
+ static F For(ReqWrap<ReqT>* req_wrap, F v) {
130
+ CHECK_NULL(req_wrap->original_callback_);
131
+ req_wrap->original_callback_ =
132
+ reinterpret_cast<typename ReqWrap<ReqT>::callback_t>(v);
133
+ return Wrapper;
134
+ }
135
+ };
136
+
137
+ template <typename T>
138
+ template <typename LibuvFunction, typename... Args>
139
+ int ReqWrap<T>::Dispatch(LibuvFunction fn, Args... args) {
140
+ Dispatched();
141
+ // This expands as:
142
+ //
143
+ // int err = fn(env()->event_loop(), req(), arg1, arg2, Wrapper, arg3, ...)
144
+ // ^ ^ ^
145
+ // | | |
146
+ // \-- Omitted if `fn` has no | |
147
+ // first `uv_loop_t*` argument | |
148
+ // | |
149
+ // A function callback whose first argument | |
150
+ // matches the libuv request type is replaced ---/ |
151
+ // by the `Wrapper` method defined above |
152
+ // |
153
+ // Other (non-function) arguments are passed -----/
154
+ // through verbatim
155
+ int err = CallLibuvFunction<T, LibuvFunction>::Call(
156
+ fn,
157
+ env()->event_loop(),
158
+ req(),
159
+ MakeLibuvRequestCallback<T, Args>::For(this, args)...);
160
+ if (err >= 0) {
161
+ ClearWeak();
162
+ env()->IncreaseWaitingRequestCounter();
163
+ }
164
+ return err;
165
+ }
166
+
167
+ } // namespace node
168
+
169
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
170
+
171
+ #endif // SRC_REQ_WRAP_INL_H_
@@ -0,0 +1,77 @@
1
+ #ifndef SRC_REQ_WRAP_H_
2
+ #define SRC_REQ_WRAP_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "async_wrap.h"
7
+ #include "util.h"
8
+ #include "v8.h"
9
+
10
+ namespace node {
11
+
12
+ class Environment;
13
+
14
+ class ReqWrapBase {
15
+ public:
16
+ explicit inline ReqWrapBase(Environment* env);
17
+
18
+ virtual ~ReqWrapBase() = default;
19
+
20
+ virtual void Cancel() = 0;
21
+ virtual AsyncWrap* GetAsyncWrap() = 0;
22
+
23
+ private:
24
+ friend int GenDebugSymbols();
25
+ friend class Environment;
26
+
27
+ ListNode<ReqWrapBase> req_wrap_queue_;
28
+ };
29
+
30
+ template <typename T>
31
+ class ReqWrap : public AsyncWrap, public ReqWrapBase {
32
+ public:
33
+ inline ReqWrap(Environment* env,
34
+ v8::Local<v8::Object> object,
35
+ AsyncWrap::ProviderType provider);
36
+ inline ~ReqWrap() override;
37
+ // Call this after the req has been dispatched, if that did not already
38
+ // happen by using Dispatch().
39
+ inline void Dispatched();
40
+ // Call this after a request has finished, if re-using this object is planned.
41
+ inline void Reset();
42
+ T* req() { return &req_; }
43
+ inline void Cancel() final;
44
+ inline AsyncWrap* GetAsyncWrap() override;
45
+
46
+ static ReqWrap* from_req(T* req);
47
+
48
+ template <typename LibuvFunction, typename... Args>
49
+ inline int Dispatch(LibuvFunction fn, Args... args);
50
+
51
+ private:
52
+ friend int GenDebugSymbols();
53
+
54
+ // Adding `friend struct MakeLibuvRequestCallback` is not enough anymore
55
+ // for some reason. Consider this private.
56
+ public:
57
+ typedef void (*callback_t)();
58
+ callback_t original_callback_ = nullptr;
59
+
60
+ protected:
61
+ // req_wrap_queue_ needs to be at a fixed offset from the start of the class
62
+ // because it is used by ContainerOf to calculate the address of the embedding
63
+ // ReqWrap. ContainerOf compiles down to simple, fixed pointer arithmetic. It
64
+ // is also used by src/node_postmortem_metadata.cc to calculate offsets and
65
+ // generate debug symbols for ReqWrap, which assumes that the position of
66
+ // members in memory are predictable. sizeof(req_) depends on the type of T,
67
+ // so req_wrap_queue_ would no longer be at a fixed offset if it came after
68
+ // req_. For more information please refer to
69
+ // `doc/contributing/node-postmortem-support.md`
70
+ T req_;
71
+ };
72
+
73
+ } // namespace node
74
+
75
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
76
+
77
+ #endif // SRC_REQ_WRAP_H_