-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
permission,dns: add permission for dns
- Loading branch information
Showing
13 changed files
with
199 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "net_dns_permission.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace node { | ||
|
||
namespace permission { | ||
|
||
void NetDNSPermission::Apply(Environment* env, | ||
const std::vector<std::string>& allow, | ||
PermissionScope scope) { | ||
deny_all_ = true; | ||
} | ||
|
||
bool NetDNSPermission::is_granted(Environment* env, | ||
PermissionScope perm, | ||
const std::string_view& param) const { | ||
return deny_all_ == false; | ||
} | ||
|
||
} // namespace permission | ||
} // namespace node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef SRC_PERMISSION_NET_DNS_PERMISSION_H_ | ||
#define SRC_PERMISSION_NET_DNS_PERMISSION_H_ | ||
|
||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
|
||
#include <vector> | ||
#include "permission/permission_base.h" | ||
|
||
|
||
namespace node { | ||
|
||
namespace permission { | ||
|
||
class NetDNSPermission final : public PermissionBase { | ||
public: | ||
void Apply(Environment* env, | ||
const std::vector<std::string>& allow, | ||
PermissionScope scope) override; | ||
bool is_granted(Environment* env, | ||
PermissionScope perm, | ||
const std::string_view& param = "") const override; | ||
|
||
private: | ||
bool deny_all_; | ||
}; | ||
|
||
} // namespace permission | ||
|
||
} // namespace node | ||
|
||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
#endif // SRC_PERMISSION_NET_DNS_PERMISSION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Flags: --experimental-permission --allow-fs-read=* | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const dns = require('dns'); | ||
const common = require('../common'); | ||
|
||
{ | ||
const functions = [ | ||
() => dns.lookup('example.com', () => {}), | ||
() => dns.lookupService('127.0.0.1', 22, () => {}), | ||
() => dns.reverse('8.8.8.8', () => {}), | ||
() => dns.resolveAny('example.com', () => {}), | ||
() => dns.resolve4('example.com', () => {}), | ||
() => dns.resolve6('example.com', () => {}), | ||
() => dns.resolveCaa('example.com', () => {}), | ||
() => dns.resolveCname('example.com', () => {}), | ||
() => dns.resolveMx('example.com', () => {}), | ||
() => dns.resolveNs('example.com', () => {}), | ||
() => dns.resolveTxt('example.com', () => {}), | ||
() => dns.resolveSrv('example.com', () => {}), | ||
() => dns.resolvePtr('example.com', () => {}), | ||
() => dns.resolveNaptr('example.com', () => {}), | ||
() => dns.resolveSoa('example.com', () => {}), | ||
]; | ||
for (let i = 0; i < functions.length; i++) { | ||
assert.throws(functions[i], /Error: Access to this API has been restricted/); | ||
} | ||
} | ||
|
||
{ | ||
const resolvers = new dns.Resolver(); | ||
const functions = [ | ||
() => resolvers.reverse('8.8.8.8', () => {}), | ||
() => resolvers.resolveAny('example.com', () => {}), | ||
() => resolvers.resolve4('example.com', () => {}), | ||
() => resolvers.resolve6('example.com', () => {}), | ||
() => resolvers.resolveCaa('example.com', () => {}), | ||
() => resolvers.resolveCname('example.com', () => {}), | ||
() => resolvers.resolveMx('example.com', () => {}), | ||
() => resolvers.resolveNs('example.com', () => {}), | ||
() => resolvers.resolveTxt('example.com', () => {}), | ||
() => resolvers.resolveSrv('example.com', () => {}), | ||
() => resolvers.resolvePtr('example.com', () => {}), | ||
() => resolvers.resolveNaptr('example.com', () => {}), | ||
() => resolvers.resolveSoa('example.com', () => {}), | ||
]; | ||
for (let i = 0; i < functions.length; i++) { | ||
assert.throws(functions[i], /Error: Access to this API has been restricted/); | ||
} | ||
} | ||
|
||
{ | ||
const functions = [ | ||
() => dns.promises.lookup('example.com'), | ||
() => dns.promises.lookupService('127.0.0.1', 22), | ||
() => dns.promises.reverse('8.8.8.8'), | ||
() => dns.promises.resolveAny('example.com'), | ||
() => dns.promises.resolve4('example.com'), | ||
() => dns.promises.resolve6('example.com'), | ||
() => dns.promises.resolveCaa('example.com'), | ||
() => dns.promises.resolveCname('example.com'), | ||
() => dns.promises.resolveMx('example.com'), | ||
() => dns.promises.resolveNs('example.com'), | ||
() => dns.promises.resolveTxt('example.com'), | ||
() => dns.promises.resolveSrv('example.com'), | ||
() => dns.promises.resolvePtr('example.com'), | ||
() => dns.promises.resolveNaptr('example.com'), | ||
() => dns.promises.resolveSoa('example.com'), | ||
]; | ||
for (let i = 0; i < functions.length; i++) { | ||
assert.rejects(functions[i], /Error: Access to this API has been restricted/).then(common.mustCall()); | ||
} | ||
} |