Skip to content

fix(core): use btoa() instead of window.Buffer.from() for base64 encoding#60148

Merged
nickvergessen merged 2 commits intomasterfrom
fix/unsupported-browser-redirect-buffer
May 5, 2026
Merged

fix(core): use btoa() instead of window.Buffer.from() for base64 encoding#60148
nickvergessen merged 2 commits intomasterfrom
fix/unsupported-browser-redirect-buffer

Conversation

@miaulalala
Copy link
Copy Markdown
Contributor

@miaulalala miaulalala commented May 4, 2026

Summary

window.Buffer is a Node.js API that is not natively available in browsers. It was apparently polyfilled in the webpack bundle by a dependency, but the polyfill is absent in environments like headless Electron (Cypress).

This went undetected because browserslist-useragent-regexp < 4.1.4 had a bug where an empty browser set produced /(?:)/ (matches everything). Electron matched as "supported" and the redirect code was never reached.

browserslist-useragent-regexp 4.1.4 fixed that bug (PR #1583: faithfully match an empty set of browsers), generating /[]/ instead. Electron 118 no longer matches as supported, the redirect path is now exercised, and window.Buffer.from() throws:

TypeError: Cannot read properties of undefined (reading 'from')

The fix replaces window.Buffer.from(str).toString('base64') with the native browser btoa(str), which has been universally available since before our minimum browser support baseline and requires no polyfill.

Fixes: #57920

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

…ding

window.Buffer is a Node.js API that is not natively available in browsers.
It was apparently polyfilled in the webpack bundle by a dependency, but
the polyfill is absent in environments like headless Electron (Cypress).

This went undetected because browserslist-useragent-regexp < 4.1.4 had a
bug where an empty browser set produced /(?:)/ (matches everything). Electron
matched as "supported" and the redirect code was never reached.

browserslist-useragent-regexp 4.1.4 fixed that bug (PR #1583: faithfully
match an empty set of browsers), generating /[]/ instead. Electron 118 no
longer matches as supported, the redirect path is now exercised, and
window.Buffer.from() throws:

  TypeError: Cannot read properties of undefined (reading 'from')

The fix replaces window.Buffer.from(str).toString('base64') with the
native browser btoa(str), which has been universally available since
before our minimum browser support baseline and requires no polyfill.

Fixes: #57920

Signed-off-by: Anna Larch <anna@nextcloud.com>
@miaulalala miaulalala added this to the Nextcloud 34 milestone May 4, 2026
@miaulalala miaulalala self-assigned this May 4, 2026
@miaulalala miaulalala requested a review from a team as a code owner May 4, 2026 17:50
@miaulalala miaulalala requested review from a team, nfebe, nickvergessen, sorbaugh and susnux and removed request for a team May 4, 2026 17:50
@miaulalala
Copy link
Copy Markdown
Contributor Author

/compile amend

@nextcloud-command nextcloud-command force-pushed the fix/unsupported-browser-redirect-buffer branch from 65d6e18 to 8ad3591 Compare May 4, 2026 18:24
Covers the main logic paths: supported browser (no redirect), unsupported
browser (redirect with btoa-encoded URL), already on the warning page
(no double redirect), and a no-throw guard that would have caught the
window.Buffer regression.

AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Anna Larch <anna@nextcloud.com>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
@miaulalala miaulalala force-pushed the fix/unsupported-browser-redirect-buffer branch from 34ad541 to ef0db44 Compare May 4, 2026 18:36
Copy link
Copy Markdown
Contributor

@susnux susnux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be polyfilled? Anyways this makes sense

@nickvergessen nickvergessen merged commit bae205f into master May 5, 2026
240 of 273 checks passed
@nickvergessen nickvergessen deleted the fix/unsupported-browser-redirect-buffer branch May 5, 2026 06:23
@miaulalala
Copy link
Copy Markdown
Contributor Author

/backport to stable33

@miaulalala
Copy link
Copy Markdown
Contributor Author

/backport to stable32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TypeError: Cannot read properties of undefined (reading 'from'

3 participants