Skip to main content
ESLint 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.


Live README from GitHubfrom eslint-plugin-browser-security/README.md, cached for 1 hour.Edit on GitHub
ESLint Interlace Logo

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

NPM VersionNPM DownloadsPackage LicenseCodecovSince Dec 2025

โญ If this plugin caught a real bug for you, star the repo โ€” it's the signal that keeps these rules maintained.

Description

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

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

โš™๏ธ 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.

๐Ÿ’ก 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);
});

๐Ÿ“ฆ Compatibility

PackageVersion
ESLint^8.0.0 || ^9.0.0 || ^10.0.0
Node.js>=18.0.0

See the ESLint Version Support Policy โ€” current ecosystem share data, the 20% gate, and the forward-looking exception that covers v10.

Rules

Legend

IconDescription
๐Ÿ’ผRecommended: Included in the recommended preset.
โš ๏ธWarns: Set to warn in recommended preset.
๐Ÿ”งAuto-fixable: Automatically fixable by the --fix CLI option.
๐Ÿ’กSuggestions: Providing code suggestions in IDE.
๐ŸšซDeprecated: This rule is deprecated.
๐ŸŸขType-unaware: AST-only, runs in oxlint JS-plugin tier.
๐ŸŸกType-aware (refining): pure-AST primary path; types refine precision.
๐ŸŸ Type-aware (graceful): requires TS program; silent without it.
RuleCWEOWASPCVSSDescription๐Ÿง ๐Ÿ’ผโš ๏ธ๐Ÿ”ง๐Ÿ’ก๐Ÿšซ
detect-mixed-contentCWE-311Detects HTTP URLs in code that should use HTTPS, preventing mixed content vulnerabilities.๐ŸŸข
no-allow-arbitrary-loadsCWE-295Prevents disabling App Transport Security (ATS) by detecting allowArbitraryLoads: true in configuration.๐ŸŸข
no-clickjackingCWE-1021Detects clickjacking vulnerabilities and missing frame protections๐ŸŸข
no-client-side-auth-logicPrevent client-side authentication logic that can be bypassed. This rule is part of eslint-plugin-browser-sโ€ฆ๐ŸŸข
no-cookie-auth-tokensCWE-1004A02:2021Prevent storing authentication tokens in JavaScript-accessible cookies.๐ŸŸข
no-credentials-in-query-paramsCWE-598CWE: CWE-598๐ŸŸข
no-disabled-certificate-validationCWE-295CWE: CWE-295๐ŸŸข
no-dynamic-service-worker-urlCWE-829A08:2021Prevent dynamic URLs in service worker registration.๐ŸŸข
no-evalCWE-94Detects dangerous eval() and similar code execution patterns๐ŸŸข๐Ÿ’ผ
no-filereader-innerhtmlCWE-693A03:2021The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance:๐ŸŸข
no-http-urlsCWE-319CWE: CWE-319๐ŸŸข
no-innerhtmlCWE-79Detects dangerous innerHTML/outerHTML assignments that can lead to Cross-Site Scripting (XSS)๐ŸŸข๐Ÿ’ผ
no-insecure-redirectsCWE-601ESLint Rule: no-insecure-redirects๐ŸŸข
no-insecure-websocketCWE-319CWE: CWE-319๐ŸŸข
no-jwt-in-storageCWE-311A02:2021This rule prevents storing JWT tokens in browser storage (localStorage/sessionStorage)๐ŸŸข
no-missing-cors-checkCWE-346Detects missing CORS validation (wildcard CORS, missing origin check) that can allow unauthorized cross-oriโ€ฆ๐ŸŸข
no-missing-csrf-protectionCWE-352Detects missing CSRF token validation in POST/PUT/DELETE requests๐ŸŸข
no-missing-security-headersCWE-693ESLint Rule: no-missing-security-headers๐ŸŸข
no-password-in-urlCWE-521This rule detects when URLs contain password-related query parameters or URL fragments๐ŸŸข
no-permissive-corsCWE-942CWE: CWE-942๐ŸŸข
no-postmessage-innerhtmlCWE-693A03:2021The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance:๐ŸŸข
no-postmessage-wildcard-originCWE-693A01:2021This rule prevents using \"\" as the targetOrigin parameter in postMessage() calls๐ŸŸข
no-sensitive-cookie-jsCWE-359A02:2021The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance:๐ŸŸข
no-sensitive-data-in-analyticsCWE-359This rule detects when sensitive user data (email, SSN, credit card, password, phone, address) is passed toโ€ฆ๐ŸŸข
no-sensitive-data-in-cacheCWE-200CWE: CWE-200๐ŸŸข
no-sensitive-indexeddbCWE-922A02:2021Prevent storing sensitive data in IndexedDB.๐ŸŸข
no-sensitive-localstorageCWE-922Detects storage of sensitive data (tokens, passwords, PII) in localStorage๐ŸŸข
no-sensitive-sessionstorageCWE-922A02:2021Prevent storing sensitive data in sessionStorage.๐ŸŸข
no-tracking-without-consentCWE-359CWE: CWE-359๐ŸŸข
no-unencrypted-transmissionCWE-319Detects unencrypted data transmission (HTTP vs HTTPS, plain text protocols)๐ŸŸข
no-unescaped-url-parameterCWE-79Detects unescaped URL parameters that can lead to Cross-Site Scripting (XSS) or open redirect vulnerabilities๐ŸŸข
no-unsafe-eval-cspCWE-95A03:2021Disallow 'unsafe-eval' in Content Security Policy directives.๐ŸŸข
no-unsafe-inline-cspCWE-79A03:2021Disallow 'unsafe-inline' in Content Security Policy directives.๐ŸŸข
no-unvalidated-deeplinksCWE-939This rule detects when deep link URLs are opened without validation in React Native or mobile web apps๐ŸŸข
no-websocket-evalCWE-319A03:2021The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance:๐ŸŸข
no-websocket-innerhtmlCWE-319A03:2021The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance:๐ŸŸข
no-worker-message-innerhtmlCWE-79A03:2021Disallow using innerHTML with Web Worker message data.๐ŸŸข
require-blob-url-revocationCWE-401A04:2021Require revoking Blob URLs after use to prevent memory leaks.๐ŸŸข
require-cookie-secure-attrsCWE-614A05:2021Require Secure and SameSite attributes on cookies.๐ŸŸข
require-csp-headersCWE-1021CWE: CWE-1021๐ŸŸข
require-https-onlyCWE-319This rule detects HTTP (unencrypted) URLs in fetch() and axios requests๐ŸŸข
require-mime-type-validationCWE-434CWE: CWE-434๐ŸŸข
require-postmessage-origin-checkCWE-346Detects postMessage event handlers without origin validation๐ŸŸข
require-url-validationCWE-601CWE: CWE-601๐ŸŸข
require-websocket-wssCWE-319A02:2021This rule enforces the use of wss:// (WebSocket Secure) protocol instead of ws:// (unencrypted WebSocket)๐ŸŸข

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

