Skip to main content
interlace
Plugin: browser-security

eslint-plugin-browser-security

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

AI-Optimized Security

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

Install

npm install -D eslint-plugin-browser-security

Live from GitHub

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

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

⭐ 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.

  • Why β€” a linter nobody reads protects nothing. We would rather miss a finding than spend your attention on one that was never real.
  • How β€” evidence, not names. A rule fires on what the code does, resolved through the AST and ESLint's own scope analysis.
  • What β€” every finding carries its fix, in prose for a human and as structured JSON for an agent. Security rules add a CWE mapping and, where assigned, a CVSS score.

That trade costs recall, and we measure it: methodology Β· results Β· a false positive is a bug.

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.40.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 NSAllowsArbitraryLoads: true in an Expo/Reactβ€¦πŸŸ’πŸ’Ό
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-incomplete-url-sanitizationCWE-020A01:2021Disallow URL substring tests and partial scheme denylists as security decisionsπŸŸ’πŸ’Ό
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 rules with LLM-optimized error messages:

Security

PluginDownloadsDescription
eslint-plugin-anthropic-securitydownloadsAnthropic SDK security.
eslint-plugin-drizzle-securitydownloadsDrizzle security.
eslint-plugin-express-securitydownloadsExpress middleware hardening.
eslint-plugin-gemini-securitydownloadsGoogle Gemini SDK security.
eslint-plugin-jwt-securitydownloadsToken security.
eslint-plugin-knex-securitydownloadsKnex security.
eslint-plugin-lambda-securitydownloadsAWS Lambda hardening.
eslint-plugin-mcp-sdk-securitydownloadsMCP SDK security.
eslint-plugin-mongodb-securitydownloadsMongoDB injection.
eslint-plugin-mysql-securitydownloadsMySQL security.
eslint-plugin-nestjs-securitydownloadsNestJS framework hardening.
eslint-plugin-node-securitydownloadsServer-side patterns.
eslint-plugin-openai-securitydownloadsOpenAI SDK security.
eslint-plugin-postgresql-securitydownloadsPostgreSQL security.
eslint-plugin-prisma-securitydownloadsPrisma security.
eslint-plugin-secure-codingdownloadsInjection prevention.
eslint-plugin-sequelize-securitydownloadsSequelize ORM security.
eslint-plugin-sqlite-securitydownloadsSQLite security.
eslint-plugin-supabase-securitydownloadsSupabase security.
eslint-plugin-typeorm-securitydownloadsTypeORM security.
eslint-plugin-vercel-ai-securitydownloadsAI SDK security.

Code quality

PluginDownloadsDescription
eslint-plugin-cli-floordownloadsCLI floor for commander, yargs and burgee.
eslint-plugin-conventionsdownloadsTeam-specific habits and styles.
eslint-plugin-import-nextdownloadsFast cycle + import-graph analysis.
eslint-plugin-maintainabilitydownloadsCognitive load and clean-code patterns.
eslint-plugin-modernizationdownloadsESNext migration + syntax evolution.
eslint-plugin-modularitydownloadsStructural integrity and DDD patterns.
eslint-plugin-operabilitydownloadsProduction readiness and resource health.
eslint-plugin-react-a11ydownloadsReact accessibility / WCAG.
eslint-plugin-react-featuresdownloadsReact best practices and optimization.
eslint-plugin-reliabilitydownloadsRuntime stability and error safety.

⭐ 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

View README.md on GitHub β†’

Building secure JavaScript with Interlace? Star the repo to get new rules and CWE coverage as we ship them β€” or follow the AI-code-security benchmarks behind them.