ESLint InterlaceESLint Interlace
Plugin: browser-security

Overview

XSS, cookie, and DOM security rules for client-side JavaScript

Live from GitHub

This content is fetched directly from README.md on GitHub and cached for 1 hour.

AI-Optimized Security

Every rule includes CWE, OWASP, and CVSS metadata for AI assistants to provide precise, context-aware fixes.


ESLint Interlace Logo

Browser-specific security rules to prevent XSS and other client-side attacks.

NPM VersionNPM DownloadsPackage LicenseCodecovSince Dec 2025

Description

This plugin provides Browser-specific security rules to prevent XSS and other client-side attacks. By using this plugin, you can proactively identify and mitigate security risks across your entire codebase.

Philosophy

Interlace fosters strength through integration. Instead of stacking isolated rules, we interlace security directly into your workflow to create a resilient fabric of code. We believe tools should guide rather than gatekeep, providing educational feedback that strengthens the developer with every interaction.

Getting Started

npm install eslint-plugin-browser-security --save-dev

๐Ÿ’ก What You Get

  • 21 security rules targeting browser-specific vulnerabilities
  • XSS prevention via DOM manipulation and dynamic content detection
  • Storage security preventing sensitive data exposure in localStorage/sessionStorage/IndexedDB
  • Cross-origin protection with postMessage origin validation
  • LLM-optimized messages with CWE references and auto-fix suggestions
  • OWASP Top 10 coverage for browser security patterns

๐ŸŽฏ Why This Plugin?

Modern browser applications face unique security challenges across storage APIs, cross-origin communication, and dynamic content rendering. This plugin provides static analysis rules specifically designed for browser security patterns:

  • XSS Prevention: Detects dangerous DOM manipulation patterns
  • Storage Security: Prevents sensitive data exposure in localStorage/sessionStorage/IndexedDB
  • Cross-Origin Protection: Validates postMessage origin checks
  • Cookie Security: Identifies insecure cookie handling in JavaScript
  • LLM-Optimized: All rules include AI-friendly remediation guidance

๐Ÿ” Detection Examples

โŒ Vulnerable Code

// XSS via innerHTML
element.innerHTML = userInput;

// Code injection via eval
eval(dynamicCode);

// JWT in localStorage (XSS can steal it)
localStorage.setItem('token', jwt);

// postMessage without origin check
window.addEventListener('message', (event) => {
  processData(event.data); // Anyone can send messages!
});

โœ… Secure Code

// Safe text assignment
element.textContent = userInput;

// Or sanitize before HTML insertion
element.innerHTML = DOMPurify.sanitize(userInput);

// Use HttpOnly cookies for auth tokens (set by server)
// Server: Set-Cookie: token=xxx; HttpOnly; Secure; SameSite=Strict

// Origin validation
window.addEventListener('message', (event) => {
  if (event.origin !== 'https://trusted-domain.com') return;
  processData(event.data);
});

โš™๏ธ Configuration Presets

PresetDescription
recommendedRecommended security configuration
strictStrict security configuration - all rules as errors

๐Ÿค– LLM-Optimized Messages

All rules include structured remediation guidance designed for AI assistants:

[browser-security/no-innerhtml] XSS vulnerability: Direct HTML assignment detected.

๐Ÿ“‹ CONTEXT:
  โ€ข Pattern: element.innerHTML = unsanitizedInput
  โ€ข Risk: Any script in unsanitizedInput will execute

๐Ÿ› ๏ธ REMEDIATION:
  Option A (Preferred): Use textContent for plain text
    element.textContent = userInput;

  Option B: Sanitize before insertion
    element.innerHTML = DOMPurify.sanitize(userInput);

๐Ÿ“š References:
  โ€ข CWE-79: https://cwe.mitre.org/data/definitions/79.html
  โ€ข OWASP XSS Prevention: https://owasp.org/...

By providing this structured context (CWE, OWASP, Fix), we enable AI tools to reason about the security flaw rather than hallucinating. This allows Copilot/Cursor to suggest the exact correct fix immediately.

Rules

Legend

