Skip to content

Commit b5cc1f5

Browse files
committed
feat: improved WASI sandboxing
Implements a restricted subset of the WASI ABI (wasi_snapshot_preview1) to support proxy-wasm modules that require base level WASI functionality. This implementation adds a ABI_WASI class to handle WASI-specific functions: - Supports core WASI functions required by proxy-wasm spec - Implements fd_write for stdout/stderr logging - Adds support for clock, random, environment, and args functions This should result in a better sandboxing of the guest modules.
1 parent 59b7566 commit b5cc1f5

File tree

4 files changed

+390
-64
lines changed

4 files changed

+390
-64
lines changed

proxy-wasm-java-host/src/main/java/io/roastedroot/proxywasm/PluginFactory.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.dylibso.chicory.runtime.ImportMemory;
66
import com.dylibso.chicory.runtime.Instance;
77
import com.dylibso.chicory.runtime.Machine;
8-
import com.dylibso.chicory.wasi.WasiOptions;
98
import com.dylibso.chicory.wasm.WasmModule;
109
import io.roastedroot.proxywasm.internal.ProxyWasm;
1110
import java.net.URI;
@@ -319,20 +318,6 @@ public PluginFactory.Builder withMachineFactory(
319318
return this;
320319
}
321320

322-
/**
323-
* Configures WebAssembly System Interface (WASI) options for the plugin instance.
324-
* WASI provides a standard interface for WASM modules to interact with the underlying operating system
325-
* for tasks like file system access, environment variables, etc. While Proxy-WASM defines its own ABI,
326-
* some modules might also utilize WASI features.
327-
*
328-
* @param options The {@link WasiOptions} to configure for the WASI environment.
329-
* @return this {@code Builder} instance for method chaining.
330-
*/
331-
public PluginFactory.Builder withWasiOptions(WasiOptions options) {
332-
proxyWasmBuilder.withWasiOptions(options);
333-
return this;
334-
}
335-
336321
/**
337322
* Configures whether the plugin instance should be shared across multiple host requests or contexts.
338323
*

proxy-wasm-java-host/src/main/java/io/roastedroot/proxywasm/internal/ABI.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.dylibso.chicory.annotations.HostModule;
99
import com.dylibso.chicory.annotations.WasmExport;
1010
import com.dylibso.chicory.runtime.ExportFunction;
11+
import com.dylibso.chicory.runtime.HostFunction;
1112
import com.dylibso.chicory.runtime.Instance;
1213
import com.dylibso.chicory.runtime.Memory;
1314
import com.dylibso.chicory.runtime.WasmRuntimeException;
@@ -1921,4 +1922,17 @@ void proxyOnForeignFunction(int contextId, int functionId, int argumentsSize) {
19211922
}
19221923
proxyOnForeignFunctionFn.apply(contextId, functionId, argumentsSize);
19231924
}
1925+
1926+
@WasmExport
1927+
void emscriptenNotifyMemoryGrowth(int size) {}
1928+
1929+
public HostFunction[] toHostFunctions() {
1930+
var functions = new ArrayList<>(List.of(ABI_ModuleFactory.toHostFunctions(this)));
1931+
1932+
HostFunction[] wasiFunctions = new ABI_WASI(handler).toHostFunctions();
1933+
functions.addAll(List.of(wasiFunctions));
1934+
functions.addAll(List.of(Helpers.withModuleName(wasiFunctions, "wasi_unstable")));
1935+
1936+
return functions.toArray(new HostFunction[0]);
1937+
}
19241938
}

0 commit comments

Comments
 (0)