Interlace ESLint
ESLint Interlace
Browser SecurityRules

no-dynamic-service-worker-url

Prevent dynamic URLs in service worker registration.

Prevent dynamic URLs in service worker registration.

⚠️ Security Issue

PropertyValue
CWECWE-829: Inclusion of Functionality from Untrusted Control Sphere
OWASPA08:2021 - Software and Data Integrity Failures
CVSS8.1 (High)
SeverityHIGH

📋 Description

Dynamically constructing service worker URLs can lead to loading malicious scripts that have full control over network requests for your site.

❌ Incorrect

// Dynamic URL construction
navigator.serviceWorker.register(userInput);

// Template literal with expression
navigator.serviceWorker.register(`${basePath}/sw.js`);

// Concatenation
navigator.serviceWorker.register(path + '/worker.js');

✅ Correct

// Static string URL
navigator.serviceWorker.register('/sw.js');

// Constant URL
navigator.serviceWorker.register('/service-worker.js', { scope: '/' });

🛠️ Options

{
  "rules": {
    "@interlace/browser-security/no-dynamic-service-worker-url": [
      "error",
      {
        "allowInTests": true
      }
    ]
  }
}

Known False Negatives

The following patterns are not detected due to static analysis limitations:

URL from Configuration

Why: Config values not analyzed.

// ❌ NOT DETECTED - From config
navigator.serviceWorker.register(config.serviceWorkerUrl);

Mitigation: Hardcode service worker URLs.

Aliased Register Function

Why: Aliased functions not traced.

// ❌ NOT DETECTED - Aliased
const registerSW = navigator.serviceWorker.register.bind(
  navigator.serviceWorker,
);
registerSW(dynamicUrl);

Mitigation: Avoid aliasing register function.

Error Message Format

The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance:

🔒 CWE-829 OWASP:A03 CVSS:7.5 | Untrusted Control Sphere Inclusion detected | HIGH
   Fix: Review and apply the recommended fix | https://owasp.org/Top10/A03_2021/

Message Components

ComponentPurposeExample
Risk StandardsSecurity benchmarksCWE-829 OWASP:A03 CVSS:7.5
Issue DescriptionSpecific vulnerabilityUntrusted Control Sphere Inclusion detected
Severity & ComplianceImpact assessmentHIGH
Fix InstructionActionable remediationFollow the remediation steps below
Technical TruthOfficial referenceOWASP Top 10

On this page