sproutboat 0.51.0 → 0.51.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,25 @@ maintained going forward by the `release` skill.
10
10
 
11
11
  ## Unreleased
12
12
 
13
+ ## [0.51.1] - 2026-11-05
14
+
15
+ Built on `@sproutboat/runtime` 0.42.2, `@sproutboat/toolchain` 0.23.1 and `@sproutboat/wire` 0.22.2. Nothing an app can observe changes except latency, the refused address ranges below and the `startTls()` write order, so there is no new compatibility date.
16
+
17
+ ### Fixed
18
+
19
+ - **Bytes written right after `socket.startTls()` no longer go out unencrypted.** On a `connect()` socket, the I/O thread took the start-TLS request and the app's queued writes in the same pass, and flushed all of them in plaintext before switching to TLS. Any write queued before the thread picked up the upgrade could leave in the clear. Only the bytes written before `startTls()` now go out in plaintext. Everything after waits until the TLS engine owns the socket, and new writes on the old plaintext socket reject, as in workerd. A failed plaintext flush is now a connection error. The egress tunnel also no longer stays paused on the discarded plain socket after an upgrade under backpressure.
20
+
21
+ - The BearSSL source ships in the package (`vendor/bearssl`, 867 KB) and is read first, hash-verified, so builds no longer depend on bearssl.org being up. bearssl.org stays as the fallback, with bounded retry on 5xx. Every source, vendored or downloaded, is checked against the pinned sha256, so a bad file cannot change what gets built.
22
+ - **A malformed `connect()` tunnel opening frame no longer ends the egress process.** A `tcp.open` head whose JSON did not parse used to throw out of the egress service's socket handler before the token was checked, which took egress down for every app. It now gets an `expected tcp.open` error frame and only that connection closes; the broker answers it as a bad request, and a refused head stops buffering whatever the client keeps sending.
23
+
24
+ ### Changed
25
+
26
+ - **`fetch()` and `connect()` refuse more reserved address space** that carries no public service: AS112 and the old IPv4 anycast blocks (`192.31.196.0/24`, `192.52.193.0/24`, `192.88.99.0/24`, `192.175.48.0/24`), SIIT (`::ffff:0:0:0/96`), IETF protocol assignments including Teredo (`2001::/23`), `3fff::/20` and SRv6 (`5f00::/16`). This applies to the broker, the egress service and a standalone binary alike, and `SB_EGRESS_ALLOW` still overrides it.
27
+
28
+ ### Performance
29
+
30
+ - **Outbound TCP sockets set `TCP_NODELAY`.** Nagle's algorithm and the peer's delayed ACK stalled every fresh HTTPS `fetch()` by about 44 ms on Linux, because each small TLS handshake flight waited for an ACK; a fresh fetch now takes about 1.4 ms. This covers `fetch()`, outbound WebSockets and `connect()` on a standalone binary, including sockets handed over by `SB_EGRESS_FD`, and the egress tunnel's connections to origins.
31
+
13
32
  ## [0.51.0] - 2026-11-03
14
33
 
15
34
  Built on `@sproutboat/runtime` 0.42.0, `@sproutboat/toolchain` 0.23.0 and `@sproutboat/wire` 0.22.0. The change below starts at a new compatibility date; earlier dates answer as before.
package/SURFACE.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > Generated by `src/surface.test.ts` from `src/surface.ts` + the pinned
4
4
  > toolchain constants. Do not edit by hand — run `UPDATE_SURFACE=1 bun test`.
5
5
 
6
- **Package:** `sproutboat` 0.51.0
6
+ **Package:** `sproutboat` 0.51.1
7
7
 
8
8
  ## Commands
9
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sproutboat",
3
- "version": "0.51.0",
3
+ "version": "0.51.1",
4
4
  "description": "Wrangler-shaped CLI for Sproutboat. Deploys workers to any control plane via --api-url / SPROUTBOAT_API_URL.",
5
5
  "keywords": [
6
6
  "cli",
@@ -64,9 +64,9 @@
64
64
  "@sproutboat/artifact": "^0.3.0",
65
65
  "@sproutboat/assets": "^0.3.0",
66
66
  "@sproutboat/config": "^0.6.0",
67
- "@sproutboat/runtime": "^0.42.0",
68
- "@sproutboat/toolchain": "^0.23.0",
69
- "@sproutboat/wire": "^0.22.0"
67
+ "@sproutboat/runtime": "^0.42.2",
68
+ "@sproutboat/toolchain": "^0.23.1",
69
+ "@sproutboat/wire": "^0.22.2"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@oxlint/plugins": "1.85.0",
@@ -78,10 +78,10 @@
78
78
  "typescript": "7.0.2"
79
79
  },
