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

  

Chromium

  

oxlint

  

ESLint

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

Interlace

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.