久久久久久久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?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 影音先锋亚洲资源 | 天天操操| 一呦二呦三呦国产精品 | 在线观看av网站永久 | 国产精品99 | 午夜精品一区二区三区在线视 | 一区二区国产在线 | 精品毛片 | 国产综合久久 | 国产在线精品一区 | 久久人人国产 | 激情视频网站 | 午夜理伦三级理论三级在线观看 | 亚洲精品自在在线观看 | 国产精品人人做人人爽 | 国产精品影视在线观看 | 美女日批免费视频 | 国产视频在线观看一区二区三区 | 国产福利二区 | 欧洲视频一区二区 | 国产欧美精品一区二区色综合朱莉 | 精品videossex高潮汇编 | 亚洲精品在线免费 | 福利片在线观看 | 天天曰天天曰 | 国产欧美日韩二区 | 精品少妇一区二区三区日产乱码 | 7777在线 | 青青久在线视频 | 国产欧美一区二区三区国产幕精品 | 亚洲欧美激情精品一区二区 | av一区二区三区四区 | 中文字幕免费 | 一区二区三区中文字幕 | 精品日韩一区二区 | 精品久久久久久久久久久 | 精品视频在线观看 | 一区二区三区在线免费观看视频 | 一级毛片视频 | 国产一区二区三区欧美 | 日日骚视频 |