[PR #7844] [MERGED] feat(electron): fetch user image securely regardless of csp #7590

Closed
opened 2026-03-13 13:42:28 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7844
Author: @jslno
Created: 2/7/2026
Status: Merged
Merged: 2/17/2026
Merged by: @Bekacru

Base: canaryHead: 02-07-2026/electron-user-image


📝 Commits (10+)

  • 9a49802 feat(electron): fetch user image securely regardless of csp
  • b4030e5 chore: fix spell
  • b5be606 refactor: use $fetch
  • c5b0b67 chore: update tests
  • 78cfd61 Merge branch 'canary' into 02-07-2026/electron-user-image
  • 92d5adf chore: export normalizeUser
  • ee16144 chore: cleanup
  • 013d6ca chore: update
  • 05449d0 chore: fix linting
  • 0f827ba Merge branch 'canary' into 02-07-2026/electron-user-image

📊 Changes

8 files changed (+827 additions, -10 deletions)

View changed files

📝 .cspell/tech-terms.txt (+2 -0)
📝 docs/content/docs/integrations/electron.mdx (+37 -0)
📝 packages/electron/src/authenticate.ts (+7 -2)
📝 packages/electron/src/browser.ts (+134 -7)
📝 packages/electron/src/client.ts (+1 -0)
📝 packages/electron/src/types/client.ts (+42 -0)
packages/electron/src/user.ts (+291 -0)
📝 packages/electron/test/electron.test.ts (+313 -1)

📄 Description

Summary by cubic

Serve user avatars via a privileged user-image:// protocol that streams validated bytes from the main process, so avatars load regardless of CSP. User objects sent to the renderer have image normalized to protocol URLs when the proxy is enabled.

  • New Features

    • User-image protocol: privileged stream handler that bypasses CSP; scheme auto-added to img-src.
    • Secure fetchUserImage: uses electron.net.fetch; http/https only; blocks localhost/private IPs (non-dev); rejects SVG; validates formats (png/jpg/gif/webp/bmp/ico/tiff/avif/heic/heif) from the first chunk; size limits; honors Accept; resolves relative URLs; supports data: URLs; custom validator.
    • Access control: serves current session user or via /admin/get-user when the admin plugin is enabled.
    • Config: ElectronClientOptions.userImageProxy { enabled, scheme, maxSize, accept, customValidator }; docs include usage and how to disable.
  • Refactors

    • normalizeUserOutput replaces image with user-image:// only when proxy is enabled; applied on authenticate success, session user-updated, and getUser IPC; exported for clients.
    • Deep link, CSP, and protocol handlers accept clientOptions; tests cover normalization, formats, SSRF, data URLs, and error paths.

Written for commit 1d5d96f2de. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7844 **Author:** [@jslno](https://github.com/jslno) **Created:** 2/7/2026 **Status:** ✅ Merged **Merged:** 2/17/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `02-07-2026/electron-user-image` --- ### 📝 Commits (10+) - [`9a49802`](https://github.com/better-auth/better-auth/commit/9a498024ccd2afa4c381e401727876f0ee951a9e) feat(electron): fetch user image securely regardless of csp - [`b4030e5`](https://github.com/better-auth/better-auth/commit/b4030e51efeaf54615ec001635831ad86543ff02) chore: fix spell - [`b5be606`](https://github.com/better-auth/better-auth/commit/b5be6064e2bad0d803e6970781154f5e5cf34494) refactor: use $fetch - [`c5b0b67`](https://github.com/better-auth/better-auth/commit/c5b0b67177f89917ab490b36d8c0b22cbaf1704d) chore: update tests - [`78cfd61`](https://github.com/better-auth/better-auth/commit/78cfd61c7b52dc255da94fd8e7279f6dd8efbcb7) Merge branch 'canary' into 02-07-2026/electron-user-image - [`92d5adf`](https://github.com/better-auth/better-auth/commit/92d5adf261ebad09502981bb0822d294d9c42633) chore: export normalizeUser - [`ee16144`](https://github.com/better-auth/better-auth/commit/ee161441916e9e3383a04a054a133ddbb6220cdf) chore: cleanup - [`013d6ca`](https://github.com/better-auth/better-auth/commit/013d6ca62b98aef915536983960a4af2909d1c58) chore: update - [`05449d0`](https://github.com/better-auth/better-auth/commit/05449d0467e2815cb8279fec08076687c808ccf7) chore: fix linting - [`0f827ba`](https://github.com/better-auth/better-auth/commit/0f827ba2a637463032b9cc240b462a80049065fd) Merge branch 'canary' into 02-07-2026/electron-user-image ### 📊 Changes **8 files changed** (+827 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `.cspell/tech-terms.txt` (+2 -0) 📝 `docs/content/docs/integrations/electron.mdx` (+37 -0) 📝 `packages/electron/src/authenticate.ts` (+7 -2) 📝 `packages/electron/src/browser.ts` (+134 -7) 📝 `packages/electron/src/client.ts` (+1 -0) 📝 `packages/electron/src/types/client.ts` (+42 -0) ➕ `packages/electron/src/user.ts` (+291 -0) 📝 `packages/electron/test/electron.test.ts` (+313 -1) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Serve user avatars via a privileged user-image:// protocol that streams validated bytes from the main process, so avatars load regardless of CSP. User objects sent to the renderer have image normalized to protocol URLs when the proxy is enabled. - **New Features** - User-image protocol: privileged stream handler that bypasses CSP; scheme auto-added to img-src. - Secure fetchUserImage: uses electron.net.fetch; http/https only; blocks localhost/private IPs (non-dev); rejects SVG; validates formats (png/jpg/gif/webp/bmp/ico/tiff/avif/heic/heif) from the first chunk; size limits; honors Accept; resolves relative URLs; supports data: URLs; custom validator. - Access control: serves current session user or via /admin/get-user when the admin plugin is enabled. - Config: ElectronClientOptions.userImageProxy { enabled, scheme, maxSize, accept, customValidator }; docs include usage and how to disable. - **Refactors** - normalizeUserOutput replaces image with user-image://<id> only when proxy is enabled; applied on authenticate success, session user-updated, and getUser IPC; exported for clients. - Deep link, CSP, and protocol handlers accept clientOptions; tests cover normalization, formats, SSRF, data URLs, and error paths. <sup>Written for commit 1d5d96f2de1c5e2511cf1cc2172c940b62702027. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:42:28 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#7590