Skip to content

fix(interpreter): preserve legacy nameref targets#1810

Merged
chaliy merged 2 commits into
mainfrom
2026-05-30-propose-fix-for-legacy-nameref-migration-bug
May 30, 2026
Merged

fix(interpreter): preserve legacy nameref targets#1810
chaliy merged 2 commits into
mainfrom
2026-05-30-propose-fix-for-legacy-nameref-migration-bug

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented May 30, 2026

Motivation

  • Legacy snapshots stored namerefs as _NAMEREF_<name>=<target> and the migration discarded marker values, creating self-referential namerefs that break readonly/nameref semantics and allow integrity bypass.

Description

  • Modify the migration helper take_prefixed in crates/bashkit/src/interpreter/mod.rs to return (stripped_name, marker_value) pairs so marker values are preserved during removal.
  • Restore legacy attributes using for (key, _) in take_prefixed(...) and restore legacy namerefs using for (key, target) in take_prefixed(...){ namerefs.entry(key).or_insert(target); } so _NAMEREF_alias=POLICY becomes alias -> POLICY.
  • Add a regression test test_restore_shell_state_migrates_legacy_nameref_targets that verifies the marker variable is removed, the nameref resolves to the original target, and readonly protection remains effective when assigning through the alias.

Testing

  • Ran cargo fmt --check and formatting checks passed.
  • Ran the unit test test_restore_shell_state_migrates_legacy_nameref_targets and the existing test_restore_shell_state under -p bashkit; both tests passed.
  • Ran cargo clippy -p bashkit --all-targets -- -D warnings and the linter completed without warnings.

Codex Task

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 30, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 6b023af Commit Preview URL May 30 2026, 09:07 AM

@chaliy chaliy merged commit 844cd41 into main May 30, 2026
34 checks passed
@chaliy chaliy deleted the 2026-05-30-propose-fix-for-legacy-nameref-migration-bug branch May 30, 2026 09:17
chaliy added a commit that referenced this pull request May 30, 2026
Legacy snapshots stored namerefs as `_NAMEREF_<name>=<target>` but the migration discarded marker values, creating self-referential namerefs that break readonly/nameref semantics. Fix `take_prefixed` to return `(stripped_name, marker_value)` pairs and use `namerefs.entry(key).or_insert(target)` so `_NAMEREF_alias=POLICY` correctly becomes `alias -> POLICY`. Adds regression test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant