How to fix: Service Worker Registered Without a Narrow Scope
A service worker is registered without an explicit narrow 'scope' option, so it defaults to controlling the entire origin. This is standard, expected behavior for most PWAs -- not itself a vulnerability -- but worth confirming was intentional.
Why it matters
A broadly-scoped service worker controls every page on the origin. If any single path under that scope is ever compromised (stored XSS, an uploaded file served from the same origin), the impact extends site-wide instead of being contained to one subpath.
Most sites intentionally register their service worker with the default (whole-origin) scope -- this is fine for the common case of a single-page app or PWA that wants offline support everywhere. Consider a narrower scope only if the service worker should not control unrelated subpaths (e.g. a docs subsection, a third-party-embeddable widget path).
How to fix it
- 1If the service worker is only meant to control a specific section of the site, pass an explicit scope: navigator.serviceWorker.register('/app/sw.js', { scope: '/app/' }).
- 2No action needed if whole-origin control is intentional, which is the common case.
Code examples
Explicit scope for a partial-site service worker
// Whole-origin (default) -- fine for most PWAs:
navigator.serviceWorker.register('/sw.js');
// Narrower scope -- only if the SW should not control the rest of the site:
navigator.serviceWorker.register('/app/sw.js', { scope: '/app/' });References
Detected automatically by VulnRadar. The check id is service-worker-scope, stable across every scan so you can filter or diff on it.
More content checks
- MediumPotential Open Redirect Parameters
- HighDirectory Listing Appears Enabled
- MediumSensitive File References Detected
- HighPotentially Outdated JavaScript Libraries
- Inforobots.txt Present - Review Manually
- InfoCMS / Technology Fingerprinting
- MediumPotentially Dangerous Inline JavaScript
- LowServer version disclosed in response header
Questions
- How severe is Service Worker Registered Without a Narrow Scope?
- VulnRadar rates this low severity in the content category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id service-worker-scope, which stays the same between runs so you can filter, diff, or gate CI on it.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.