0Pricing
Electron Desktop App Development · レッスン

リモートコンテンツのリスクへの対策

webSecurity、CSP、ナビゲーション制御を使い、リモートまたは信頼できないWebコンテンツによる脅威からElectronアプリを保護します。分離とサンドボックス化の知識も活用します。

「リモートコンテンツのリスクへの対策」はCoddyKit上の無料Electron Desktop App Developmentレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはElectron Desktop App Development学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Electron Desktop App Developmentコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

The Danger of Remote Content

Loading remote URLs or untrusted HTML can expose your app to cross-site scripting and code execution. Hardening is essential.

Prefer Local Content

The safest app loads only local files you control. Treat any remote content as hostile until proven otherwise.

Keep webSecurity On

Never disable webSecurity. It enforces the same-origin policy inside your renderer.

new BrowserWindow({
  webPreferences: {
    webSecurity: true
  }
});

Content Security Policy

A CSP restricts what scripts and resources can load, blocking injected code.

<meta http-equiv="Content-Security-Policy" content="default-src 'self'">

Validating a CSP

A strict CSP avoids unsafe-inline and unsafe-eval. You can lint your policy programmatically.

function isStrict(csp) {
  return !csp.includes('unsafe-inline') && !csp.includes('unsafe-eval');
}
console.log(isStrict("default-src 'self'"));

Controlling Navigation

Block unexpected navigation with the will-navigate event, allowing only your trusted origins.

function allowed(url) {
  return url.startsWith('https://myapp.example.com');
}
console.log(allowed('https://evil.com'));

Blocking New Windows

Intercept setWindowOpenHandler to deny or vet any attempt to open new windows from content.

contents.setWindowOpenHandler(({ url }) => {
  return { action: allowed(url) ? 'allow' : 'deny' };
});

Opening Links Safely

Send external links to the OS browser with shell.openExternal instead of loading them inside your app.

Disable Unused Permissions

Use a setPermissionRequestHandler to deny camera, geolocation, and other requests your app does not need.

session.setPermissionRequestHandler((wc, perm, cb) => {
  cb(perm === 'notifications');
});

Avoid Disabling Protections

Flags like allowRunningInsecureContent and nodeIntegration: true on remote content are dangerous. Keep defaults.

Audit Regularly

Run Electron's security checklist and keep Electron updated to inherit Chromium's latest patches.

Quick Check

Test your remote-content hardening knowledge.

Recap

You learned to harden against remote content: prefer local files, keep webSecurity on, enforce a strict CSP, control navigation and window opening, deny unneeded permissions, and audit regularly.

よくある質問

「リモートコンテンツのリスクへの対策」レッスンは無料ですか?

はい。「リモートコンテンツのリスクへの対策」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Electron Desktop App Developmentコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Electron Desktop App Developmentコースには全4レッスンが含まれています。

「リモートコンテンツのリスクへの対策」で何を学びますか?

webSecurity、CSP、ナビゲーション制御を使い、リモートまたは信頼できないWebコンテンツによる脅威からElectronアプリを保護します。分離とサンドボックス化の知識も活用します。 ブラウザで直接実行するハンズオンコードでElectron Desktop App Developmentを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Electron Desktop App Developmentを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのElectron Desktop App Developmentは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「リモートコンテンツのリスクへの対策」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このElectron Desktop App Developmentレッスンでコードを書いて実行できますか?

はい。すべてのElectron Desktop App Developmentレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 安全なIPCパターン
  2. コンテキスト分離とPreloadスクリプト
  3. rendererプロセスのサンドボックス化
  4. リモートコンテンツのリスクへの対策
← Electron Desktop App Developmentに戻る