PluginDownloadsDescription
eslint-plugin-secure-codingdownloadsGeneral security rules & OWASP guidelines.
eslint-plugin-pgdownloadsPostgreSQL security & best practices.
eslint-plugin-node-securitydownloadsNode.js core-module security (fs, child_process, vm, crypto, Buffer).
eslint-plugin-jwtdownloadsJWT security & best practices.
eslint-plugin-browser-securitydownloadsBrowser-specific security & XSS prevention.
eslint-plugin-express-securitydownloadsExpress.js security hardening rules.
eslint-plugin-lambda-securitydownloadsAWS Lambda security best practices.
eslint-plugin-nestjs-securitydownloadsNestJS security rules & patterns.
eslint-plugin-mongodb-securitydownloadsMongoDB security best practices.
eslint-plugin-vercel-ai-securitydownloadsVercel AI SDK security hardening.
eslint-plugin-import-nextdownloadsNext-gen import sorting & architecture.

โญ Support & follow

If this plugin caught a real bug for you, star the repo โ€” stars are the signal that keeps the Interlace ESLint ecosystem maintained โ€” and follow the writeups on Dev.to for the benchmarks and security research behind these rules.

GitHub stars

๐Ÿ“„ License

MIT ยฉ Ofri Peretz

ESLint Interlace Plugin

View README.md on GitHub โ†’

On this page

No Headings