File tree 4 files changed +35
-6
lines changed
4 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ pub trait NodePermissions {
87
87
path : & str ,
88
88
api_name : Option < & str > ,
89
89
) -> Result < PathBuf , PermissionCheckError > ;
90
+ fn grant_net ( & mut self , host : & str , port : Option < u16 > ) ;
90
91
}
91
92
92
93
impl NodePermissions for deno_permissions:: PermissionsContainer {
@@ -147,6 +148,11 @@ impl NodePermissions for deno_permissions::PermissionsContainer {
147
148
) -> Result < ( ) , PermissionCheckError > {
148
149
deno_permissions:: PermissionsContainer :: check_sys ( self , kind, api_name)
149
150
}
151
+
152
+ fn grant_net ( & mut self , host : & str , port : Option < u16 > ) {
153
+ // ignore the result when host parsing fails
154
+ _ = deno_permissions:: PermissionsContainer :: grant_net ( self , host, port) ;
155
+ }
150
156
}
151
157
152
158
#[ allow( clippy:: disallowed_types) ]
Original file line number Diff line number Diff line change 44
44
let permissions = state_. borrow_mut :: < P > ( ) ;
45
45
permissions. check_net ( ( hostname. as_str ( ) , None ) , "lookup" ) ?;
46
46
}
47
+
47
48
let mut resolver = GaiResolver :: new ( ) ;
48
49
let name = Name :: from_str ( & hostname)
49
50
. map_err ( |_| GetAddrInfoError :: Resolution ( hostname. clone ( ) ) ) ?;
@@ -52,14 +53,19 @@ where
52
53
. await
53
54
. map_err ( |_| GetAddrInfoError :: Resolution ( hostname) )
54
55
. map ( |addrs| {
56
+ let mut state_ = state. borrow_mut ( ) ;
57
+ let permissions = state_. borrow_mut :: < P > ( ) ;
55
58
addrs
56
59
. into_iter ( )
57
- . map ( |addr| GetAddrInfoResult {
58
- family : match addr {
59
- std:: net:: SocketAddr :: V4 ( _) => 4 ,
60
- std:: net:: SocketAddr :: V6 ( _) => 6 ,
61
- } ,
62
- address : addr. ip ( ) . to_string ( ) ,
60
+ . map ( |addr| {
61
+ permissions. grant_net ( & addr. ip ( ) . to_string ( ) , None ) ;
62
+ GetAddrInfoResult {
63
+ family : match addr {
64
+ std:: net:: SocketAddr :: V4 ( _) => 4 ,
65
+ std:: net:: SocketAddr :: V6 ( _) => 6 ,
66
+ } ,
67
+ address : addr. ip ( ) . to_string ( ) ,
68
+ }
63
69
} )
64
70
. collect :: < Vec < _ > > ( )
65
71
} )
Original file line number Diff line number Diff line change @@ -3344,6 +3344,20 @@ impl PermissionsContainer {
3344
3344
) ,
3345
3345
)
3346
3346
}
3347
+
3348
+ pub fn grant_net (
3349
+ & self ,
3350
+ host : & str ,
3351
+ port : Option < u16 > ,
3352
+ ) -> Result < bool , NetDescriptorParseError > {
3353
+ Ok (
3354
+ self
3355
+ . inner
3356
+ . lock ( )
3357
+ . net
3358
+ . insert_granted ( Some ( & NetDescriptor ( Host :: parse ( host) ?, port) ) ) ,
3359
+ )
3360
+ }
3347
3361
}
3348
3362
3349
3363
const fn unit_permission_from_flag_bools (
Original file line number Diff line number Diff line change @@ -121,6 +121,9 @@ impl deno_node::NodePermissions for Permissions {
121
121
) -> Result < ( ) , PermissionCheckError > {
122
122
unreachable ! ( "snapshotting!" )
123
123
}
124
+ fn grant_net ( & mut self , _host : & str , _port : Option < u16 > ) {
125
+ unreachable ! ( "snapshotting!" )
126
+ }
124
127
}
125
128
126
129
impl deno_net:: NetPermissions for Permissions {
You can’t perform that action at this time.
0 commit comments