Repository navigation
fix(cli): confine bundled imports to page directory - #2358
Open
beardthelion wants to merge 1 commit into
Open
beardthelion wants to merge 1 commit into
beardthelion wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2356.
Summary
bend page.html -o outrunsBun.buildwith a loader for.bendimports and a virtual module for inline<script type="module">blocks. Every other import specifier falls through to Bun's asset loader, which copies the resolved file into the publishable output directory. A page could therefore read any file the bundler's user could read: a../path to a sibling secret, an absolute path such as/etc/hostname, or a symlink named.bendpointing outside the page tree.cli_bundlenow adds a third, minimalonResolveplugin. For file-namespace specifiers it resolves withBun.resolveSync, canonicalizes with the existingpath_real(), and refuses any target outside the entry page's real directory. This covers relative, absolute, and bare specifiers, including bare imports that resolve throughnode_moduleslinks. Real.bendmodules outside the page directory are still allowed because the loader compiles them rather than copying them as assets. The entry point, virtual namespaces, and unresolvable imports are left to their existing handling; the-ooverwrite guard and all control behavior are unchanged. A rejected import prints a clean CLI error such as:Test plan
tests/io/bundle_page_confine.bendandtests/io/bundle_page_confine.js. The foreign-JS test creates a temp tree with a canary secret outside the page directory, a valid in-tree.bendmodule, a real out-of-tree.bendmodule, a.bendsymlink to the secret, and anode_modulessymlink to the secret. It builds pages with a../import, a self-contained absolute import, the symlink, and a barepkg/credentialsspecifier, plus in-tree and out-of-tree.bendcontrols. It asserts each escaping import exits 1 with the confinement error and no crash text, both controls bundle and their output runs, and no output file contains the canary. Temp directories are removed on exit; telemetry is disabled andHOMEis set to the temp dir.-o .still reports the overwrite error.CHANGELOG.mdwith the CLI behavior change.bun gates/repo.ts: PASS 56 / 56.bun gates/test.ts; it could not acquire cluster nodes becausessh clusterdoes not resolve in this environment. The new test and the existing bundle tests (bundle_page_input,bundle_inline,html_script_types,bundle_own_exports) were each run directly and returned 0.bend2/main.tstoken count: 13656 withttok -m gpt-3.5-turbo, under the 16000 cap.Cross-references
cli_bundle; this change keeps inline virtual modules and their in-tree.bendimports working, and only confines file imports that would otherwise be copied as assets.