IconDescription
๐Ÿ’ผRecommended: Included in the recommended preset.
โš ๏ธWarns: Set towarn in recommended preset.
๐Ÿ”งAuto-fixable: Automatically fixable by the --fix CLI option.
๐Ÿ’กSuggestions: Providing code suggestions in IDE.
๐ŸšซDeprecated: This rule is deprecated.
RuleCWEOWASPCVSSDescription๐Ÿ’ผโš ๏ธ๐Ÿ”ง๐Ÿ’ก๐Ÿšซ
detect-mixed-contentESLint rule documentation for detect-mixed-content
no-allow-arbitrary-loadsESLint rule documentation for no-allow-arbitrary-loads
no-clickjackingESLint rule documentation for no-clickjacking
no-client-side-auth-logicESLint rule documentation for no-client-side-auth-logic
no-cookie-auth-tokensCWE-1004A02:20255.3ESLint rule documentation for no-cookie-auth-tokens๐Ÿ’ผ๐Ÿ’ก
no-credentials-in-query-paramsESLint rule documentation for no-credentials-in-query-params
no-disabled-certificate-validationESLint rule documentation for no-disabled-certificate-validation
no-dynamic-service-worker-urlCWE-829A08:20257.5ESLint rule documentation for no-dynamic-service-worker-url๐Ÿ’ผ๐Ÿ’ก
no-evalCWE-95A03:20259.8ESLint rule documentation for no-eval๐Ÿ’ผ๐Ÿ’ก๐Ÿšซ
no-filereader-innerhtmlCWE-79A03:20256.1ESLint rule documentation for no-filereader-innerhtml๐Ÿ’ผ๐Ÿ’ก
no-http-urlsESLint rule documentation for no-http-urls
no-innerhtmlCWE-79A03:20256.1ESLint rule documentation for no-innerhtml๐Ÿ’ผ๐Ÿ’ก
no-insecure-redirectsESLint rule documentation for no-insecure-redirects
no-insecure-websocketESLint rule documentation for no-insecure-websocket
no-jwt-in-storageCWE-922A02:20257.5ESLint rule documentation for no-jwt-in-storage๐Ÿ’ผ๐Ÿ’ก
no-missing-cors-checkESLint rule documentation for no-missing-cors-check
no-missing-csrf-protectionESLint rule documentation for no-missing-csrf-protection
no-missing-security-headersESLint rule documentation for no-missing-security-headers
no-password-in-urlESLint rule documentation for no-password-in-url
no-permissive-corsESLint rule documentation for no-permissive-cors
no-postmessage-innerhtmlCWE-79A03:20256.1ESLint rule documentation for no-postmessage-innerhtml๐Ÿ’ผ
no-postmessage-wildcard-originCWE-346A01:20258.8ESLint rule documentation for no-postmessage-wildcard-origin๐Ÿ’ผ
no-sensitive-cookie-jsCWE-1004A02:20255.3ESLint rule documentation for no-sensitive-cookie-js๐Ÿ’ผ๐Ÿ’ก
no-sensitive-data-in-analyticsESLint rule documentation for no-sensitive-data-in-analytics
no-sensitive-data-in-cacheESLint rule documentation for no-sensitive-data-in-cache
no-sensitive-indexeddbCWE-922A02:20257.5ESLint rule documentation for no-sensitive-indexeddb๐Ÿ’ผ๐Ÿ’ก
no-sensitive-localstorageCWE-922A02:20257.5ESLint rule documentation for no-sensitive-localstorage๐Ÿ’ผ๐Ÿ’ก
no-sensitive-sessionstorageCWE-922A02:20257.5ESLint rule documentation for no-sensitive-sessionstorage๐Ÿ’ผ๐Ÿ’ก
no-tracking-without-consentESLint rule documentation for no-tracking-without-consent
no-unencrypted-transmissionESLint rule documentation for no-unencrypted-transmission
no-unescaped-url-parameterESLint rule documentation for no-unescaped-url-parameter
no-unsafe-eval-cspCWE-95A03:20259.8ESLint rule documentation for no-unsafe-eval-csp๐Ÿ’ผ๐Ÿ’ก
no-unsafe-inline-cspCWE-79A03:20256.1ESLint rule documentation for no-unsafe-inline-csp๐Ÿ’ผ๐Ÿ’ก
no-unvalidated-deeplinksESLint rule documentation for no-unvalidated-deeplinks
no-websocket-evalCWE-95A03:20259.8ESLint rule documentation for no-websocket-eval๐Ÿ’ผ๐Ÿ’ก
no-websocket-innerhtmlCWE-79A03:20256.1ESLint rule documentation for no-websocket-innerhtml๐Ÿ’ผ๐Ÿ’ก
no-worker-message-innerhtmlCWE-79A03:20256.1ESLint rule documentation for no-worker-message-innerhtml๐Ÿ’ผ
require-blob-url-revocationCWE-401A04:20255.3ESLint rule documentation for require-blob-url-revocation๐Ÿ’ผโš ๏ธ๐Ÿ’ก
require-cookie-secure-attrsCWE-614A05:20255.3ESLint rule documentation for require-cookie-secure-attrs๐Ÿ’ผ๐Ÿšซ
require-csp-headersESLint rule documentation for require-csp-headers
require-https-onlyESLint rule documentation for require-https-only
require-mime-type-validationESLint rule documentation for require-mime-type-validation
require-postmessage-origin-checkCWE-346A01:20258.8ESLint rule documentation for require-postmessage-origin-check๐Ÿ’ผ
require-url-validationESLint rule documentation for require-url-validation
require-websocket-wssCWE-319A02:20257.5ESLint rule documentation for require-websocket-wss๐Ÿ’ผ๐Ÿ’ก๐Ÿšซ

Part of the Interlace ESLint Ecosystem โ€” AI-native security plugins with LLM-optimized error messages:

PluginDownloadsDescription
eslint-plugin-secure-codingGeneral security rules & OWASP guidelines.
eslint-plugin-pgPostgreSQL security & best practices.
eslint-plugin-cryptoNodeJS Cryptography security rules.
eslint-plugin-jwtJWT security & best practices.
eslint-plugin-browser-securityBrowser-specific security & XSS prevention.
eslint-plugin-express-securityExpress.js security hardening rules.
eslint-plugin-lambda-securityAWS Lambda security best practices.
eslint-plugin-nestjs-securityNestJS security rules & patterns.
eslint-plugin-mongodb-securityMongoDB security best practices.
eslint-plugin-vercel-ai-securityVercel AI SDK security hardening.
eslint-plugin-import-nextNext-gen import sorting & architecture.

๐Ÿ“„ License

MIT ยฉ Ofri Peretz

ESLint Interlace Plugin

View README.md on GitHub โ†’

On this page

No Headings