Skip to content

Instantly share code, notes, and snippets.

@Jelmerro
Created August 23, 2022 09:04
Show Gist options
  • Save Jelmerro/7e6422665528b0f88b8b83c9dc93f35f to your computer and use it in GitHub Desktop.
Save Jelmerro/7e6422665528b0f88b8b83c9dc93f35f to your computer and use it in GitHub Desktop.
atob broken in Electron
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<title>Hello World!</title>
</head>
<body>
<webview src="about:blank" />
</body>
</html>
const {app, BrowserWindow} = require('electron')
const path = require('path')
app.whenReady().then(() => {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
webviewTag: true
}
})
mainWindow.loadFile('index.html')
mainWindow.webContents.openDevTools()
mainWindow.webContents.on("will-attach-webview", (_, prefs) => {
delete prefs.preloadURL
prefs.sandbox = false
prefs.contextIsolation = true
prefs.preload = path.join(__dirname, "preload.js")
})
})
app.on('window-all-closed', app.quit)
// Enter this to see the webview console with the errors
// document.querySelector("webview").openDevTools()
{
"name": "previous-mud-bake-agfn0",
"productName": "previous-mud-bake-agfn0",
"description": "My Electron application description",
"keywords": [],
"main": "./main.js",
"version": "1.0.0",
"author": "jelmerro",
"scripts": {
"start": "electron ."
},
"dependencies": {},
"devDependencies": {
"electron": "20.0.3"
}
}
window.addEventListener("load", () => {
// This will error:
console.log(window.atob)
console.log(window.atob("wcBMA1vBYNp8yqygAQgAnwBiRbRoTkZ7TtRuI1RI7X6fi7v//1cWEvbqb+G7\nKqjY68of7traLORhKWZK+Sbge+o+B5l0YjKTejCbqQOXhh/tETSJsQ+hiQp4\ncSkgtSjouNs/r48OZF1eHKPJvWVBnlTNcvk+lhC7PPhbsuKz+AU6Ha8lSlMI\nZQZtFY4oLXAXaC/YNx4mHEHk9AjM8K+LYcXx7puqKQdaP9D01OF9h//939Jk\nw0xp3F0zKVS0gcgLHWcATJ241ywZHzBQ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5QBxzbqFA84RjbV7Vxq6ic/4se\njjlNBKg82xJT8/uOjky/BtkB1Z4sQ3+/EX/6k2cMP7ZUn7GLmYSn8nKpZF5p\npoeflzhI0v3KNhurCTFcMVjdS5oCAh+udeHooB8p+AwcLFKbDiBarZu5k9il\nsCNMHd9dXksC3ZDQJfoGOkU9ki8udgX3m4BoicN/t2f4QElQekVNmuRXakgM\ny0VXMDH1r0E8OgZWizbAOtUrfoxmg4pHHOLa5fuiekxIaxU/5QcmCKpfcEBX\n/zmuzGGzVKxNBX0ZvJiMIANgoZKMrSSdxEkPNzXjuVITsWnV0tpg3QGIbARU\n/2tDdibrihQf900Bxuou3AnG+6tgvSvPgjR4Hm1oHxxRGRZLavlcFyD4UetI\nwuMPc6jNQWY/bn1/9OICRyoS69a5O6s1NXmkQD5BL5dyWbymQDJ9XIYAvMHs\nKc3VTHPuI8LUEWTZ5eddxvfdQ2hH8+8llU3Si/VDr4fIvEw1NEfUycaMBnlK\nlAP14s+s6A921J/Q+cLlFyMSaD5Ymrdiy+9fEexmp+YQoAB6MmrhrPX38bPs\nx8wZ5xzAiCjuVXJ6NXMqM61V4o0tMOg/RdbVfJrcpiCGJ9F0u5C/hdMHn1vL\nRTuFQjBzvPSaEHlO5x9SRyyN8SJ9L5OKlmD2zHy+zAjxkSitGbKcUoRiUN84\n+uoY02eOnEETrJLxOlWwgI1xJv6O0RgsFMWpmCPnh9u19Zbz4J36dhtjQzYG\nMjvE8N8JDt7eCx/KMV5RYp45emql4TUC3U71ZYoCC/cBR6osRRAz/QK6\n"))
// A better implementation would be like this, comment out above to see it work:
window.btoa = i => Buffer.from(String(i), "latin1").toString("base64")
window.atob = i => Buffer.from(String(i), "base64").toString("latin1")
console.log(atob("wcBMA1vBYNp8yqygAQgAnwBiRbRoTkZ7TtRuI1RI7X6fi7v//1cWEvbqb+G7\nKqjY68of7traLORhKWZK+Sbge+o+B5l0YjKTejCbqQOXhh/tETSJsQ+hiQp4\ncSkgtSjouNs/r48OZF1eH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gmS+qq757Vxo2lUkCvxPQ2yv9AYfHps+qDUMNc\nJZKrWDBa1seccnzHEvg0BNeEEkU/cDOpENoylI1n7HKpWD4ftSg/kwDFNl9F\nUcG6BgaR5AS6xrkvzymLePXRDiFa1Yq4sN5QBxzbqFA84RjbV7Vxq6ic/4se\njjlNBKg82xJT8/uOjky/BtkB1Z4sQ3+/EX/6k2cMP7ZUn7GLmYSn8nKpZF5p\npoeflzhI0v3KNhurCTFcMVjdS5oCAh+udeHooB8p+AwcLFKbDiBarZu5k9il\nsCNMHd9dXksC3ZDQJfoGOkU9ki8udgX3m4BoicN/t2f4QElQekVNmuRXakgM\ny0VXMDH1r0E8OgZWizbAOtUrfoxmg4pHHOLa5fuiekxIaxU/5QcmCKpfcEBX\n/zmuzGGzVKxNBX0ZvJiMIANgoZKMrSSdxEkPNzXjuVITsWnV0tpg3QGIbARU\n/2tDdibrihQf900Bxuou3AnG+6tgvSvPgjR4Hm1oHxxRGRZLavlcFyD4UetI\nwuMPc6jNQWY/bn1/9OICRyoS69a5O6s1NXmkQD5BL5dyWbymQDJ9XIYAvMHs\nKc3VTHPuI8LUEWTZ5eddxvfdQ2hH8+8llU3Si/VDr4fIvEw1NEfUycaMBnlK\nlAP14s+s6A921J/Q+cLlFyMSaD5Ymrdiy+9fEexmp+YQoAB6MmrhrPX38bPs\nx8wZ5xzAiCjuVXJ6NXMqM61V4o0tMOg/RdbVfJrcpiCGJ9F0u5C/hdMHn1vL\nRTuFQjBzvPSaEHlO5x9SRyyN8SJ9L5OKlmD2zHy+zAjxkSitGbKcUoRiUN84\n+uoY02eOnEETrJLxOlWwgI1xJv6O0RgsFMWpmCPnh9u19Zbz4J36dhtjQzYG\nMjvE8N8JDt7eCx/KMV5RYp45emql4TUC3U71ZYoCC/cBR6osRRAz/QK6\n"))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment