Skip to content

feat(java): add a Java binding running bashkit as JVM bytecode - #3053

Open
andreaTP wants to merge 5 commits into
everruns:mainfrom
andreaTP:feat/java-binding
Open

andreaTP wants to merge 5 commits into
everruns:mainfrom
andreaTP:feat/java-binding

Conversation

@andreaTP

@andreaTP andreaTP commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What changed

A first bulk of changes for a Java binding, crates/bashkit-java:

  • Bashkit compiled to wasm32-wasip1 and translated to JVM bytecode by Endive: a pure Java 11+ jar, no native libraries.
  • A Java API that follows the Rust one: limits and profiles, HTTP grants and credentials, hooks, snapshots.
  • One change to bashkit itself: http_client builds on wasm in transport-only mode.
  • CI (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

  • Low: a new crate; the bashkit change only affects wasm builds, plus a local header check.

Checklist

  • Tests added or updated
  • Backward compatibility considered

Thank you for your time, any feedback is very welcome!


Show it working
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

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.
@andreaTP
andreaTP marked this pull request as ready for review December 4, 2026 17:11

@bashkit-pr-reviewer bashkit-pr-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java binding review: solid isolation shape (per-shell Wasm instance, ZeroFs root, NEVER redirects, per-hop grant check), but the HTTP egress path is weaker than native against DNS-rebinding SSRF. See inline findings.

public Response execute(Request request) throws IOException {
URI uri = URI.create(request.url());
if (!request.privateIpsAllowed()) {
for (InetAddress address : InetAddress.getAllByName(uri.getHost())) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Comment thread crates/bashkit-java/src/lib.rs Outdated
}
// Grants are checked by the transport, on the final URL of every hop.
builder = builder
.network(NetworkAllowlist::allow_all().block_private_ips(false))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@bashkit-pr-reviewer

bashkit-pr-reviewer Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Review summary (head fb17fef)

Verdict: close — the push resolves 3 of 4 prior findings (guest now uses http.allowlist() instead of allow_all, isPrivate is range-for-range with a NetworkTest.privateIpsMatchBashkit table, proxy/redirect/timeout handling is locked down, and knowledge/runtimes/java-package.md + knowledge/security/http-transport.md + threat-model TM-NET-033/036/TM-DOS-159 document the boundary). One P2 remains: pinned_addrs is still dropped at the bashkit_java.http wire (host.rs), so the host cannot close the documented TM-NET-036 rebind window.

Findings: 1x new P2 (java-pinned-addrs-dropped). Prior keys java-ssrf-dns-toctou / java-allowall-delegates-policy / java-wire-private-ip-coverage / java-knowledge-threat-model-stale not re-posted (tool dedupes; first three are addressed or documented, the last is resolved by the new knowledge pages).

Context read: refreshed checkout at fb17fef, JdkHttpTransport.java:37-223, host.rs, policy.rs:277-310, transport.rs:22-73 SHOULD contract, threat-model.md TM entries, NetworkTest.java:247-268, lib.rs:102. Diff is ~5.2k lines and API-truncated, so review focused on the sandbox boundary; no build/test run per sandbox rules.

- 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.

@bashkit-pr-reviewer bashkit-pr-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review of the new push: good progress — knowledge pages, TM-NET-036/033 docs, range-for-range isPrivate, NO_PROXY/NEVER redirects, and guest allowlist() instead of allow_all address most of the last round. One remaining gap below.

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant