Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Disallow TCP/UDP socket creation by default (#13936)

Alex Crichton55433cf52cf5
diff --git a/crates/wasi-tls/tests/p2/mod.rs b/crates/wasi-tls/tests/p2/mod.rs
index 0e046b988c..c5d5c3df00 100644
--- a/crates/wasi-tls/tests/p2/mod.rs
+++ b/crates/wasi-tls/tests/p2/mod.rs
@@ -40,6 +40,8 @@ async fn run_test(provider: Box<dyn TlsProvider>, path: &str) -> Result<()> {
.inherit_stderr()
.inherit_network()
.allow_ip_name_lookup(true)
+ .allow_tcp(true)
+ .allow_udp(true)
.build(),
wasi_tls_ctx: WasiTlsCtxBuilder::new().provider(provider).build(),
};
diff --git a/crates/wasi-tls/tests/p3/mod.rs b/crates/wasi-tls/tests/p3/mod.rs
index 5ad61830f8..6a2f392cda 100644
--- a/crates/wasi-tls/tests/p3/mod.rs
+++ b/crates/wasi-tls/tests/p3/mod.rs
@@ -38,6 +38,8 @@ async fn run_test(provider: Box<dyn TlsProvider>, path: &str) -> Result<()> {
.inherit_stderr()
.inherit_network()
.allow_ip_name_lookup(true)
+ .allow_tcp(true)
+ .allow_udp(true)
.build(),
wasi_tls_ctx: WasiTlsCtxBuilder::new().provider(provider).build(),
};
diff --git a/crates/wasi/src/sockets/mod.rs b/crates/wasi/src/sockets/mod.rs
index 2cb38271ee..5c082d53ce 100644
--- a/crates/wasi/src/sockets/mod.rs
+++ b/crates/wasi/src/sockets/mod.rs
@@ -81,23 +81,13 @@ pub trait WasiSocketsView: Send {
fn sockets(&mut self) -> WasiSocketsCtxView<'_>;
}
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, Default)]
pub(crate) struct AllowedNetworkUses {
pub(crate) ip_name_lookup: bool,
pub(crate) udp: bool,
pub(crate) tcp: bool,
}
-impl Default for AllowedNetworkUses {
- fn default() -> Self {
- Self {
- ip_name_lookup: false,
- udp: true,
- tcp: true,
- }
- }
-}
-
impl AllowedNetworkUses {
pub(crate) fn check_allowed_udp(&self) -> std::io::Result<()> {
if !self.udp {
diff --git a/crates/wasi/tests/all/store.rs b/crates/wasi/tests/all/store.rs
index 1114633417..f5bef3b1a3 100644
--- a/crates/wasi/tests/all/store.rs
+++ b/crates/wasi/tests/all/store.rs
@@ -48,6 +48,8 @@ impl<T> Ctx<T> {
builder
.args(&[name, "."])
.inherit_network()
+ .allow_tcp(true)
+ .allow_udp(true)
.allow_ip_name_lookup(true);
println!("preopen: {workspace:?}");
builder.preopened_dir(workspace.path(), ".", DirPerms::all(), FilePerms::all())?;
diff --git a/src/common.rs b/src/common.rs
index 07c74ca1aa..d1d81b8642 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -364,6 +364,9 @@ impl RunCommon {
if self.common.wasi.inherit_network == Some(true) {
builder.inherit_network();
+ // Implicitly enable TCP/UDP if the entire network is being
+ // inherited to avoid the need to also pass `-Stcp,udp`.
+ builder.allow_tcp(true).allow_udp(true);
}
if let Some(enable) = self.common.wasi.allow_ip_name_lookup {
builder.allow_ip_name_lookup(enable);
diff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rs
index ea54c4b3ee..95d08ca435 100644
--- a/tests/all/cli_tests.rs
+++ b/tests/all/cli_tests.rs
@@ -3008,7 +3008,7 @@ start a print 1234
#[test]
fn p3_cli_deny_listen() -> Result<()> {
- run_wasmtime(&["run", P3_CLI_DENY_LISTEN_COMPONENT])?;
+ run_wasmtime(&["run", "-Stcp", P3_CLI_DENY_LISTEN_COMPONENT])?;
Ok(())
}
}
diff --git a/tests/wasi.rs b/tests/wasi.rs
index 7af9ba29b7..957ab293fb 100644
--- a/tests/wasi.rs
+++ b/tests/wasi.rs
@@ -132,6 +132,7 @@ fn execute(path: &Path) -> Result<()> {
if path.iter().any(|p| p == "wasm32-wasip3") {
cmd.arg("-Sp3").arg("-Wcomponent-model-async");
}
+ cmd.arg("-Stcp,udp");
for proposal in proposals.as_deref().unwrap_or(&[]) {
match proposal {
WasiProposal::Sockets => {