Security and quality

Deny unused permissions

Install a permission handler that rejects camera, microphone, notification, and other web permissions the app does not use.

8 minute lesson

~~~

Chromium exposes permissions for media, geolocation, screen capture, notifications, devices, and filesystem features. Desktop Notes needs none.

Install both permission handlers after the app is ready:

const { session } = require('electron')

session.defaultSession.setPermissionRequestHandler(
  (_webContents, _permission, callback) => {
    callback(false)
  }
)

session.defaultSession.setPermissionCheckHandler(() => false)

Electron documents both handlers because web APIs can check permission before requesting it. Implementing only one leaves an incomplete policy.

If the app later needs one permission, check the exact permission, requesting origin, embedding origin, and frame details. Deny everything else.

A prompt is not a security policy. The handler should decide which requests are valid before Chromium presents or grants them.

Exercise the policy from renderer DevTools with a harmless permission request, such as notifications. Confirm it is denied and no operating-system prompt appears.

If you add a custom session or partition later, install the same policy there. defaultSession does not configure unrelated sessions automatically.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →