Skip to content
Prev Previous commit
Next Next commit
net: add missing dtls permission check
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Claude/Opus
  • Loading branch information
jasnell committed Jul 7, 2026
commit 2c39e2aec103a4ea4a78903ca5d1f9c24264591b
3 changes: 3 additions & 0 deletions src/dtls/dtls_endpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ void DTLSEndpoint::DoBind(const FunctionCallbackInfo<Value>& args) {
return THROW_ERR_INVALID_ARG_VALUE(env, "Invalid address");
}

THROW_IF_INSUFFICIENT_PERMISSIONS(
env, permission::PermissionScope::kNet, addr.ToString());

int err = endpoint->Bind(addr);
if (err != 0) {
return THROW_ERR_INVALID_STATE(env, uv_strerror(err));
Expand Down
11 changes: 9 additions & 2 deletions test/parallel/test-permission-net-dtls.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ const ca = readFileSync(join(fixturesDir, 'ca1-cert.pem')).toString();
);
}

// Test: Creating a DTLSEndpoint without connect/listen is allowed
// since no network I/O occurs at construction time.
// Test: Creating a DTLSEndpoint is allowed (no network I/O at construction
// time), but bind() requires net permission.
{
const endpoint = new DTLSEndpoint();
assert.ok(endpoint);
assert.throws(
() => endpoint.bind('127.0.0.1', 0),
{
code: 'ERR_ACCESS_DENIED',
permission: 'Net',
},
);
}