Skip to content

feat(wallet): session-scoped read/sign/submit permissions (#1194) - #1306

Open
robertocarlous wants to merge 1 commit into
Nanle-code:masterfrom
robertocarlous:feat/session-scoped-wallet-permissions
Open

robertocarlous wants to merge 1 commit into
Nanle-code:masterfrom
robertocarlous:feat/session-scoped-wallet-permissions

Conversation

@robertocarlous

Copy link
Copy Markdown
Contributor

Closes #1194

What

Adds session-scoped read / sign / submit permissions for a connected wallet. A fresh session grants all three (preserving existing behaviour); the user can revoke any of them from Wallet → Session permissions for the rest of the browser session. Revocations are enforced end to end and reset when the session ends.

Behaviour

  • read — gates account/chain data fetching (wallet connect and the Freighter background account refresh).
  • sign — enforced centrally in createAdapter (src/lib/wallet/adapters.ts), before any network or XDR work, so a revoked session never reaches the wallet. Covers signTransaction and signAuthEntry.
  • submit — enforced in useWriteGuard().guard(...), which now exposes a permissionDenied result instead of calling onConfirm.

Permissions are stored in sessionStorage (stellar-dash:wallet-session-permissions) and the in-memory session slice. They are deliberately not in PERSIST_KEYS, are cleared on disconnectWallet() / revokeWalletSession(), and fail closed on corrupt storage (read kept, sign/submit denied).

Files

  • src/lib/wallet/sessionPermissions.ts (new) — framework-free validation, persistence and enforcement core.
  • src/lib/store.ts — walletSessionPermissions + grant/revoke actions; reset/clear on disconnect and revoke; installs the checker.
  • src/lib/wallet/adapters.ts — signing gate.
  • src/lib/wallet/sessionListeners.ts — read gate for background refresh.
  • src/hooks/useWriteGuard.ts — submit gate.
  • src/hooks/useWalletPermissions.ts (new), src/components/settings/WalletSessionPermissions.tsx (new) — UI/hook surface.
  • src/components/dashboard/WalletConnect.tsx — mounts the settings control.
  • docs/security/wallet-session-permissions.md (new), SECURITY.md.

Tests (happy path / boundary / failure)

  • src/lib/wallet/__tests__/sessionPermissions.test.ts — normalization, persistence round-trip, corrupt-JSON/shape/blocked-storage fallbacks, flag coercion boundary, throwing checker.
  • src/lib/wallet/__tests__/sessionPermissions.store.test.ts — grant/revoke wiring and disconnect/revoke reset + storage clear.
  • src/lib/wallet/__tests__/sessionPermissions.enforcement.test.ts — adapter signing gate for signTransaction and signAuthEntry, plus the granted control case.

Verification (all pass):

pnpm exec vitest run --config vitest.config.js \
  src/lib/wallet/__tests__/sessionPermissions.test.ts \
  src/lib/wallet/__tests__/sessionPermissions.store.test.ts \
  src/lib/wallet/__tests__/sessionPermissions.enforcement.test.ts
# 25 passed
pnpm exec vitest run --config vitest.config.js tests/unit/hooks/useWriteGuard.test.ts  # 9 passed

Security, privacy, accessibility, network safety

  • Fails closed: a corrupt/unreadable record denies sign/submit rather than re-granting them; a throwing checker fails closed for privileged actions.
  • Signing is refused before any wallet/network call, removing an accidental-approval path.
  • Not a cryptographic boundary (the wallet still confirms every signature); see the doc.
  • No data egress — the record holds three booleans in sessionStorage.
  • The control uses labelled role="switch" toggles, aria-checked, reduced-motion and high-contrast support.

Notes

…code#1194)

Adds per-session wallet permissions that users can revoke from settings and
that are enforced at every wallet choke point:

- read: account/chain data fetches (connect + Freighter background refresh)
- sign: all adapter signTransaction / signAuthEntry calls
- submit: writes routed through useWriteGuard

Permissions live in sessionStorage and the in-memory session slice, reset on
disconnect/revoke, and fail closed on corrupt storage. Signing is blocked
before any network/XDR work so a revoked session never reaches the wallet.

Includes the settings control, hook, tests (happy/boundary/failure), and
docs/security/wallet-session-permissions.md.
@vercel

vercel Bot commented Oct 19, 2026

Copy link
Copy Markdown

@robertocarlous is attempting to deploy a commit to the nanle-code's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

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

[2026 Wallet] Add session-scoped permissions for read, sign and submit actions

1 participant