Skip to content

fix(ai-vault): support non-secure web contexts - #13142

Closed
m8928 wants to merge 1 commit into
stablyai:mainfrom
m8928:agent/fix-ai-vault-insecure-context-uuid
Closed

m8928 wants to merge 1 commit into
stablyai:mainfrom
m8928:agent/fix-ai-vault-insecure-context-uuid

Conversation

@m8928

@m8928 m8928 commented Aug 8, 2026 •

Copy link
Copy Markdown

Summary

  • Prevent Agent Session History from crashing the right sidebar on plain HTTP web clients.
  • Use the existing createBrowserUuid() fallback for the AI Vault scan request token.
  • Add a regression test that mounts the real refresh hook with crypto.randomUUID unavailable.

Root cause: browsers do not expose crypto.randomUUID in non-secure contexts such as a LAN or Tailscale web client served over plain HTTP. The AI Vault refresh hook called it unconditionally during render, so the right-sidebar error boundary replaced the panel before any session request could start.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Focused verification:

  • vitest run --config config/vitest.config.ts src/renderer/src/components/right-sidebar/ai-vault-session-refresh.test.ts src/renderer/src/lib/non-secure-context-crypto.repro.test.ts — 2 files, 31 tests passed after rebasing onto current main and again after the full build.
  • The new test fails on the previous code with TypeError: crypto.randomUUID is not a function at ai-vault-session-refresh.ts.

The full test suite was attempted after the rebase, but this local sandbox forbids the Unix/TCP socket and DNS operations used by many integration tests (listen EPERM, ENOTFOUND), causing repeated 30–60 second infrastructure timeouts. The run was stopped after more than 12 minutes rather than reporting those environment failures as change-related results. Full lint, full typecheck, full desktop/web/native build, and the focused regression surface pass.

AI Review Report

The review checked the render-time failure path, hook cleanup, request-token stability, existing UUID fallback behavior, and test isolation. No change-specific findings remained.

Cross-platform compatibility was reviewed for macOS, Linux, and Windows. The change introduces no shortcuts, labels, paths, shell behavior, native modules, or Electron-specific branches. SSH hosts and folder workspaces are unaffected because the token is created in the renderer before the existing IPC/runtime request.

Supported agents and integrations are unaffected. The change only replaces renderer-side request-token generation before the existing provider-neutral AI Vault API call; it does not branch on agent type, integration, Git provider, workspace type, or runtime transport.

Performance risk is negligible: createBrowserUuid() runs once per hook instance through the existing useRef initialization path, matching the previous UUID call's frequency. It adds no polling, I/O, subscription, or hot-path work. UI quality review is not applicable because there is no visual, layout, or interaction change beyond preventing the sidebar crash.

Security Audit

No new input, command execution, path handling, authentication, secret, dependency, or IPC surface is introduced. The request token is a cancellation/correlation identifier rather than an authorization credential. In the affected non-secure browser context, the existing helper uses crypto.getRandomValues; its final Math.random fallback is unchanged and remains limited to non-security-sensitive UI identifiers.

Notes

Constraint: Plain HTTP LAN clients do not expose crypto.randomUUID.
Rejected: Global crypto polyfill | Existing createBrowserUuid keeps the fallback scoped to renderer identifiers.
Confidence: high
Scope-risk: narrow
Directive: Use createBrowserUuid for renderer IDs that must work outside secure contexts.
Tested: pnpm lint; pnpm typecheck; focused Vitest 31 passed after rebase.
Not-tested: full pnpm test; pnpm build
@m8928
m8928 marked this pull request as ready for review August 8, 2026 06:52
@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The refresh hook now imports and calls createBrowserUuid() to generate request tokens. Tests preserve and restore the original global crypto object. Added coverage mounts the hook with a getRandomValues-only implementation, verifies one scan, and checks that the request token matches UUID format. Cancellation and refresh behavior remain unchanged.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the primary fix for AI Vault in non-secure web contexts.
Description check ✅ Passed The description includes all required sections, explains the change, documents testing limits, and provides AI review and security audit details.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker

Copy link
Copy Markdown
Contributor

Flagging overlap rather than closing: #22516 now covers this bug end to end — every crypto.randomUUID call site in src/renderer/src and src/shared, one shared generator instead of the per-site fallbacks, and an oxlint ratchet over both layers so a new call site cannot regress it. It also carries a before/after of the real web bundle on a non-secure origin.

The AI Vault request-token test from #20465 has been ported into #22516, so that coverage is not lost. A maintainer should close this in favour of #22516 unless it covers something #22516 misses — if it does, please say so on #22516.

@nwparker

nwparker commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded by #22516, which is merged and present on main.

I checked this PR's scope and discussion against the merged implementation. The replacement explicitly supersedes this PR and covers its requested behavior. Thanks for the contribution; the branch is preserved.

@nwparker nwparker closed this Oct 6, 2026
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.

4 participants