You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(kernel-ui): validate branded KRef values instead of unsafe casts (#921)
A follow-up to #917 addressing various items deferred during the
introduction of branded kernel identifier types.
## Summary
- Replace `as KRef` casts from unvalidated sources with runtime
validation in `kernel-ui`
- `db-parser.ts`: remove dead `?? ''` fallbacks on regex match groups,
add `insistKRef` validation for slot resolution from JSON-parsed DB
values
- `SendMessageForm.tsx`: validate user-selected target with `isKRef`
before sending, replacing the blind `as KRef` cast
- Add `isKRef`, `insistKRef`, `KRefStruct` to `setupOcapKernelMock` test
utility
- Includes prior commit addressing PR review feedback on branded types
in `ocap-kernel`
## Test plan
- [x] `yarn workspace @metamask/kernel-ui run build` passes
- [x] `yarn workspace @metamask/kernel-ui test:dev:quiet` passes (all 34
test files, 263 tests)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Adds runtime `KRef` validation in UI and DB parsing paths, which can
now reject/throw on previously accepted malformed values. Risk is
moderate because it changes input handling and parsing behavior but is
narrowly scoped and covered by updated tests.
>
> **Overview**
> **Hardens branded identifier handling** by validating `KRef` values at
runtime instead of relying on unchecked `as KRef` casts.
>
> In `SendMessageForm`, the selected target is now stored as `KRef |
null`, validated via `isKRef` on change, and sending is blocked when the
target is invalid; tests are updated accordingly and add coverage for
failed `KRef` validation.
>
> In `kernel-ui`’s `db-parser`, regex match fallbacks are removed and
`resolveSlot` now calls `insistKRef` when converting JSON-parsed slot
strings, making malformed DB data fail fast. Supporting changes extend
`setupOcapKernelMock` with `isKRef`/`insistKRef`/`KRefStruct`, and
`ocap-kernel` tests/docs are updated (including new `getKnownRelays`
test coverage and tighter ID validation cases).
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
55a981a. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
0 commit comments