<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://mochiu.net/index.php?action=history&amp;feed=atom&amp;title=%E8%A8%AD%E5%AE%9A_-_nodeIntegration</id>
	<title>設定 - nodeIntegration - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://mochiu.net/index.php?action=history&amp;feed=atom&amp;title=%E8%A8%AD%E5%AE%9A_-_nodeIntegration"/>
	<link rel="alternate" type="text/html" href="https://mochiu.net/index.php?title=%E8%A8%AD%E5%AE%9A_-_nodeIntegration&amp;action=history"/>
	<updated>2026-05-30T00:33:27Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://mochiu.net/index.php?title=%E8%A8%AD%E5%AE%9A_-_nodeIntegration&amp;diff=2772&amp;oldid=prev</id>
		<title>Wiki: /* 概要 */</title>
		<link rel="alternate" type="text/html" href="https://mochiu.net/index.php?title=%E8%A8%AD%E5%AE%9A_-_nodeIntegration&amp;diff=2772&amp;oldid=prev"/>
		<updated>2021-01-16T12:43:23Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;概要&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2021年1月16日 (土) 21:43時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;1行目:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;1行目:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 概要 ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 概要 ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;RendererプロセスでElectronのモジュールを使用する手順を記載する。&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;XSS対策のため、nodeIntegrationで無効にすることで、RendererプロセスからNode.jsの機能へのアクセスを制限することができる。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;XSS対策のため、nodeIntegrationで無効にすることで、RendererプロセスからNode.jsの機能へのアクセスを制限することができる。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;そのため、Rendererプロセスでrequire関数が呼ぶことができず、以下のようなエラーが出力される。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;そのため、Rendererプロセスでrequire関数が呼ぶことができず、以下のようなエラーが出力される。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mochiu_wiki:diff:1.41:old-2771:rev-2772:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Wiki</name></author>
	</entry>
	<entry>
		<id>https://mochiu.net/index.php?title=%E8%A8%AD%E5%AE%9A_-_nodeIntegration&amp;diff=2771&amp;oldid=prev</id>
		<title>Wiki: ページの作成:「== 概要 == XSS対策のため、nodeIntegrationで無効にすることで、RendererプロセスからNode.jsの機能へのアクセスを制限することができ…」</title>
		<link rel="alternate" type="text/html" href="https://mochiu.net/index.php?title=%E8%A8%AD%E5%AE%9A_-_nodeIntegration&amp;diff=2771&amp;oldid=prev"/>
		<updated>2021-01-16T12:42:17Z</updated>

		<summary type="html">&lt;p&gt;ページの作成:「== 概要 == XSS対策のため、nodeIntegrationで無効にすることで、RendererプロセスからNode.jsの機能へのアクセスを制限することができ…」&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== 概要 ==&lt;br /&gt;
XSS対策のため、nodeIntegrationで無効にすることで、RendererプロセスからNode.jsの機能へのアクセスを制限することができる。&amp;lt;br&amp;gt;&lt;br /&gt;
そのため、Rendererプロセスでrequire関数が呼ぶことができず、以下のようなエラーが出力される。&amp;lt;br&amp;gt;&lt;br /&gt;
 Uncaught ReferenceError: require is not defined&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
詳細においては、以下に示すElectronの公式Webサイトを参照すること。&amp;lt;br&amp;gt;&lt;br /&gt;
[https://electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content Do not enable Node.js Integration for Remote Content]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 方法 ==&lt;br /&gt;
以下に示す通り、対応策は2つある。&amp;lt;br&amp;gt;&lt;br /&gt;
* ノードインテグレーションを有効にする。&lt;br /&gt;
* preloadを使用する。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== ノードインテグレーションを有効にする ====&lt;br /&gt;
main.jsファイルのBrowserWindowにおいて、webPreferencesのnodeIntegrationオプションをtrueにする。&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 // main.jsファイル&lt;br /&gt;
 &lt;br /&gt;
 // ...&lt;br /&gt;
 mainWindow = new BrowserWindow(&lt;br /&gt;
 {&lt;br /&gt;
    width: 1000,&lt;br /&gt;
    height: 800,&lt;br /&gt;
    webPreferences: {nodeIntegration: true},  // 追記&lt;br /&gt;
 });&lt;br /&gt;
 // ...&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
ただし、ElectronでXSS攻撃を受ける場合、PCのデータも操作される危険性もあるため、falseが安全である。&amp;lt;br&amp;gt;&lt;br /&gt;
ローカルで完結するようなElectronソフトウェアの場合、trueにしても良いが、&amp;lt;br&amp;gt;&lt;br /&gt;
DBからユーザが入力したテキストを表示する等、リモートコンテンツを表示する機能がある場合、falseのままが良い。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== preloadを使用する ====&lt;br /&gt;
ノードインテグレーションを有効にしない場合、preloadを使用する。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
preloadとは、他のスクリプトが実行される前にロードするスクリプトを指定するオプションであり、&amp;lt;br&amp;gt;&lt;br /&gt;
指定したスクリプト内では、Node.jsのAPIにアクセスできる。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
そのため、以下のように、windowオブジェクト等に使用するモジュールをセットできる。&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 // main.jsファイル&lt;br /&gt;
 &lt;br /&gt;
 new BrowserWindow(&lt;br /&gt;
 {&lt;br /&gt;
    width: 1200,&lt;br /&gt;
    height: 800,&lt;br /&gt;
    webPreferences: {nodeIntegration: false, preload: `${__dirname}/&amp;lt;JavaScriptファイル名&amp;gt;.js`}  // 読み込むjsファイルのパス&lt;br /&gt;
 });&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 // &amp;lt;JavaScriptファイル名&amp;gt;.jsファイル&lt;br /&gt;
 &lt;br /&gt;
 window.ipcRenderer = require(&amp;#039;electron&amp;#039;).ipcRenderer;&lt;br /&gt;
 window.remote = require(&amp;#039;electron&amp;#039;).remote;&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
このように記述した後、Rendererプロセスでwindow.ipcRendererを呼び出す。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__FORCETOC__&lt;br /&gt;
[[カテゴリ:Electron]]&lt;/div&gt;</summary>
		<author><name>Wiki</name></author>
	</entry>
</feed>