Repository navigation
Conversation
wasm has no sockets, so reqwest and rustls cannot be used there and the `http_client` feature did not build for wasm. Make reqwest and rustls native-only dependencies and run HttpClient on wasm in transport-only mode: the URL allowlist, before_http/after_http hooks, credential injection, bot-auth signing and the response size cap all still run, and the request is handed to the host's HttpTransport (BashBuilder::http_transport). Without one, a request fails with a clear error instead of failing to compile. - Header syntax is checked by a local function, which a test pins to reqwest's rules, so the same check runs on every target. - The DNS private-IP precheck has no resolver on wasm and takes the existing fail-open path (no pinned addresses); host transports own SSRF filtering there, as the HttpTransport contract already requires. - The transport deadline uses time_compat::timeout, since tokio's timer panics on wasm32-unknown-unknown. - The crypto backend compile_error only applies where rustls is built. - Export is_private_ip so custom transports can apply the same classifier the built-in transport uses. - CI's wasm checks now build http_client for wasm32-unknown-unknown and wasm32-wasip2.
crates/bashkit-java runs bashkit on the JVM without native libraries: a wasm32-wasip1 reactor that Endive translates to JVM bytecode at build time, and a Maven project (com.everruns:bashkit, Java 11+) around it. - The guest imports two host functions, `http` and `hook`, and takes the whole policy once at init. Every dependency is WASI-only, so the crate is empty in host builds. - The shell's `/` is a WASI directory backed by any java.nio Path, in-memory ZeroFs by default, so Java and scripts share files. - Nothing outside the shell is reachable unless granted: HTTP grants by URL, access level and private addresses are checked in the guest's HttpTransport on the final URL of every hop, then Java sends the request. Credentials name secrets resolved at build time. - Limits, profiles, commands narrowing, python/typescript/git on demand, all eight hook points, and snapshots. SSH, SQLite, fetchkit/markkit, CPython and publishing are not included.
java.yml builds the wasm32-wasip1 guest once (with clippy), then runs the Maven build and tests on Java 11 and 25 (25 also runs spotless and checkstyle), behind a `Java Check` gate. Path filters match the Python and JS workflows. Dependabot covers the Maven project.
1a80178 to
495d3d7
Compare
| public Response execute(Request request) throws IOException { | ||
| URI uri = URI.create(request.url()); | ||
| if (!request.privateIpsAllowed()) { | ||
| for (InetAddress address : InetAddress.getAllByName(uri.getHost())) { |
There was a problem hiding this comment.
[P1] DNS check-then-use race: InetAddress.getAllByName(uri.getHost()) rejects private IPs, but the HttpClient below re-resolves at connect time. Unlike crates/bashkit/src/network/allowlist.rs + PrivateIpFilteringResolver (refuses private IPs at dial time, see client.rs docs TM-NET-002/TM-NET-014), an attacker controlling DNS (TTL 0 / rebinding, redirect target) can pass this check and still dial a private IP. Also pinned_addrs from HttpTransportRequest (client.rs:746-754) is never encoded in host.rs/HostCalls.java, so the Rust-side pinning defense is dropped. Fix: pin the validated InetAddress[] for the actual connection, or fail closed and document the gap in knowledge/security/threat-model.md.
| } | ||
| // Grants are checked by the transport, on the final URL of every hop. | ||
| builder = builder | ||
| .network(NetworkAllowlist::allow_all().block_private_ips(false)) |
There was a problem hiding this comment.
[P1] NetworkAllowlist::allow_all().block_private_ips(false) disables the Rust-side allowlist/SSRF precheck and delegates everything to host::JavaHttp per-hop. That is only safe if every hop (initial + each curl/wget redirect re-execute) goes through policy::Http::check and the Java private-IP check above holds. Given the TOCTOU above, the Java path is strictly weaker than the native reqwest path. At minimum, forward pinned_addrs/enforce per-hop checks and note the weaker guarantee; preferably keep a restrictive allowlist in the guest too.
| Some(Host::Ipv6(ip)) => Some(ip.into()), | ||
| _ => None, | ||
| }; | ||
| if let Some(ip) = ip.filter(|ip| !private && bashkit::is_private_ip(ip)) { |
There was a problem hiding this comment.
[P2] Guest-side Http::check only filters literal-IP hosts (Host::Ipv4/Ipv6 + bashkit::is_private_ip); DNS names fall through to the Java isPrivate check. JdkHttpTransport.isPrivate approximates allowlist.rs::is_private_ip via isLoopback/isLinkLocal/isSiteLocal/isMulticast plus a few explicit ranges, but the explicit lists differ (e.g. docs ranges 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24, 255.255.255.255/32, ::ffff:0:0/96 handling). Worth a conformance test comparing both predicates over the ranges in allowlist.rs:26-40, or delegate to a single shared predicate.
| @@ -0,0 +1,221 @@ | |||
| //! Bashkit as a WASI reactor for the Java binding: one shell per instance, with | |||
There was a problem hiding this comment.
[P2] New trust boundary (WASI reactor + bashkit_java.http/hook host imports, ZeroFs-backed /, JDK HTTP egress) with no knowledge/ update in the diff. Per AGENTS.md the knowledge index must be updated in the same change; knowledge/security/threat-model.md (TM-NET-002/008/011/014, VFS escapes) should record the Java transport's TOCTOU/pinning limits, credential flow (builder.credential -> transport headers visible to custom HttpTransport/beforeHttp), and Endive/WASI FS guarantees.
Review summary (head
|
- Give Bashkit an allowlist built from the grants, so its own checks run before and after hooks, as they do natively. It has no wildcards, so a `*` or `*.domain` grant makes it allow all; private IPs stay blocked unless a grant allows them. As in Bashkit, a hook can no longer turn a URL no grant covers into one that is granted. - Port `is_private_ip` to the JDK transport range for range. One table of boundary addresses now runs through both checks. - Ignore JVM proxy settings in the JDK transport. The JDK still resolves the host again to connect, and java.net.http has no resolver hook to pin it; that window is recorded as TM-NET-036.
Add TM-NET-036 (the JDK transport's rebind window), TM-NET-037 (Java host code sees injected credentials), TM-DOS-159 (no quotas on the default root yet) and TM-FS-019 (a caller-supplied root), and extend TM-NET-033 to the JVM's proxy settings. Describe the guest's allowlist on the Java page, and drop the notes saying `http_client` can't build on wasm.
| w.u64(request.timeout.as_millis() as u64); | ||
| w.u64(request.connect_timeout.map_or(0, |t| t.as_millis() as u64)); | ||
| w.u64(request.max_response_bytes as u64); | ||
| w.bool(private); |
There was a problem hiding this comment.
[P2] pinned_addrs still dropped at the WASI boundary: HttpTransportRequest.pinned_addrs (resolve-then-check IPs from the guest precheck, transport.rs:56-67) is never encoded in host.rs (Writer sends method/url/headers/body/timeouts/max/private only), so HostCalls/JdkHttpTransport cannot honor the transport.rs SHOULD (connect to a pinned address or re-resolve + filter). Combined with the documented TM-NET-036 re-resolution window in JdkHttpTransport.java:38, the host has no way to close the rebind TOCTOU even though the guest resolved good addresses. Fix: extend the bashkit_java.http wire with the pinned list and prefer it (or fail closed when empty on a grant that blocks private IPs).
What changed
A first bulk of changes for a Java binding,
crates/bashkit-java:wasm32-wasip1and translated to JVM bytecode by Endive: a pure Java 11+ jar, no native libraries.bashkititself:http_clientbuilds on wasm in transport-only mode.java.yml), a README, a knowledge page and threat-model entries.Why
Following the WebAssembly approach we discussed. Context is in tersePrompts/bashkit4j#5, where we're still waiting for an answer, so there's no rush here.
Status
Follow-ups for separate PRs: filesystem quotas (TM-DOS-159) and credentials scoped by method.
Risk
bashkitchange only affects wasm builds, plus a local header check.Checklist
Thank you for your time, any feedback is very welcome!
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.