Repository navigation
fix(cli): validate checkup imports before reading - #2359
Open
beardthelion wants to merge 1 commit into
Open
beardthelion wants to merge 1 commit into
beardthelion wants to merge 1 commit into
Conversation
cli_checkup re-parses the import header itself, so it read targets the loader would refuse: non-.bend files, arbitrary absolute paths and symlinks whose real target left .bend. Validate each target before the first read or echo and report the loader expected/observed error instead.
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 #2357.
Summary
bend file.bend --checkupre-parses the import header with its own regex and reads each listed target withfs.readFileSyncbefore the loader runs. That path skipped the loader's own checks, so a header could name a non-.bendfile, an arbitrary absolute path, or a.bendsymlink to a non-.bendsecret. Checkup then echoed the file in a parse error or ran its Bend code.cli_checkupnow validates every header target before the first read or echo:.bend;./,../prefixes, and plain-name absolute paths are still accepted);fs.realpathSync) must still end in.bend, which refuses a symlink named.bendthat points at a non-.bendsecret.A rejected import prints the loader-style
expected : an import of a .bend file/observed : '<path>'error, marks the run bad, and exits 1 at the end. Valid in-tree imports, out-of-tree.bendcontrols, absolute.bendimports,import Base, and#comments are unchanged.Test plan
tests/io/checkup_import_grammar.bendandtests/io/checkup_import_grammar.js. The JS test builds a temp tree containing an outside canary secret, an outside non-.bendfile holding valid Bend code, a valid outside.bendcontrol, and a.bendsymlink to the secret. It runs the CLI asprocess.execPath ... --checkupfor an entry importing each target and asserts:.bendimports, the symlink, the executable non-.bendfile, and a dotted-name.bendpath all exit 1 without leaking the canary or printing the foreign code;.bendcontrol, the absolute.bendcontrol, and an in-tree.bendimport still exit 0 and print their values.main.tsand 0 with the fix.CHANGELOG.mdwith the CLI behavior change.bun gates/repo.ts: PASS 56 / 56.bend2/main.tstoken count: 13554 withttok -m gpt-3.5-turbo, under the 16000 cap.bun gates/test.tscould not complete in this environment: the gate acquires cluster nodes overssh cluster, and the hostname does not resolve here. The new test was exercised directly and through a local shard-style--checkupaggregator instead.Cross-references