80
80
  "optionalDependencies": {
81
- "@sproutboat/cli-darwin-arm64": "0.51.0",
82
- "@sproutboat/cli-darwin-x64": "0.51.0",
83
- "@sproutboat/cli-linux-arm64": "0.51.0",
84
- "@sproutboat/cli-linux-x64": "0.51.0"
81
+ "@sproutboat/cli-darwin-arm64": "0.51.1",
82
+ "@sproutboat/cli-darwin-x64": "0.51.1",
83
+ "@sproutboat/cli-linux-arm64": "0.51.1",
84
+ "@sproutboat/cli-linux-x64": "0.51.1"
85
85
  },
86
86
  "engines": {
87
87
  "node": ">=18"
package/src/bearssl.ts CHANGED
@@ -19,6 +19,9 @@ import { existsSync } from "node:fs";
19
19
  import { mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
20
20
  import { homedir } from "node:os";
21
21
  import { resolve } from "node:path";
22
+ // @ts-expect-error Bun's file loader returns the embedded asset path in a compiled executable.
23
+ import embeddedBearsslArchive from "../vendor/bearssl/bearssl-7bea48e.tar.gz" with { type: "file" };
24
+ import { fetchPinned, type FetchPinnedOptions } from "./fetch-pinned";
22
25
  import { LINUX_TARGETS, type BuildTarget } from "./targets";
23
26
  import { resolveHostCompiler } from "./toolchain";
24
27
 
@@ -112,12 +115,22 @@ const run = (
112
115
  child.on("close", (code) => done({ code: code ?? 1, stderr }));
113
116
  });
114
117
 
118
+ /**
119
+ * The pinned BearSSL source: the vendored copy (ships in the npm package, embedded in standalone
120
+ * binaries) first, bearssl.org only as a fallback. bearssl.org returned 502 for hours on 2026-11-04.
121
+ */
122
+ export const bearsslVendorArchive = (): string => embeddedBearsslArchive;
123
+
124
+ export const fetchBearsslTarball = (overrides: Partial<FetchPinnedOptions> = {}): Promise<Buffer> =>
125
+ fetchPinned({
126
+ localPath: bearsslVendorArchive(),
127
+ urls: [BEARSSL_URL],
128
+ sha256: BEARSSL_SHA256,
129
+ ...overrides,
130
+ });
131
+
115
132
  async function download(url: string, expected: string, to: string): Promise<Buffer> {
116
- const response = await fetch(url);
117
- if (!response.ok) throw new Error(`could not download ${url}: HTTP ${response.status}`);
118
- const bytes = Buffer.from(await response.arrayBuffer());
119
- const digest = createHash("sha256").update(bytes).digest("hex");
120
- if (digest !== expected) throw new Error(`checksum mismatch for ${url}: expected ${expected}, got ${digest}`);
133
+ const bytes = await fetchPinned({ urls: [url], sha256: expected });
121
134
  await writeFile(to, bytes);
122
135
  return bytes;
123
136
  }
@@ -143,7 +156,7 @@ async function sourceTree(): Promise<string> {
143
156
  await rm(tree, { recursive: true, force: true });
144
157
  if (!existsSync(tarball) || (await digest(tarball)) !== BEARSSL_SHA256) {
145
158
  await rm(tarball, { force: true });
146
- await download(BEARSSL_URL, BEARSSL_SHA256, tarball);
159
+ await writeFile(tarball, await fetchBearsslTarball());
147
160
  }
148
161
  const stage = resolve(dir, `.bearssl-stage-${process.pid}-${crypto.randomUUID()}`);
149
162
  await mkdir(stage, { recursive: true });
@@ -0,0 +1,80 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync } from "node:fs";
3
+ import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
4
+ import { dirname } from "node:path";
5
+
6
+ type Fetcher = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
7
+
8
+ export type FetchPinnedOptions = {
9
+ /** A vendored copy read from disk before any network source. Used only if its hash matches. */
10
+ localPath?: string;
11
+ /** Ordered download sources, tried after the vendored copy. Every one must serve the same bytes. */
12
+ urls: readonly string[];
13
+ /** Lowercase hex sha256 of the exact bytes. A source that serves anything else is rejected. */
14
+ sha256: string;
15
+ /** A verified copy is kept here (written atomically) and reused while its hash matches. */
16
+ cachePath?: string;
17
+ fetcher?: Fetcher;
18
+ /** Attempts per source for a 5xx or a network error. 4xx and a hash mismatch are never retried. */
19
+ attempts?: number;
20
+ /** First backoff; doubles each retry. */
21
+ backoffMs?: number;
22
+ timeoutMs?: number;
23
+ sleep?: (ms: number) => Promise<void>;
24
+ };
25
+
26
+ const sha256Hex = (bytes: Uint8Array): string => createHash("sha256").update(bytes).digest("hex");
27
+
28
+ /** A failure that will not change on retry: a 4xx, or bytes that fail the pin. */
29
+ class Permanent extends Error {}
30
+
31
+ /**
32
+ * Return a build-time dependency's bytes, only if they hash to the pinned sha256: first the vendored
33
+ * file (`localPath`), then the ordered download list. The pin is what makes every source safe: one
34
+ * that has different bytes (a tampered vendored file included) is skipped, so the list can only
35
+ * improve availability, never change what gets built. A 5xx or a network error is retried with exponential backoff (bounded); a 4xx or a
36
+ * hash mismatch moves straight on to the next source.
37
+ */
38
+ export async function fetchPinned(options: FetchPinnedOptions): Promise<Buffer> {
39
+ const sha256 = options.sha256.toLowerCase();
40
+ const fetcher: Fetcher = options.fetcher ?? fetch;
41
+ const attempts = Math.max(1, options.attempts ?? 3);
42
+ const sleep = options.sleep ?? ((ms: number) => Bun.sleep(ms));
43
+ if (options.localPath && existsSync(options.localPath)) {
44
+ const vendored = await readFile(options.localPath);
45
+ if (sha256Hex(vendored) === sha256) return vendored;
46
+ console.warn(
47
+ `fetchPinned: vendored ${options.localPath} does not match the pinned sha256, falling back to download`,
48
+ );
49
+ }
50
+ if (options.cachePath && existsSync(options.cachePath)) {
51
+ const cached = await readFile(options.cachePath);
52
+ if (sha256Hex(cached) === sha256) return cached;
53
+ await rm(options.cachePath, { force: true });
54
+ }
55
+ const failures: string[] = [];
56
+ for (const url of options.urls) {
57
+ for (let attempt = 0; attempt < attempts; attempt++) {
58
+ if (attempt > 0) await sleep((options.backoffMs ?? 500) * 2 ** (attempt - 1));
59
+ try {
60
+ const response = await fetcher(url, { signal: AbortSignal.timeout(options.timeoutMs ?? 60_000) });
61
+ if (response.status >= 500) throw new Error(`HTTP ${response.status}`);
62
+ if (!response.ok) throw new Permanent(`HTTP ${response.status}`);
63
+ const bytes = Buffer.from(await response.arrayBuffer());
64
+ const got = sha256Hex(bytes);
65
+ if (got !== sha256) throw new Permanent(`sha256 mismatch (expected ${sha256}, got ${got})`);
66
+ if (options.cachePath) {
67
+ await mkdir(dirname(options.cachePath), { recursive: true });
68
+ const stage = `${options.cachePath}.${process.pid}.tmp`;
69
+ await writeFile(stage, bytes);
70
+ await rename(stage, options.cachePath);
71
+ }
72
+ return bytes;
73
+ } catch (error) {
74
+ failures.push(`${url}: ${error instanceof Error ? error.message : String(error)}`);
75
+ if (error instanceof Permanent) break;
76
+ }
77
+ }
78
+ }
79
+ throw new Error(`could not download a verified copy (sha256 ${sha256}) from any source:\n ${failures.join("\n ")}`);
80
+ }
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,14 @@
1
+ # Vendored BearSSL source
2
+
3
+ `bearssl-7bea48e.tar.gz` is the BearSSL source snapshot the CLI builds embedded sprouts against. It ships in the
4
+ npm package (and is embedded in standalone binaries), so a build needs no network access to bearssl.org, which
5
+ returned HTTP 502 for hours on 2026-11-04.
6
+
7
+ - Origin: https://bearssl.org/gitweb/?p=BearSSL;a=snapshot;h=7bea48e5e850ab4cafbe68d3765cdaba13a86d6f;sf=tgz
8
+ - Commit: `7bea48e5e850ab4cafbe68d3765cdaba13a86d6f` (`7bea48e5`; `git get-tar-commit-id` agrees)
9
+ - sha256: `ed397832b1613582737d9c1ce01c1af74ad6a9e9c52a341e24433987cda0f372`
10
+ - License: MIT, see `LICENSE.txt` (copied from the tarball)
11
+
12
+ `src/bearssl.ts` pins the sha256 and `fetchPinned` (`src/fetch-pinned.ts`) rejects this file if it does not match,
13
+ then falls back to bearssl.org. To update: replace the tarball, then change `BEARSSL_COMMIT`, `BEARSSL_SHA256` and
14
+ the import path in `src/bearssl.ts`.