久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在與應用程序一起打包的本地頁面上啟用 Electr

Would it be safe to enable nodeIntegration in Electron on a local page that is packaged with the app?(在與應用程序一起打包的本地頁面上啟用 Electron 中的 nodeIntegration 是否安全?) - IT屋-程序員軟件開發技術分享
本文介紹了在與應用程序一起打包的本地頁面上啟用 Electron 中的 nodeIntegration 是否安全?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在創建自定義窗口控件(如關閉、最小/最大和還原)時遇到問題,但 nodeIntegration 已關閉.我在渲染器的本地 html 文件中創建了按鈕

<塊引用>

main.js

mainWindow = new BrowserWindow({x, y, 寬度, 高度,框架:假,顯示:假,webPreferences: { devTools: true }});mainWindow.loadURL(url.format({協議:'文件:',斜線:真,路徑名:path.join(__dirname, 'assets', 'index.html')}));

<塊引用>

index.html

<div id='minimize' class='noSelect'>&#xE921;</div><div id='maximize' class='noSelect'>&#xE922;</div><div id='restore' class='noSelect'>&#xE923;</div><div id='close' class='noSelect'>&#xE8BB;</div><script type='text/javascript' src='../assets/js/index.js'></script>

默認情況下,nodeIntegration 處于關閉狀態,因此 index.js 無法訪問 Node.但是,我需要能夠向按鈕添加功能以關閉、最小/最大和恢復窗口.

<塊引用>

index.js

const { remote } = require('electron');const mainWindow = remote.getCurrentWindow();document.getElementById('close').addEventListener('click', () => {mainWindow.close();});

這不起作用,因為 nodeIntegration 被禁用.在本地頁面中啟用它是否安全?如果沒有,這樣做的安全方法是什么?

解決方案

TL;DR: 啟用 nodeIntegration 只會在您從不受信任的來源加載和執行代碼時產生風險,即互聯網或來自用戶輸入.

如果您完全確定您的應用程序將只運行您創建的代碼(并且沒有 NodeJS 模塊從互聯網加載腳本),基本上,啟用 nodeIntegration 的風險很小.

但是,如果您允許用戶運行代碼(即輸入然后 eval 它)或者您提供插件 API,您無法控制加載的插件,風險級別上升是因為 NodeJS 允許任何 NodeJS 腳本(例如)操作文件系統.

另一方面,如果禁用nodeIntegration,則無法與主進程通信或操作BrowserWindow,因此無法創建自定義窗口控件.

I am stuck when creating custom window controls like close, min/max and restore with nodeIntegration turned off. I created the buttons in my renderer's local html file

main.js

mainWindow = new BrowserWindow({
    x, y, width, height,
    frame: false,
    show: false,
    webPreferences: { devTools: true }
});

mainWindow.loadURL(url.format({
    protocol: 'file:',
    slashes: true,
    pathname: path.join(__dirname, 'assets', 'index.html')
}));

index.html

<div id='minimize' class='noSelect'>&#xE921;</div>
<div id='maximize' class='noSelect'>&#xE922;</div>
<div id='restore' class='noSelect'>&#xE923;</div>
<div id='close' class='noSelect'>&#xE8BB;</div>

<script type='text/javascript' src='../assets/js/index.js'></script>

By default, nodeIntegration is off so index.js has no access to Node. However, I need to be able to add functionality to the buttons to close, min/max and restore the window.

index.js

const { remote } = require('electron');
const mainWindow = remote.getCurrentWindow();

document.getElementById('close').addEventListener('click', () => {
  mainWindow.close();
});

This wouldn't work because of nodeIntegration being disabled. Is it safe to have it enabled in a local page? If not, what is a safe way of doing this?

解決方案

TL;DR: Enabling nodeIntegration only imposes risks if you load and execute code from untrusted sources, i.e. the internet or from user input.

If you are completely sure that your application will only run the code you have created (and no NodeJS module loads scripts from the internet), basically, there is no to very little risk if enabling nodeIntegration.

However, if you allow the user to run code (i.e. input and then eval it) or you provide plug-in APIs from which you do not have any control over the plug-ins loaded, the risk level rises because NodeJS allows any NodeJS script, ex., to manipulate the filesystem.

On the other hand, if you disable nodeIntegration, you have no way of communicating with the main process or manipulating the BrowserWindow, thus cannot create custom window controls.

這篇關于在與應用程序一起打包的本地頁面上啟用 Electron 中的 nodeIntegration 是否安全?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 久久成人精品视频 | aaaa日韩| 亚洲国产一区二区三区在线观看 | 99国产精品99久久久久久 | 一级黄在线观看 | 免费在线观看一区二区 | 欧美三级成人理伦 | 国产一区二区三区在线 | 中文字幕在线观看 | 欧美jizzhd精品欧美巨大免费 | 国产成人精品一区二区三区在线 | 亚洲黄色高清视频 | aaa在线| 奇米超碰在线 | 污片在线观看 | 婷婷福利 | 国产免费让你躁在线视频 | 影音先锋中文字幕在线观看 | 久久五月婷| 久久久久久久久中文字幕 | 成人在线一区二区三区 | 精品一区在线 | 夜夜夜操 | 免费黄色日本 | 欧美久久久网站 | 国产欧美精品区一区二区三区 | 中文字幕在线观看 | 欧美激情精品久久久久久 | 久草在线| 欧美激情一区二区三级高清视频 | 色网站在线 | 欧美激情精品久久久久久 | 在线视频a | 天天干夜夜 | 性色视频在线观看 | www国产亚洲精品 | 欧美精品a∨在线观看不卡 国产精品久久国产精品 | 国产一区中文字幕 | 欧产日产国产精品视频 | 亚洲看片网站 | 日韩精品一区二区三区中文字幕 |