You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The released bend binary runs bunfig.tomlpreload from the working directory, so checking a project can run its code and fake the verdict #1018
The release archive's bin/bend is a Bun standalone executable (bend-2.0.26-darwin-arm64.tar.gz, sha256 a340f4f0… as in flake.nix; Bun v1.4.0). With the default build options, a Bun executable loads bunfig.toml from the current directory at startup and runs its preload scripts before bend's own code. The Homebrew formula and the Nix flake install the same archive.
A directory with a false law:
LAWS.bend
import Base
law false_law:
{1n == 0n : Nat}
PROOF.bend
import Base
import ./LAWS.bend as Laws
def Laws.false_law():
{==}
and two more files the project can ship next to them:
bend PROOF.bend --check-only behaves the same way. A preload that only writes a marker file shows that it runs for any file passed to bend, including a plain main.bend. The script is ordinary TypeScript with full access to the machine.
The same autoloading also reads .env (see the comment on #1005: a project can point BEND_LIB at unverified copies of hub packages). The released binary does this too: the .env repro from #1005 prints All terms check. with it.
Why it matters
The verdict can be forged. In the LAWS/PROOF workflow, the side that writes PROOF.bend can also add bunfig.toml and a hidden script, and bend PROOF.bend then reports success and exits 0 for any laws. CI that runs bend PROOF.bend in the checked-out tree is affected in the same way.
Checking runs the project's code. Running bend on a project you do not trust (to check it, not to run it) executes arbitrary code from that project with the user's permissions. Nothing in Bend itself does this: the checker never runs IO, so users have no reason to expect it.
Expected behavior
bend should not read Bun configuration from the directory it is run in. Bun has build flags for this: bun build --compile --no-compile-autoload-bunfig --no-compile-autoload-dotenv (and, for completeness, --no-compile-autoload-package-json --no-compile-autoload-tsconfig), or the matching autoloadBunfig: false / autoloadDotenv: false in Bun.build's compile options. The build lives in release.ts in the bend-lang.com repo, so I could not test the fixed binary myself.
Running bun bend2/main.ts from a checkout has the same problem with bunfig.toml and .env in the working directory. That is less common for users, but the guide or README could mention it.
Version
bend 2.0.26 (release archive bend-2.0.26-darwin-arm64.tar.gz)
Bun v1.4.0 (embedded)
Darwin arm64
More effects of the .env autoloading on the released binary. Each one needs only a .env in the project, with no bunfig.toml and no script, so --no-compile-autoload-dotenv matters on its own and not just alongside --no-compile-autoload-bunfig.
1. The Bender key is sent to a server the project chooses.hub_ask sends Authorization: Bearer <key from ~/.bend/bender.json> to BEND_HUB (main.ts#L535-L538), and BEND_HUB can come from .env. I tested this offline, with a fake key in a scratch HOME and a local server that logs request headers:
So publishing from a directory you did not create hands your key to whoever wrote its .env. bend link goes through hub_ask too.
2. bend update runs a script the project chooses.cli_update prints curl -fsSL $ORIGIN/install.sh | sh and runs it immediately, and BEND_ORIGIN can come from .env. I found this by reading the code and did not run it.
3. A hash check on load would not cover named imports. In my comment on #1005 I suggested checking cached packages against their hash on every load. That works for 0x…/ imports but not for name@version/ ones: name_hash keeps the name → hash mapping in BEND_LIB/names/, which is under the same BEND_LIB. A project that sets BEND_LIB can therefore supply both the mapping and a package that matches it. I checked this on the released binary: a LAWS.bend that imports [email protected]/lib.bend, with the mapping and the package under a .cache/ named in .env, gives All terms check. for a false law. For named imports, only turning off .env loading helps.
Activity
jasisz commentedon Sep 23, 2026
More effects of the
.envautoloading on the released binary. Each one needs only a.envin the project, with nobunfig.tomland no script, so--no-compile-autoload-dotenvmatters on its own and not just alongside--no-compile-autoload-bunfig.1. The Bender key is sent to a server the project chooses.
hub_asksendsAuthorization: Bearer <key from ~/.bend/bender.json>toBEND_HUB(main.ts#L535-L538), andBEND_HUBcan come from.env. I tested this offline, with a fake key in a scratchHOMEand a local server that logs request headers:The server's log:
So publishing from a directory you did not create hands your key to whoever wrote its
.env.bend linkgoes throughhub_asktoo.2.
bend updateruns a script the project chooses.cli_updateprintscurl -fsSL $ORIGIN/install.sh | shand runs it immediately, andBEND_ORIGINcan come from.env. I found this by reading the code and did not run it.3. A hash check on load would not cover named imports. In my comment on #1005 I suggested checking cached packages against their hash on every load. That works for
0x…/imports but not forname@version/ones:name_hashkeeps the name → hash mapping inBEND_LIB/names/, which is under the sameBEND_LIB. A project that setsBEND_LIBcan therefore supply both the mapping and a package that matches it. I checked this on the released binary: a LAWS.bend that imports[email protected]/lib.bend, with the mapping and the package under a.cache/named in.env, givesAll terms check.for a false law. For named imports, only turning off.envloading helps.Lorenzobattistela commentedon Sep 23, 2026
Thanks for the detailed report.
Lorenzobattistela commentedon Sep 23, 2026
Fixed in v2.0.27