11
11
#include " memory_tracker.h"
12
12
#include " node.h"
13
13
#include " node_internals.h"
14
+ #include " permission/permission.h"
14
15
#include " util.h"
15
16
16
17
#include " ares.h"
@@ -214,6 +215,8 @@ class GetNameInfoReqWrap final : public ReqWrap<uv_getnameinfo_t> {
214
215
public:
215
216
GetNameInfoReqWrap (Environment* env, v8::Local<v8::Object> req_wrap_obj);
216
217
218
+ SET_INSUFFICIENT_PERMISSION_ERROR_CALLBACK (permission::PermissionScope::kNet )
219
+
217
220
SET_NO_MEMORY_INFO ()
218
221
SET_MEMORY_INFO_NAME (GetNameInfoReqWrap)
219
222
SET_SELF_SIZE (GetNameInfoReqWrap)
@@ -249,6 +252,15 @@ class QueryWrap final : public AsyncWrap {
249
252
void AresQuery (const char * name,
250
253
ares_dns_class_t dnsclass,
251
254
ares_dns_rec_type_t type) {
255
+ permission::PermissionScope scope = permission::PermissionScope::kNet ;
256
+ Environment* env_holder = env ();
257
+
258
+ if (!env_holder->permission ()->is_granted (env_holder, scope, name))
259
+ [[unlikely]] {
260
+ QueuePermissionModelResponseCallback (name);
261
+ return ;
262
+ }
263
+
252
264
channel_->EnsureServers ();
253
265
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1 (
254
266
TRACING_CATEGORY_NODE2 (dns, native), trace_name_, this ,
@@ -262,6 +274,8 @@ class QueryWrap final : public AsyncWrap {
262
274
nullptr );
263
275
}
264
276
277
+ SET_INSUFFICIENT_PERMISSION_ERROR_CALLBACK (permission::PermissionScope::kNet )
278
+
265
279
void ParseError (int status) {
266
280
CHECK_NE (status, ARES_SUCCESS);
267
281
v8::HandleScope handle_scope (env ()->isolate ());
@@ -356,6 +370,20 @@ class QueryWrap final : public AsyncWrap {
356
370
wrap->QueueResponseCallback (status);
357
371
}
358
372
373
+ void QueuePermissionModelResponseCallback (const char * resource) {
374
+ BaseObjectPtr<QueryWrap<Traits>> strong_ref{this };
375
+ const std::string res{resource};
376
+ env ()->SetImmediate ([this , strong_ref, res](Environment*) {
377
+ InsufficientPermissionError (res);
378
+
379
+ // Delete once strong_ref goes out of scope.
380
+ Detach ();
381
+ });
382
+
383
+ channel_->set_query_last_ok (true );
384
+ channel_->ModifyActivityQueryCount (-1 );
385
+ }
386
+
359
387
void QueueResponseCallback (int status) {
360
388
BaseObjectPtr<QueryWrap<Traits>> strong_ref{this };
361
389
env ()->SetImmediate ([this , strong_ref](Environment*) {
0 commit comments