Skip to content

fix(cli): validate checkup imports before reading - #2359

Open
beardthelion wants to merge 1 commit into
bendlang:mainfrom
beardthelion:fix/cli-checkup-import-grammar
Open

beardthelion wants to merge 1 commit into
bendlang:mainfrom
beardthelion:fix/cli-checkup-import-grammar

Conversation

@beardthelion

Copy link
Copy Markdown

Fixes #2357.

Summary

bend file.bend --checkup re-parses the import header with its own regex and reads each listed target with fs.readFileSync before the loader runs. That path skipped the loader's own checks, so a header could name a non-.bend file, an arbitrary absolute path, or a .bend symlink to a non-.bend secret. Checkup then echoed the file in a parse error or ran its Bend code.

cli_checkup now validates every header target before the first read or echo:

  • the path must end in .bend;
  • it must match the loader's plain-name path grammar (leading ./, ../ prefixes, and plain-name absolute paths are still accepted);
  • its real target (fs.realpathSync) must still end in .bend, which refuses a symlink named .bend that points at a non-.bend secret.

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 .bend controls, absolute .bend imports, import Base, and # comments are unchanged.

Test plan

  • Added tests/io/checkup_import_grammar.bend and tests/io/checkup_import_grammar.js. The JS test builds a temp tree containing an outside canary secret, an outside non-.bend file holding valid Bend code, a valid outside .bend control, and a .bend symlink to the secret. It runs the CLI as process.execPath ... --checkup for an entry importing each target and asserts:
    • relative and absolute non-.bend imports, the symlink, the executable non-.bend file, and a dotted-name .bend path all exit 1 without leaking the canary or printing the foreign code;
    • the out-of-tree .bend control, the absolute .bend control, and an in-tree .bend import still exit 0 and print their values.
  • Confirmed the test returns 1 against the unfixed main.ts and 0 with the fix.
  • Ran the original checkup repro: the four leaking cases are now blocked with the clean expected/observed error, and the benign in-tree control still prints its value.
  • Updated CHANGELOG.md with the CLI behavior change.
  • Ran bun gates/repo.ts: PASS 56 / 56.
  • bend2/main.ts token count: 13554 with ttok -m gpt-3.5-turbo, under the 16000 cap.
  • bun gates/test.ts could not complete in this environment: the gate acquires cluster nodes over ssh cluster, and the hostname does not resolve here. The new test was exercised directly and through a local shard-style --checkup aggregator instead.

Cross-references

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

bend file.bend --checkup reads and runs import targets the loader refuses

1 participant