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

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>
This commit is contained in:
Anna Larch 2026-05-04 19:48:19 +02:00 committed by backportbot[bot]
parent 86ce5b4382
commit 09f67f8eee

View file

@ -33,7 +33,7 @@ export function testSupportedBrowser() {
// redirect to the unsupported warning page
if (window.location.pathname.indexOf(redirectPath) === -1) {
const redirectUrl = window.location.href.replace(window.location.origin, '')
const base64Param = window.Buffer.from(redirectUrl).toString('base64')
const base64Param = btoa(redirectUrl)
history.pushState(null, null, `${redirectPath}?redirect_url=${base64Param}`)
window.location.reload()
}