Skip to main content

no-electron-webview-insecure-webpreferences

Disallow unsafe Electron <webview> webpreferences string flags.

Targeted pattern scopeโ€‹

This rule targets static <webview webpreferences="..." /> attributes that enable insecure flags such as:

  • allowRunningInsecureContent=yes
  • contextIsolation=no
  • experimentalFeatures=yes
  • sandbox=no
  • webSecurity=no

What this rule reportsโ€‹

This rule reports static webpreferences strings on Electron webview elements when they contain unsafe hardening overrides.

Why this rule existsโ€‹

Electron webview attributes often hide security-critical renderer settings inside string flags. Those strings can quietly disable isolation or enable risky behavior that should stay off for untrusted content.

โŒ Incorrectโ€‹

const view = (
<webview
src="https://example.com"
webpreferences="webSecurity=no, contextIsolation=no"
/>
);

โœ… Correctโ€‹

const view = (
<webview
src="https://example.com"
webpreferences="sandbox=yes, contextIsolation=yes, webSecurity=yes"
/>
);

Behavior and migration notesโ€‹

This rule currently reports only static string values. Dynamic webpreferences expressions are ignored to avoid false positives.

ESLint flat config exampleโ€‹

import sdl from "eslint-plugin-sdl-2";

export default [
{
plugins: { sdl },

rules: {
"sdl/no-electron-webview-insecure-webpreferences": "error",
},
},
];

When not to use itโ€‹

Disable only if reviewed webview content requires these flags and the host application enforces compensating controls elsewhere.

Package documentationโ€‹

Further readingโ€‹

Rule catalog ID: R051