fix(js): authenticate BashTool snapshots#1838
Merged
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 3bdf267 | Commit Preview URL | Jun 02 2026, 01:52 PM |
21aee56 to
63722a9
Compare
63722a9 to
ef3a68e
Compare
There was a problem hiding this comment.
Pull request overview
This PR hardens snapshot/restore for multi-tenant BashTool usage by requiring HMAC-authenticated snapshots and plumbing an hmacKey through the JS wrapper into the napi/Rust keyed snapshot APIs, while keeping plain Bash usage backward-compatible (unkeyed by default, keyed when a key is supplied).
Changes:
- Added
hmacKeyto JSSnapshotOptions, converting it to a nativeBufferand enforcing it forBashToolsnapshot/restore/fromSnapshot flows. - Extended the napi/Rust
SnapshotOptionswithhmac_keyand routed snapshot/restore to keyed Rust APIs when a key is present (required forBashTool). - Updated README examples and JS integration tests to require/verify HMAC behavior for
BashToolsnapshots.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
crates/bashkit-js/wrapper.ts |
Adds hmacKey plumbing and enforces HMAC key presence for BashTool snapshot APIs. |
crates/bashkit-js/src/lib.rs |
Adds hmac_key to napi SnapshotOptions and switches to keyed Rust snapshot APIs when a key is provided/required. |
crates/bashkit-js/README.md |
Updates snapshot security guidance and BashTool snapshot usage examples/API list. |
crates/bashkit-js/__test__/integration.spec.ts |
Updates BashTool integration tests to include required hmacKey and verify HMAC failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
1260
to
1263
| snapshot(options?: SnapshotOptions): Uint8Array { | ||
| requireSnapshotHmacKey(options); | ||
| return this.native.snapshot(toNativeSnapshotOptions(options)); | ||
| } |
Comment on lines
1270
to
1276
| restoreSnapshot(data: Uint8Array, options?: SnapshotOptions): void { | ||
| requireSnapshotHmacKey(options); | ||
| this.native.restoreSnapshot( | ||
| Buffer.from(data), | ||
| toNativeSnapshotOptions(options), | ||
| ); | ||
| } |
Comment on lines
+1301
to
+1306
| static fromSnapshot( | ||
| data: Uint8Array, | ||
| options?: BashOptions, | ||
| snapshotOptions?: SnapshotOptions, | ||
| ): BashTool { | ||
| requireSnapshotHmacKey(snapshotOptions); |
Comment on lines
+272
to
+273
| const snapshotKey = new TextEncoder().encode("integration snapshot hmac key"); | ||
|
|
| - `Bash.fromSnapshot(data)` / `Bash.fromSnapshotKeyed(data, key, options?)` | ||
| - `snapshot(options?)` / `snapshotKeyed(key, options?)` | ||
| - `restoreSnapshot(data, options?)` / `restoreSnapshotKeyed(data, key)` | ||
| - `Bash.fromSnapshot(data, options?)` / `Bash.fromSnapshotKeyed(data, key, options?)` |
- BashTool.snapshot/restoreSnapshot require SnapshotOptions & { hmacKey }
- BashTool.fromSnapshot second param is BashOptions | undefined so third
(snapshotOptions with required hmacKey) can be non-optional
- Add Bash hmacKey roundtrip and tamper-rejection integration tests
- Fix README: Bash.fromSnapshotKeyed has no options parameter
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.
Motivation
BashToolflows and steering JS bindings to keyed Rust APIs when a key is supplied.Description
hmacKeyto JSSnapshotOptionsand plumb it throughtoNativeSnapshotOptionsinto the napi binding.hmacKeyforBashTool.snapshot,BashTool.restoreSnapshot, andBashTool.fromSnapshotin the JS wrapper and reject missing/empty keys.snapshot_to_bytes_keyed,from_bytes_keyed,restore_snapshot_keyed) when a key is present; fall back to unkeyed APIs for plainBashusage.README.mdto require/illustratehmacKeyusage and add an integration test asserting missing/wrong/tampered-key failures.Testing
cargo fmt --checkandcargo check -p bashkit-js(both succeeded).pnpm install --frozen-lockfileandpnpm run build:napi(succeeded).pnpm run build:cjs && pnpm run build:tsand ranpnpm run type-check(succeeded)../node_modules/.bin/ava --match="integration: BashTool *"and all relevant integration tests passed.pnpm run format:checkinitially reported pre-existing unrelated formatting warnings; changed files were formatted withprettier --writeas part of the rollout.Codex Task